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;
abstract class AppsBlocEvents {
void setActiveApp(final String? appID);
void setActiveApp(final String appID);
}
abstract class AppsBlocStates {
@ -13,7 +13,7 @@ abstract class AppsBlocStates {
BehaviorSubject<Result<NotificationsAppInterface?>> get notificationsAppImplementation;
BehaviorSubject<String?> get activeAppID;
BehaviorSubject<String> get activeAppID;
BehaviorSubject get openNotifications;
@ -48,7 +48,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
}
}
if (!activeAppID.hasValue) {
await setActiveApp(initialApp);
await setActiveApp(initialApp!);
}
}),
);
@ -144,7 +144,7 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
}
@override
BehaviorSubject<String?> activeAppID = BehaviorSubject<String?>();
BehaviorSubject<String> activeAppID = BehaviorSubject<String>();
@override
BehaviorSubject<Result<Iterable<AppImplementation<Bloc, NextcloudAppSpecificOptions>>>> appImplementations =
@ -175,15 +175,16 @@ class AppsBloc extends InteractiveBloc implements AppsBlocEvents, AppsBlocStates
}
@override
Future setActiveApp(final String? appID) async {
if (appID != null &&
(await appImplementations.firstWhere((final a) => a.hasData)).requireData.tryFind(appID) != null) {
Future setActiveApp(final String appID) async {
final apps = await appImplementations.firstWhere((final a) => a.hasData);
if (apps.requireData.tryFind(appID) != null) {
// TODO: make activeAppID distinct
if (activeAppID.valueOrNull != appID) {
activeAppID.add(appID);
}
} else if (appID == 'notifications') {
openNotifications.add(null);
} else if (appID != null) {
} else {
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
Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<String?>(
builder: (final context, final appImplementations) => StreamBuilder<String>(
stream: _appsBloc.activeAppID,
builder: (final context, final activeAppIDSnapshot) => OptionBuilder<NavigationMode>(
option: _globalOptions.navigationMode,
@ -126,7 +126,7 @@ class _HomePageState extends State<HomePage> {
] else ...[
if (activeAppIDSnapshot.hasData) ...[
Expanded(
child: appImplementations.data!.find(activeAppIDSnapshot.data!).page,
child: appImplementations.requireData.find(activeAppIDSnapshot.requireData).page,
),
],
],

Loading…
Cancel
Save