Browse Source

neon: inject bloc for every app via provider

pull/363/head
Nikolas Rimikis 1 year ago
parent
commit
c0c2689454
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 4
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 10
      packages/neon/neon/lib/src/pages/home.dart
  3. 4
      packages/neon/neon/lib/src/utils/app_implementation.dart

4
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; return _blocs[appImplementation.id] = appImplementation.buildBloc(_account.client) as T;
} }
List<Provider>? getAppProviders() => appImplementations.valueOrNull?.data
?.map((final appImplementation) => appImplementation.blocProvider(_account.client))
.toList();
} }

10
packages/neon/neon/lib/src/pages/home.dart

@ -504,7 +504,7 @@ class _HomePageState extends State<HomePage> {
], ],
); );
final body = Builder( Widget body = Builder(
builder: (final context) => Row( builder: (final context) => Row(
children: [ children: [
if (navigationMode == NavigationMode.quickBar) ...[ if (navigationMode == NavigationMode.quickBar) ...[
@ -540,6 +540,14 @@ class _HomePageState extends State<HomePage> {
), ),
); );
final appProviders = _appsBloc.getAppProviders();
if (appProviders != null) {
body = MultiProvider(
providers: appProviders,
child: body,
);
}
return WillPopScope( return WillPopScope(
onWillPop: () async { onWillPop: () async {
if (_scaffoldKey.currentState!.isDrawerOpen) { if (_scaffoldKey.currentState!.isDrawerOpen) {

4
packages/neon/neon/lib/src/utils/app_implementation.dart

@ -24,6 +24,10 @@ abstract class AppImplementation<T extends Bloc, R extends NextcloudAppSpecificO
T buildBloc(final NextcloudClient client); T buildBloc(final NextcloudClient client);
Provider<T> blocProvider(final NextcloudClient client) => Provider<T>(
create: (final _) => buildBloc(client),
);
BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc); BehaviorSubject<int>? getUnreadCounter(final AppsBloc appsBloc);
Widget buildPage(final BuildContext context, final AppsBloc appsBloc); Widget buildPage(final BuildContext context, final AppsBloc appsBloc);

Loading…
Cancel
Save