From 0cd0bc28827f67e34d502b2334d0defcc07155a6 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sat, 23 Dec 2023 09:54:55 +0100 Subject: [PATCH] fixup! refactor: Make bloc implementations private --- packages/neon/neon_dashboard/lib/src/pages/main.dart | 2 +- packages/neon/neon_files/lib/src/widgets/browser_view.dart | 2 +- packages/neon/neon_news/lib/src/widgets/articles_view.dart | 6 ++---- packages/neon/neon_news/lib/src/widgets/feeds_view.dart | 2 +- packages/neon/neon_news/lib/src/widgets/folders_view.dart | 2 +- .../neon/neon_notes/lib/src/widgets/categories_view.dart | 2 +- packages/neon/neon_notes/lib/src/widgets/notes_view.dart | 2 +- packages/neon/neon_notifications/lib/src/pages/main.dart | 2 +- packages/neon_framework/lib/src/bloc/bloc.dart | 2 +- .../neon_framework/lib/src/pages/login_check_account.dart | 6 ++---- .../lib/src/widgets/unified_search_results.dart | 2 +- 11 files changed, 13 insertions(+), 17 deletions(-) diff --git a/packages/neon/neon_dashboard/lib/src/pages/main.dart b/packages/neon/neon_dashboard/lib/src/pages/main.dart index 3ce55837e31..8301f56eaee 100644 --- a/packages/neon/neon_dashboard/lib/src/pages/main.dart +++ b/packages/neon/neon_dashboard/lib/src/pages/main.dart @@ -42,7 +42,7 @@ class DashboardMainPage extends StatelessWidget { scrollKey: 'dashboard', isLoading: snapshot.isLoading, error: snapshot.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), sliver: SliverFillRemaining( hasScrollBody: false, child: Center( 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 3f70414185b..3e635e8968c 100644 --- a/packages/neon/neon_files/lib/src/widgets/browser_view.dart +++ b/packages/neon/neon_files/lib/src/widgets/browser_view.dart @@ -126,7 +126,7 @@ class _FilesBrowserViewState extends State { }, isLoading: filesSnapshot.isLoading, error: filesSnapshot.error, - onRefresh: widget.bloc.refresh, + onRefresh: () async => widget.bloc.refresh(), topScrollingChildren: [ FilesBrowserNavigator( uri: uriSnapshot.requireData, 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 aec4c2c044a..9ca8e809ec0 100644 --- a/packages/neon/neon_news/lib/src/widgets/articles_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/articles_view.dart @@ -57,10 +57,8 @@ class _NewsArticlesViewState extends State { isLoading: articles.isLoading || feeds.isLoading, error: articles.error ?? feeds.error, onRefresh: () async { - await Future.wait([ - widget.bloc.refresh(), - widget.newsBloc.refresh(), - ]); + await widget.bloc.refresh(); + await widget.newsBloc.refresh(); }, itemCount: feeds.hasData ? sorted.length : null, itemBuilder: (final context, final index) { 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 3b6d843d5ff..b7d8a7ab19b 100644 --- a/packages/neon/neon_news/lib/src/widgets/feeds_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/feeds_view.dart @@ -40,7 +40,7 @@ class NewsFeedsView extends StatelessWidget { scrollKey: 'news-feeds', isLoading: feeds.isLoading || folders.isLoading, error: feeds.error ?? folders.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), itemCount: sorted.length, itemBuilder: (final context, final index) => _buildFeed( context, 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 e45722fa26f..993ad744261 100644 --- a/packages/neon/neon_news/lib/src/widgets/folders_view.dart +++ b/packages/neon/neon_news/lib/src/widgets/folders_view.dart @@ -41,7 +41,7 @@ class NewsFoldersView extends StatelessWidget { scrollKey: 'news-folders', isLoading: feeds.isLoading || folders.isLoading, error: feeds.error ?? folders.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), itemCount: sorted.length, itemBuilder: (final context, final index) => _buildFolder( context, 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 fd402990868..10830134578 100644 --- a/packages/neon/neon_notes/lib/src/widgets/categories_view.dart +++ b/packages/neon/neon_notes/lib/src/widgets/categories_view.dart @@ -41,7 +41,7 @@ class NotesCategoriesView extends StatelessWidget { scrollKey: 'notes-categories', isLoading: notes.isLoading, error: notes.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), itemCount: sorted.length, itemBuilder: (final context, final index) => _buildCategory( context, 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 72f1683dc3b..516ccfdcf7e 100644 --- a/packages/neon/neon_notes/lib/src/widgets/notes_view.dart +++ b/packages/neon/neon_notes/lib/src/widgets/notes_view.dart @@ -41,7 +41,7 @@ class NotesView extends StatelessWidget { scrollKey: 'notes-notes', isLoading: notesList.isLoading, error: notesList.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), itemCount: sorted.length, itemBuilder: (final context, final index) => _buildNote(context, sorted[index]), ), diff --git a/packages/neon/neon_notifications/lib/src/pages/main.dart b/packages/neon/neon_notifications/lib/src/pages/main.dart index 8ead9636338..d0d244f0ac1 100644 --- a/packages/neon/neon_notifications/lib/src/pages/main.dart +++ b/packages/neon/neon_notifications/lib/src/pages/main.dart @@ -53,7 +53,7 @@ class _NotificationsMainPageState extends State { scrollKey: 'notifications-notifications', isLoading: notifications.isLoading, error: notifications.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), itemCount: notifications.data?.length, itemBuilder: (final context, final index) => _buildNotification(context, notifications.data![index]), ), diff --git a/packages/neon_framework/lib/src/bloc/bloc.dart b/packages/neon_framework/lib/src/bloc/bloc.dart index dade5fcac4d..e9224bcb50a 100644 --- a/packages/neon_framework/lib/src/bloc/bloc.dart +++ b/packages/neon_framework/lib/src/bloc/bloc.dart @@ -35,7 +35,7 @@ abstract class InteractiveBloc extends Bloc { /// Refreshes the state of the bloc. /// /// Commonly involves re-fetching data from the server. - Future refresh(); + FutureOr refresh(); /// Adds an error to the [errors] state. @protected diff --git a/packages/neon_framework/lib/src/pages/login_check_account.dart b/packages/neon_framework/lib/src/pages/login_check_account.dart index f83bc60b893..7ee5fa3dbf2 100644 --- a/packages/neon_framework/lib/src/pages/login_check_account.dart +++ b/packages/neon_framework/lib/src/pages/login_check_account.dart @@ -1,5 +1,3 @@ -import 'dart:async'; - import 'package:flutter/material.dart'; import 'package:meta/meta.dart'; import 'package:neon_framework/l10n/localizations.dart'; @@ -90,13 +88,13 @@ class _LoginCheckAccountPageState extends State { const HomeRoute().go(context); } - : () { + : () async { if (state.hasError && NeonError.getDetails(state.error).isUnauthorized) { Navigator.pop(context); return; } - unawaited(bloc.refresh()); + bloc.refresh(); }, child: Text( state.hasData diff --git a/packages/neon_framework/lib/src/widgets/unified_search_results.dart b/packages/neon_framework/lib/src/widgets/unified_search_results.dart index 25a821820bc..f018009fba7 100644 --- a/packages/neon_framework/lib/src/widgets/unified_search_results.dart +++ b/packages/neon_framework/lib/src/widgets/unified_search_results.dart @@ -35,7 +35,7 @@ class NeonUnifiedSearchResults extends StatelessWidget { scrollKey: 'unified-search', isLoading: results.isLoading, error: results.error, - onRefresh: bloc.refresh, + onRefresh: () async => bloc.refresh(), itemCount: values?.length ?? 0, itemBuilder: (final context, final index) { final snapshot = values![index];