Browse Source

neon: better nullability of AppsBloc.activeAppID

pull/411/head
Nikolas Rimikis 2 years ago
parent
commit
05210c8d23
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 17
      packages/neon/neon/lib/src/blocs/apps.dart
  2. 4
      packages/neon/neon/lib/src/pages/home.dart

17
packages/neon/neon/lib/src/blocs/apps.dart

@ -3,7 +3,7 @@ part of 'blocs.dart';
typedef NextcloudApp = NextcloudCoreNavigationApps_Ocs_Data; typedef NextcloudApp = NextcloudCoreNavigationApps_Ocs_Data;
abstract class AppsBlocEvents { abstract class AppsBlocEvents {
void setActiveApp(final String? appID); void setActiveApp(final String appID);
} }
abstract class AppsBlocStates { abstract class AppsBlocStates {
@ -13,7 +13,7 @@ abstract class AppsBlocStates {
BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation; BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation;
BehaviorSubject<String?> get activeAppID; BehaviorSubject<String> get activeAppID;
BehaviorSubject get openNotifications; BehaviorSubject get openNotifications;
@ -48,7 +48,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} }
} }
if (!activeAppID.hasValue) { if (!activeAppID.hasValue) {
await setActiveApp(initialApp); await setActiveApp(initialApp!);
} }
}), }),
); );
@ -144,7 +144,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} }
@override @override
BehaviorSubject<String?> activeAppID = BehaviorSubject<String?>(); BehaviorSubject<String> activeAppID = BehaviorSubject<String>();
@override @override
BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations = BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations =
@ -175,15 +175,16 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
} }
@override @override
Future setActiveApp(final String? appID) async { Future setActiveApp(final String appID) async {
if (appID != null && final apps = await appImplementations.firstWhere((final a) => a.hasData);
(await appImplementations.firstWhere((final a) => a.hasData)).requireData.tryFind(appID) != null) { if (apps.requireData.tryFind(appID) != null) {
// TODO: make activeAppID distinct
if (activeAppID.valueOrNull != appID) { if (activeAppID.valueOrNull != appID) {
activeAppID.add(appID); activeAppID.add(appID);
} }
} else if (appID == 'notifications') { } else if (appID == 'notifications') {
openNotifications.add(null); openNotifications.add(null);
} else if (appID != null) { } else {
throw Exception('App $appID not found'); throw Exception('App $appID not found');
} }
} }

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

@ -100,7 +100,7 @@ class _HomePageState extends State<HomePage> {
@override @override
Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject( Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: _appsBloc.appImplementations, stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<String?>( builder: (final context, final appImplementations) => StreamBuilder<String>(
stream: _appsBloc.activeAppID, stream: _appsBloc.activeAppID,
builder: (final context, final activeAppIDSnapshot) => OptionBuilder<NavigationMode>( builder: (final context, final activeAppIDSnapshot) => OptionBuilder<NavigationMode>(
option: _globalOptions.navigationMode, option: _globalOptions.navigationMode,
@ -126,7 +126,7 @@ class _HomePageState extends State<HomePage> {
] else ...[ ] else ...[
if (activeAppIDSnapshot.hasData) ...[ if (activeAppIDSnapshot.hasData) ...[
Expanded( Expanded(
child: appImplementations.data!.find(activeAppIDSnapshot.data!).page, child: appImplementations.requireData.find(activeAppIDSnapshot.requireData).page,
), ),
], ],
], ],

Loading…
Cancel
Save