Skip to content

Commit

Permalink
feat: add example for custom settings, use git dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Feb 4, 2024
1 parent 4726045 commit ae9e273
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 138 deletions.
4 changes: 3 additions & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'account/provider.dart';
import 'settings/provider.dart';
import 'settings/ui/provider.dart';

void main() {
runApp(
ProviderScope(
overrides: [
realAccountsProvider.overrideWith(CustomRealAccounts.new),
settingsUiElementsProvider.overrideWith(CustomSettingsUiElements.new),
settingsProvider.overrideWith(CustomSettingsNotifier.new),
],
child: const MailyApp(),
child: const EnoughMailApp(),
),
);
}
37 changes: 10 additions & 27 deletions lib/settings/provider.dart
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
import 'package:enough_mail_app/enough_mail_app.dart';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'provider.g.dart';
/// Shows how to override the default settings
class CustomSettingsNotifier extends SettingsNotifier {
/// Creates a new [CustomSettingsNotifier]
CustomSettingsNotifier({
super.settings,
});

@Riverpod(keepAlive: true)
class CustomSettingsUiElements extends _$CustomSettingsUiElements
implements SettingsUiElements {
@override
void build() {}
String getSignatureHtmlGlobal(BuildContext context) =>
state.signatureHtml ?? '<p>---<br/>${context.text.signature}</p>';

@override
List<UiSettingsElement> generate(
BuildContext context,
) {
final text = context.text;
final standardElements = SettingsUiElements.buildStandardElements(context);

/// You can remove a standard element easily like this:
// standardElements.removeType(UiSettingsType.welcome);
// You can insert a new element at a specific position like this:
// standardElements.insertAfter(UiSettingsType.accounts, newElement);

return [
...standardElements,
UiSettingsElement.divider(),
UiSettingsElement(
title: text.settingsDevelopment,
onTap: () => context.pushNamed(Routes.settingsDevelopment),
),
];
}
String getSignaturePlainGlobal(BuildContext context) =>
state.signaturePlain ?? '---\n${context.text.signature}';
}
35 changes: 35 additions & 0 deletions lib/settings/ui/provider.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:enough_mail_app/enough_mail_app.dart';
import 'package:flutter/widgets.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'provider.g.dart';

@Riverpod(keepAlive: true)
class CustomSettingsUiElements extends _$CustomSettingsUiElements
implements SettingsUiElements {
@override
void build() {}

@override
List<UiSettingsElement> generate(
BuildContext context,
) {
final text = context.text;
final standardElements = SettingsUiElements.buildStandardElements(context);

/// You can remove a standard element easily like this:
// standardElements.removeType(UiSettingsType.welcome);
// You can insert a new element at a specific position like this:
// standardElements.insertAfter(UiSettingsType.accounts, newElement);

return [
...standardElements,
UiSettingsElement.divider(),
UiSettingsElement(
title: text.settingsDevelopment,
onTap: () => context.pushNamed(Routes.settingsDevelopment),
),
];
}
}
File renamed without changes.
40 changes: 20 additions & 20 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,18 @@ dependency_overrides:
path: packages/pdfx

# out-comment the following to enable git-based development:
# enough_mail:
# git:
# url: https://github.com/Enough-Software/enough_mail.git
# enough_mail_app:
# git:
# url: https://github.com/Enough-Software/enough_mail_app.git
# enough_mail_flutter:
# git:
# url: https://github.com/Enough-Software/enough_mail_flutter.git
# enough_mail_html:
# git:
# url: https://github.com/Enough-Software/enough_mail_html.git
enough_mail:
git:
url: https://github.com/Enough-Software/enough_mail.git
enough_mail_app:
git:
url: https://github.com/Enough-Software/enough_mail_app.git
enough_mail_flutter:
git:
url: https://github.com/Enough-Software/enough_mail_flutter.git
enough_mail_html:
git:
url: https://github.com/Enough-Software/enough_mail_html.git
enough_media:
git:
url: https://github.com/Enough-Software/enough_media.git
Expand Down Expand Up @@ -142,14 +142,14 @@ dependency_overrides:
git:
url: https://github.com/Enough-Software/enough_platform_widgets.git
# out-comment the following to enable local development:
enough_mail:
path: ../enough_mail
enough_mail_app:
path: ../enough_mail_app
enough_mail_flutter:
path: ../enough_mail_flutter
enough_mail_html:
path: ../enough_mail_html
# enough_mail:
# path: ../enough_mail
# enough_mail_app:
# path: ../enough_mail_app
# enough_mail_flutter:
# path: ../enough_mail_flutter
# enough_mail_html:
# path: ../enough_mail_html
# enough_icalendar:
# path: ../enough_icalendar
# enough_mail_icalendar:
Expand Down
90 changes: 0 additions & 90 deletions pubspec_generated.yaml

This file was deleted.

0 comments on commit ae9e273

Please sign in to comment.