From ca142ffca9dd1a1fff3ffbb4c79861cdeb1dc2c7 Mon Sep 17 00:00:00 2001 From: provokateurin Date: Sat, 29 Jun 2024 13:32:06 +0200 Subject: [PATCH] refactor(neon_framework): Expose AppImplementationOptions through NeonProvider Signed-off-by: provokateurin --- .../neon_files/lib/src/blocs/browser.dart | 3 --- .../neon/neon_files/lib/src/blocs/files.dart | 3 --- .../lib/src/widgets/browser_view.dart | 8 +++++-- .../neon_files/lib/src/widgets/dialog.dart | 3 ++- .../lib/src/widgets/file_list_tile.dart | 4 +++- .../lib/src/widgets/file_preview.dart | 3 ++- .../neon_news/lib/src/blocs/articles.dart | 3 --- .../neon/neon_news/lib/src/blocs/news.dart | 2 -- .../neon/neon_news/lib/src/pages/article.dart | 8 ++++++- .../neon/neon_news/lib/src/pages/feed.dart | 3 ++- .../neon/neon_news/lib/src/pages/main.dart | 12 ++++++---- .../lib/src/widgets/articles_view.dart | 9 ++++--- .../neon_news/lib/src/widgets/feeds_view.dart | 7 ++++-- .../lib/src/widgets/folder_view.dart | 24 ++++++++++++------- .../lib/src/widgets/folders_view.dart | 8 +++++-- packages/neon/neon_notes/lib/neon_notes.dart | 1 - .../neon/neon_notes/lib/src/blocs/note.dart | 6 ----- .../neon/neon_notes/lib/src/blocs/notes.dart | 7 ------ .../neon/neon_notes/lib/src/pages/main.dart | 13 ++++++---- .../neon/neon_notes/lib/src/pages/note.dart | 3 ++- .../lib/src/widgets/categories_view.dart | 8 +++++-- .../lib/src/widgets/notes_view.dart | 6 +++-- packages/neon_framework/lib/neon.dart | 1 + .../lib/src/models/app_implementation.dart | 5 ++++ 24 files changed, 88 insertions(+), 62 deletions(-) diff --git a/packages/neon/neon_files/lib/src/blocs/browser.dart b/packages/neon/neon_files/lib/src/blocs/browser.dart index 2d36f55c1b0..050a4f05b36 100644 --- a/packages/neon/neon_files/lib/src/blocs/browser.dart +++ b/packages/neon/neon_files/lib/src/blocs/browser.dart @@ -39,8 +39,6 @@ sealed class FilesBrowserBloc implements InteractiveBloc { BehaviorSubject get uri; - FilesOptions get options; - /// Mode to operate the `FilesBrowserView` in. FilesBrowserMode get mode; } @@ -65,7 +63,6 @@ class _FilesBrowserBloc extends InteractiveBloc implements FilesBrowserBloc { @override final log = Logger('FilesBrowserBloc'); - @override final FilesOptions options; final Account account; diff --git a/packages/neon/neon_files/lib/src/blocs/files.dart b/packages/neon/neon_files/lib/src/blocs/files.dart index 6e06b7466dc..bc64c9071fb 100644 --- a/packages/neon/neon_files/lib/src/blocs/files.dart +++ b/packages/neon/neon_files/lib/src/blocs/files.dart @@ -49,8 +49,6 @@ sealed class FilesBloc implements InteractiveBloc { BehaviorSubject> get tasks; - FilesOptions get options; - FilesBrowserBloc get browser; FilesBrowserBloc getNewFilesBrowserBloc({PathUri? initialUri, FilesBrowserMode? mode}); @@ -68,7 +66,6 @@ class _FilesBloc extends InteractiveBloc implements FilesBloc { @override final log = Logger('FilesBloc'); - @override final FilesOptions options; final Account account; @override diff --git a/packages/neon/neon_files/lib/src/widgets/browser_view.dart b/packages/neon/neon_files/lib/src/widgets/browser_view.dart index b70ec489ac2..6946e77fdb8 100644 --- a/packages/neon/neon_files/lib/src/widgets/browser_view.dart +++ b/packages/neon/neon_files/lib/src/widgets/browser_view.dart @@ -13,6 +13,7 @@ import 'package:neon_files/src/widgets/file_list_tile.dart'; import 'package:neon_files/src/widgets/navigator.dart'; import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/sort_box.dart'; +import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; import 'package:nextcloud/webdav.dart'; @@ -32,6 +33,7 @@ class FilesBrowserView extends StatefulWidget { class _FilesBrowserViewState extends State { late final StreamSubscription errorsSubscription; + late final FilesOptions options; @override void initState() { @@ -39,6 +41,8 @@ class _FilesBrowserViewState extends State { NeonError.showSnackbar(context, error); }); + options = NeonProvider.of(context); + super.initState(); } @@ -72,8 +76,8 @@ class _FilesBrowserViewState extends State { }, child: SortBoxBuilder( sortBox: filesSortBox, - sortProperty: widget.bloc.options.filesSortPropertyOption, - sortBoxOrder: widget.bloc.options.filesSortBoxOrderOption, + sortProperty: options.filesSortPropertyOption, + sortBoxOrder: options.filesSortBoxOrderOption, presort: const { (property: FilesSortProperty.isFolder, order: SortBoxOrder.ascending), }, diff --git a/packages/neon/neon_files/lib/src/widgets/dialog.dart b/packages/neon/neon_files/lib/src/widgets/dialog.dart index ef804089325..73e7834c550 100644 --- a/packages/neon/neon_files/lib/src/widgets/dialog.dart +++ b/packages/neon/neon_files/lib/src/widgets/dialog.dart @@ -9,6 +9,7 @@ import 'package:image_picker/image_picker.dart'; import 'package:neon_files/l10n/localizations.dart'; import 'package:neon_files/src/blocs/browser.dart'; import 'package:neon_files/src/blocs/files.dart'; +import 'package:neon_files/src/options.dart'; import 'package:neon_files/src/utils/dialog.dart'; import 'package:neon_files/src/widgets/browser_view.dart'; import 'package:neon_framework/platform.dart'; @@ -73,7 +74,7 @@ class _FilesChooseCreateModalState extends State { } Future confirmUpload(int size) async { - final sizeWarning = widget.bloc.options.uploadSizeWarning.value; + final sizeWarning = NeonProvider.of(context).uploadSizeWarning.value; if (sizeWarning != null) { if (size > sizeWarning) { final result = await showUploadConfirmationDialog(context, sizeWarning, size); diff --git a/packages/neon/neon_files/lib/src/widgets/file_list_tile.dart b/packages/neon/neon_files/lib/src/widgets/file_list_tile.dart index ebc6d0e548a..3a1fa53a225 100644 --- a/packages/neon/neon_files/lib/src/widgets/file_list_tile.dart +++ b/packages/neon/neon_files/lib/src/widgets/file_list_tile.dart @@ -4,11 +4,13 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart import 'package:neon_files/src/blocs/browser.dart'; import 'package:neon_files/src/blocs/files.dart'; import 'package:neon_files/src/models/file_details.dart'; +import 'package:neon_files/src/options.dart'; import 'package:neon_files/src/utils/dialog.dart'; import 'package:neon_files/src/utils/task.dart'; import 'package:neon_files/src/widgets/actions.dart'; import 'package:neon_files/src/widgets/file_preview.dart'; import 'package:neon_framework/theme.dart'; +import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; class FileListTile extends StatelessWidget { @@ -27,7 +29,7 @@ class FileListTile extends StatelessWidget { if (details.isDirectory) { browserBloc.setPath(details.uri); } else if (browserBloc.mode == FilesBrowserMode.browser) { - final sizeWarning = bloc.options.downloadSizeWarning.value; + final sizeWarning = NeonProvider.of(context).downloadSizeWarning.value; if (sizeWarning != null && details.size != null && details.size! > sizeWarning) { final decision = await showDownloadConfirmationDialog(context, sizeWarning, details.size!); diff --git a/packages/neon/neon_files/lib/src/widgets/file_preview.dart b/packages/neon/neon_files/lib/src/widgets/file_preview.dart index a75eac17462..cc94707a7ff 100644 --- a/packages/neon/neon_files/lib/src/widgets/file_preview.dart +++ b/packages/neon/neon_files/lib/src/widgets/file_preview.dart @@ -2,6 +2,7 @@ import 'package:file_icons/file_icons.dart'; import 'package:flutter/material.dart'; import 'package:neon_files/src/blocs/files.dart'; import 'package:neon_files/src/models/file_details.dart'; +import 'package:neon_files/src/options.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/theme.dart'; import 'package:neon_framework/utils.dart'; @@ -46,7 +47,7 @@ class FilePreview extends StatelessWidget { } return ValueListenableBuilder( - valueListenable: bloc.options.showPreviewsOption, + valueListenable: NeonProvider.of(context).showPreviewsOption, builder: (context, showPreviews, _) { if (showPreviews && (details.hasPreview ?? false)) { final preview = FilePreviewImage( diff --git a/packages/neon/neon_news/lib/src/blocs/articles.dart b/packages/neon/neon_news/lib/src/blocs/articles.dart index 3cf59637135..ae24b1b980f 100644 --- a/packages/neon/neon_news/lib/src/blocs/articles.dart +++ b/packages/neon/neon_news/lib/src/blocs/articles.dart @@ -44,8 +44,6 @@ sealed class NewsArticlesBloc implements InteractiveBloc { BehaviorSubject get filterType; - NewsOptions get options; - ListType? get listType; } @@ -79,7 +77,6 @@ class _NewsArticlesBloc extends InteractiveBloc implements NewsArticlesBloc { final log = Logger('NewsArticlesBloc'); final NewsBloc _newsBloc; - @override final NewsOptions options; final Account account; final int? id; diff --git a/packages/neon/neon_news/lib/src/blocs/news.dart b/packages/neon/neon_news/lib/src/blocs/news.dart index bfe34e1d145..ca7bca68f78 100644 --- a/packages/neon/neon_news/lib/src/blocs/news.dart +++ b/packages/neon/neon_news/lib/src/blocs/news.dart @@ -40,8 +40,6 @@ sealed class NewsBloc implements InteractiveBloc { BehaviorSubject get unreadCounter; - NewsOptions get options; - NewsMainArticlesBloc get mainArticlesBloc; } diff --git a/packages/neon/neon_news/lib/src/pages/article.dart b/packages/neon/neon_news/lib/src/pages/article.dart index a31f3e16ce2..a96fa26f7fe 100644 --- a/packages/neon/neon_news/lib/src/pages/article.dart +++ b/packages/neon/neon_news/lib/src/pages/article.dart @@ -4,10 +4,12 @@ import 'package:flutter/material.dart'; import 'package:flutter_html/flutter_html.dart'; import 'package:neon_framework/platform.dart'; import 'package:neon_framework/theme.dart'; +import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; import 'package:neon_news/l10n/localizations.dart'; import 'package:neon_news/src/blocs/article.dart'; import 'package:neon_news/src/blocs/articles.dart'; +import 'package:neon_news/src/options.dart'; import 'package:share_plus/share_plus.dart'; import 'package:url_launcher/url_launcher_string.dart'; import 'package:wakelock_plus/wakelock_plus.dart'; @@ -89,7 +91,11 @@ class _NewsArticlePageState extends State { Future _startMarkAsReadTimer() async { if (await widget.bloc.unread.first) { - if (widget.articlesBloc.options.articleDisableMarkAsReadTimeoutOption.value) { + if (!mounted) { + return; + } + + if (NeonProvider.of(context).articleDisableMarkAsReadTimeoutOption.value) { widget.bloc.markArticleAsRead(); } else { _markAsReadTimer = Timer(const Duration(seconds: 3), () async { diff --git a/packages/neon/neon_news/lib/src/pages/feed.dart b/packages/neon/neon_news/lib/src/pages/feed.dart index 87687023ee5..6716139b41d 100644 --- a/packages/neon/neon_news/lib/src/pages/feed.dart +++ b/packages/neon/neon_news/lib/src/pages/feed.dart @@ -3,6 +3,7 @@ import 'package:neon_framework/models.dart'; import 'package:neon_framework/utils.dart'; import 'package:neon_news/src/blocs/articles.dart'; import 'package:neon_news/src/blocs/news.dart'; +import 'package:neon_news/src/options.dart'; import 'package:neon_news/src/widgets/articles_view.dart'; import 'package:nextcloud/news.dart' as news; @@ -27,7 +28,7 @@ class NewsFeedPage extends StatelessWidget { child: NewsArticlesView( bloc: NewsArticlesBloc( newsBloc: bloc, - options: bloc.options, + options: NeonProvider.of(context), account: NeonProvider.of(context), id: feed.id, listType: ListType.feed, diff --git a/packages/neon/neon_news/lib/src/pages/main.dart b/packages/neon/neon_news/lib/src/pages/main.dart index d171649d3f6..edbdbba1392 100644 --- a/packages/neon/neon_news/lib/src/pages/main.dart +++ b/packages/neon/neon_news/lib/src/pages/main.dart @@ -6,6 +6,7 @@ import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; import 'package:neon_news/l10n/localizations.dart'; import 'package:neon_news/src/blocs/news.dart'; +import 'package:neon_news/src/options.dart'; import 'package:neon_news/src/widgets/articles_view.dart'; import 'package:neon_news/src/widgets/feed_floating_action_button.dart'; import 'package:neon_news/src/widgets/feeds_view.dart'; @@ -23,13 +24,14 @@ class NewsMainPage extends StatefulWidget { class _NewsMainPageState extends State { late NewsBloc bloc; - late int _index = bloc.options.defaultCategoryOption.value.index; + late int index; late final StreamSubscription errorsSubscription; @override void initState() { super.initState(); bloc = NeonProvider.of(context); + index = NeonProvider.of(context).defaultCategoryOption.value.index; errorsSubscription = bloc.errors.listen((error) { NeonError.showSnackbar(context, error); @@ -67,10 +69,10 @@ class _NewsMainPageState extends State { return Scaffold( resizeToAvoidBottomInset: false, bottomNavigationBar: BottomNavigationBar( - currentIndex: _index, + currentIndex: index, onTap: (index) { setState(() { - _index = index; + this.index = index; }); }, items: [ @@ -88,8 +90,8 @@ class _NewsMainPageState extends State { ), ], ), - body: views[_index], - floatingActionButton: floatingActionButtons[_index], + body: views[index], + floatingActionButton: floatingActionButtons[index], ); } } diff --git a/packages/neon/neon_news/lib/src/widgets/articles_view.dart b/packages/neon/neon_news/lib/src/widgets/articles_view.dart index af7b81e4fc4..fe09acb1c9d 100644 --- a/packages/neon/neon_news/lib/src/widgets/articles_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/articles_view.dart @@ -42,6 +42,7 @@ class NewsArticlesView extends StatefulWidget { class _NewsArticlesViewState extends State { late final StreamSubscription errorsSubscription; + late final NewsOptions options; @override void initState() { @@ -50,6 +51,8 @@ class _NewsArticlesViewState extends State { errorsSubscription = widget.bloc.errors.listen((error) { NeonError.showSnackbar(context, error); }); + + options = NeonProvider.of(context); } @override @@ -67,8 +70,8 @@ class _NewsArticlesViewState extends State { subject: widget.bloc.articles, builder: (context, articles) => SortBoxBuilder( sortBox: articlesSortBox, - sortProperty: widget.newsBloc.options.articlesSortPropertyOption, - sortBoxOrder: widget.newsBloc.options.articlesSortBoxOrderOption, + sortProperty: options.articlesSortPropertyOption, + sortBoxOrder: options.articlesSortBoxOrderOption, input: articles.data?.toList(), builder: (context, sorted) => NeonListView( scrollKey: 'news-articles', @@ -219,7 +222,7 @@ class _NewsArticlesViewState extends State { } }, onTap: () async { - final viewType = widget.newsBloc.options.articleViewTypeOption.value; + final viewType = options.articleViewTypeOption.value; String? bodyData; try { bodyData = _fixArticleBody(article.body); diff --git a/packages/neon/neon_news/lib/src/widgets/feeds_view.dart b/packages/neon/neon_news/lib/src/widgets/feeds_view.dart index be435a3b626..853c8acd432 100644 --- a/packages/neon/neon_news/lib/src/widgets/feeds_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/feeds_view.dart @@ -6,6 +6,7 @@ import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; import 'package:neon_news/l10n/localizations.dart'; import 'package:neon_news/src/blocs/news.dart'; +import 'package:neon_news/src/options.dart'; import 'package:neon_news/src/pages/feed.dart'; import 'package:neon_news/src/sort/feeds.dart'; import 'package:neon_news/src/utils/dialog.dart'; @@ -25,14 +26,16 @@ class NewsFeedsView extends StatelessWidget { @override Widget build(BuildContext context) { + final options = NeonProvider.of(context); + return ResultBuilder.behaviorSubject( subject: bloc.folders, builder: (context, folders) => ResultBuilder.behaviorSubject( subject: bloc.feeds, builder: (context, feeds) => SortBoxBuilder( sortBox: feedsSortBox, - sortProperty: bloc.options.feedsSortPropertyOption, - sortBoxOrder: bloc.options.feedsSortBoxOrderOption, + sortProperty: options.feedsSortPropertyOption, + sortBoxOrder: options.feedsSortBoxOrderOption, input: folders.hasData ? feeds.data?.where((f) => folderID == null || f.folderId == folderID).toList() : null, builder: (context, sorted) => NeonListView( scrollKey: 'news-feeds', diff --git a/packages/neon/neon_news/lib/src/widgets/folder_view.dart b/packages/neon/neon_news/lib/src/widgets/folder_view.dart index 005f324327c..59e19c9b6d3 100644 --- a/packages/neon/neon_news/lib/src/widgets/folder_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/folder_view.dart @@ -23,8 +23,16 @@ class NewsFolderView extends StatefulWidget { } class _NewsFolderViewState extends State { - late final option = widget.bloc.options.defaultFolderViewTypeOption; - late DefaultFolderViewType _viewType = option.value; + late final NewsOptions options; + late DefaultFolderViewType viewType; + + @override + void initState() { + super.initState(); + + options = NeonProvider.of(context); + viewType = options.defaultFolderViewTypeOption.value; + } @override Widget build(BuildContext context) { @@ -34,28 +42,28 @@ class _NewsFolderViewState extends State { margin: const EdgeInsets.symmetric(horizontal: 15), child: DropdownButton( isExpanded: true, - value: _viewType, - items: option.values.keys + value: viewType, + items: options.defaultFolderViewTypeOption.values.keys .map( (key) => DropdownMenuItem( value: key, - child: Text(option.values[key]!(context)), + child: Text(options.defaultFolderViewTypeOption.values[key]!(context)), ), ) .toList(), onChanged: (value) { setState(() { - _viewType = value!; + viewType = value!; }); }, ), ), Expanded( - child: _viewType == DefaultFolderViewType.articles + child: viewType == DefaultFolderViewType.articles ? NewsArticlesView( bloc: NewsArticlesBloc( newsBloc: widget.bloc, - options: widget.bloc.options, + options: options, account: NeonProvider.of(context), id: widget.folder.id, listType: ListType.folder, diff --git a/packages/neon/neon_news/lib/src/widgets/folders_view.dart b/packages/neon/neon_news/lib/src/widgets/folders_view.dart index 739631072cd..bdebbd5e908 100644 --- a/packages/neon/neon_news/lib/src/widgets/folders_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/folders_view.dart @@ -2,9 +2,11 @@ import 'package:flutter/material.dart'; import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/sort_box.dart'; import 'package:neon_framework/theme.dart'; +import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; import 'package:neon_news/l10n/localizations.dart'; import 'package:neon_news/src/blocs/news.dart'; +import 'package:neon_news/src/options.dart'; import 'package:neon_news/src/pages/folder.dart'; import 'package:neon_news/src/sort/folders.dart'; import 'package:neon_news/src/utils/dialog.dart'; @@ -19,14 +21,16 @@ class NewsFoldersView extends StatelessWidget { @override Widget build(BuildContext context) { + final options = NeonProvider.of(context); + return ResultBuilder.behaviorSubject( subject: bloc.folders, builder: (context, folders) => ResultBuilder.behaviorSubject( subject: bloc.feeds, builder: (context, feeds) => SortBoxBuilder( sortBox: foldersSortBox, - sortProperty: bloc.options.foldersSortPropertyOption, - sortBoxOrder: bloc.options.foldersSortBoxOrderOption, + sortProperty: options.foldersSortPropertyOption, + sortBoxOrder: options.foldersSortBoxOrderOption, input: feeds.hasData ? [ ...?folders.data, diff --git a/packages/neon/neon_notes/lib/neon_notes.dart b/packages/neon/neon_notes/lib/neon_notes.dart index f462db58a7e..6a2b2c5ff71 100644 --- a/packages/neon/neon_notes/lib/neon_notes.dart +++ b/packages/neon/neon_notes/lib/neon_notes.dart @@ -32,7 +32,6 @@ class NotesApp extends AppImplementation { @override NotesBloc buildBloc(Account account) => NotesBloc( - options: options, account: account, ); diff --git a/packages/neon/neon_notes/lib/src/blocs/note.dart b/packages/neon/neon_notes/lib/src/blocs/note.dart index 03d1e685826..36a3f31402f 100644 --- a/packages/neon/neon_notes/lib/src/blocs/note.dart +++ b/packages/neon/neon_notes/lib/src/blocs/note.dart @@ -5,7 +5,6 @@ import 'package:logging/logging.dart'; import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_notes/src/blocs/notes.dart'; -import 'package:neon_notes/src/options.dart'; import 'package:nextcloud/nextcloud.dart'; import 'package:nextcloud/notes.dart' as notes; import 'package:queue/queue.dart'; @@ -26,8 +25,6 @@ sealed class NotesNoteBloc implements InteractiveBloc { BehaviorSubject get category; - NotesOptions get options; - String get initialContent; String get initialTitle; @@ -71,9 +68,6 @@ class _NotesNoteBloc extends InteractiveBloc implements NotesNoteBloc { }); } - @override - NotesOptions get options => notesBloc.options; - final NotesBloc notesBloc; final Account account; final updateQueue = Queue(); diff --git a/packages/neon/neon_notes/lib/src/blocs/notes.dart b/packages/neon/neon_notes/lib/src/blocs/notes.dart index 065474b7230..63e3e3c5994 100644 --- a/packages/neon/neon_notes/lib/src/blocs/notes.dart +++ b/packages/neon/neon_notes/lib/src/blocs/notes.dart @@ -5,13 +5,11 @@ import 'package:logging/logging.dart'; import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/models.dart'; import 'package:neon_framework/utils.dart'; -import 'package:neon_notes/src/options.dart'; import 'package:nextcloud/notes.dart' as $notes; import 'package:rxdart/rxdart.dart'; sealed class NotesBloc implements InteractiveBloc { factory NotesBloc({ - required NotesOptions options, required Account account, }) = _NotesBloc; @@ -32,13 +30,10 @@ sealed class NotesBloc implements InteractiveBloc { void deleteNote(int id); BehaviorSubject>> get notes; - - NotesOptions get options; } class _NotesBloc extends InteractiveBloc implements NotesBloc { _NotesBloc({ - required this.options, required this.account, }) { unawaited(refresh()); @@ -47,8 +42,6 @@ class _NotesBloc extends InteractiveBloc implements NotesBloc { @override final log = Logger('NotesBloc'); - @override - final NotesOptions options; final Account account; @override diff --git a/packages/neon/neon_notes/lib/src/pages/main.dart b/packages/neon/neon_notes/lib/src/pages/main.dart index 67b230faf12..82784882797 100644 --- a/packages/neon/neon_notes/lib/src/pages/main.dart +++ b/packages/neon/neon_notes/lib/src/pages/main.dart @@ -5,6 +5,7 @@ import 'package:neon_framework/theme.dart'; import 'package:neon_framework/utils.dart'; import 'package:neon_notes/l10n/localizations.dart'; import 'package:neon_notes/src/blocs/notes.dart'; +import 'package:neon_notes/src/options.dart'; import 'package:neon_notes/src/utils/exception_handler.dart'; import 'package:neon_notes/src/widgets/categories_view.dart'; import 'package:neon_notes/src/widgets/notes_floating_action_button.dart'; @@ -21,7 +22,7 @@ class NotesMainPage extends StatefulWidget { class _NotesMainPageState extends State { late NotesBloc bloc; - late int _index = bloc.options.defaultCategoryOption.value.index; + late int index; late final StreamSubscription errorsSubscription; @override @@ -30,6 +31,8 @@ class _NotesMainPageState extends State { bloc = NeonProvider.of(context); + index = NeonProvider.of(context).defaultCategoryOption.value.index; + errorsSubscription = bloc.errors.listen((error) { handleNotesException(context, error); }); @@ -61,10 +64,10 @@ class _NotesMainPageState extends State { return Scaffold( resizeToAvoidBottomInset: false, bottomNavigationBar: BottomNavigationBar( - currentIndex: _index, + currentIndex: index, onTap: (index) { setState(() { - _index = index; + this.index = index; }); }, items: [ @@ -78,8 +81,8 @@ class _NotesMainPageState extends State { ), ], ), - body: views[_index], - floatingActionButton: floatingActionButtons[_index], + body: views[index], + floatingActionButton: floatingActionButtons[index], ); } } diff --git a/packages/neon/neon_notes/lib/src/pages/note.dart b/packages/neon/neon_notes/lib/src/pages/note.dart index 43a341c702e..7158458cca8 100644 --- a/packages/neon/neon_notes/lib/src/pages/note.dart +++ b/packages/neon/neon_notes/lib/src/pages/note.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:neon_framework/theme.dart'; +import 'package:neon_framework/utils.dart'; import 'package:neon_notes/l10n/localizations.dart'; import 'package:neon_notes/src/blocs/note.dart'; import 'package:neon_notes/src/blocs/notes.dart'; @@ -62,7 +63,7 @@ class _NotesNotePageState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { unawaited(WakelockPlus.enable()); - if (widget.bloc.options.defaultNoteViewTypeOption.value == DefaultNoteViewType.edit || + if (NeonProvider.of(context).defaultNoteViewTypeOption.value == DefaultNoteViewType.edit || widget.bloc.initialContent.isEmpty) { setState(() { _showEditor = true; diff --git a/packages/neon/neon_notes/lib/src/widgets/categories_view.dart b/packages/neon/neon_notes/lib/src/widgets/categories_view.dart index d66845d1399..5ccf623dad1 100644 --- a/packages/neon/neon_notes/lib/src/widgets/categories_view.dart +++ b/packages/neon/neon_notes/lib/src/widgets/categories_view.dart @@ -2,9 +2,11 @@ import 'package:flutter/material.dart'; import 'package:neon_framework/blocs.dart'; import 'package:neon_framework/sort_box.dart'; import 'package:neon_framework/theme.dart'; +import 'package:neon_framework/utils.dart'; import 'package:neon_framework/widgets.dart'; import 'package:neon_notes/l10n/localizations.dart'; import 'package:neon_notes/src/blocs/notes.dart'; +import 'package:neon_notes/src/options.dart'; import 'package:neon_notes/src/pages/category.dart'; import 'package:neon_notes/src/sort/categories.dart'; import 'package:neon_notes/src/utils/category_color.dart'; @@ -19,12 +21,14 @@ class NotesCategoriesView extends StatelessWidget { @override Widget build(BuildContext context) { + final options = NeonProvider.of(context); + return ResultBuilder.behaviorSubject( subject: bloc.notes, builder: (context, notes) => SortBoxBuilder( sortBox: categoriesSortBox, - sortProperty: bloc.options.categoriesSortPropertyOption, - sortBoxOrder: bloc.options.categoriesSortBoxOrderOption, + sortProperty: options.categoriesSortPropertyOption, + sortBoxOrder: options.categoriesSortBoxOrderOption, input: notes.data ?.map((note) => note.category) .toSet() diff --git a/packages/neon/neon_notes/lib/src/widgets/notes_view.dart b/packages/neon/neon_notes/lib/src/widgets/notes_view.dart index 2e0699a335e..52544fdebd6 100644 --- a/packages/neon/neon_notes/lib/src/widgets/notes_view.dart +++ b/packages/neon/neon_notes/lib/src/widgets/notes_view.dart @@ -28,6 +28,8 @@ class NotesView extends StatelessWidget { @override Widget build(BuildContext context) { + final options = NeonProvider.of(context); + return ResultBuilder.behaviorSubject( subject: bloc.notes, builder: (context, notesList) => SortBoxBuilder( @@ -35,8 +37,8 @@ class NotesView extends StatelessWidget { presort: const { (property: NotesSortProperty.favorite, order: SortBoxOrder.ascending), }, - sortProperty: bloc.options.notesSortPropertyOption, - sortBoxOrder: bloc.options.notesSortBoxOrderOption, + sortProperty: options.notesSortPropertyOption, + sortBoxOrder: options.notesSortBoxOrderOption, input: category != null ? notesList.data?.where((note) => note.category == category).toList() : notesList.data?.toList(), diff --git a/packages/neon_framework/lib/neon.dart b/packages/neon_framework/lib/neon.dart index e4f7e7b821f..32041569d55 100644 --- a/packages/neon_framework/lib/neon.dart +++ b/packages/neon_framework/lib/neon.dart @@ -89,6 +89,7 @@ Future runNeon({ create: (_) => appImplementations, dispose: (_, appImplementations) => appImplementations.disposeAll(), ), + for (final appImplementation in appImplementations) appImplementation.optionsProvider, Provider.value(value: packageInfo), ], child: NeonApp(neonTheme: theme), diff --git a/packages/neon_framework/lib/src/models/app_implementation.dart b/packages/neon_framework/lib/src/models/app_implementation.dart index b75830a9f0c..5d673844fc7 100644 --- a/packages/neon_framework/lib/src/models/app_implementation.dart +++ b/packages/neon_framework/lib/src/models/app_implementation.dart @@ -64,6 +64,11 @@ abstract class AppImplementation get optionsProvider => Provider.value( + value: options, + ); + /// Checks if the app is supported on the server of the [account]. /// /// A value of `null` means that it can not be known if the app is supported.