From c0c268945439c91a80cc90578524c5cb4688e6ce Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 6 Jun 2023 20:05:21 +0200 Subject: [PATCH] neon: inject bloc for every app via provider --- packages/neon/neon/lib/src/blocs/apps.dart | 4 ++++ packages/neon/neon/lib/src/pages/home.dart | 10 +++++++++- .../neon/neon/lib/src/utils/app_implementation.dart | 4 ++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/neon/neon/lib/src/blocs/apps.dart b/packages/neon/neon/lib/src/blocs/apps.dart index 4e7a341a..3654250f 100644 --- a/packages/neon/neon/lib/src/blocs/apps.dart +++ b/packages/neon/neon/lib/src/blocs/apps.dart @@ -144,4 +144,8 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates return _blocs[appImplementation.id] = appImplementation.buildBloc(_account.client) as T; } + + List? getAppProviders() => appImplementations.valueOrNull?.data + ?.map((final appImplementation) => appImplementation.blocProvider(_account.client)) + .toList(); } diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index a3cc9f7b..68d9916b 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -504,7 +504,7 @@ class _HomePageState extends State { ], ); - final body = Builder( + Widget body = Builder( builder: (final context) => Row( children: [ if (navigationMode == NavigationMode.quickBar) ...[ @@ -540,6 +540,14 @@ class _HomePageState extends State { ), ); + final appProviders = _appsBloc.getAppProviders(); + if (appProviders != null) { + body = MultiProvider( + providers: appProviders, + child: body, + ); + } + return WillPopScope( onWillPop: () async { if (_scaffoldKey.currentState!.isDrawerOpen) { diff --git a/packages/neon/neon/lib/src/utils/app_implementation.dart b/packages/neon/neon/lib/src/utils/app_implementation.dart index aea3331e..d04279f9 100644 --- a/packages/neon/neon/lib/src/utils/app_implementation.dart +++ b/packages/neon/neon/lib/src/utils/app_implementation.dart @@ -24,6 +24,10 @@ abstract class AppImplementation blocProvider(final NextcloudClient client) => Provider( + create: (final _) => buildBloc(client), + ); + BehaviorSubject? getUnreadCounter(final AppsBloc appsBloc); Widget buildPage(final BuildContext context, final AppsBloc appsBloc);