From 2c7e8b74c8f1aa0f80d80169d0875876213dbb48 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Thu, 22 Jun 2023 13:53:16 +0200 Subject: [PATCH] neon: refactor page loading --- packages/neon/neon/lib/src/pages/home.dart | 148 +++++++++++---------- 1 file changed, 75 insertions(+), 73 deletions(-) diff --git a/packages/neon/neon/lib/src/pages/home.dart b/packages/neon/neon/lib/src/pages/home.dart index 47f518bb..6b3bbf3c 100644 --- a/packages/neon/neon/lib/src/pages/home.dart +++ b/packages/neon/neon/lib/src/pages/home.dart @@ -98,79 +98,81 @@ class _HomePageState extends State { } @override - Widget build(final BuildContext context) => ResultBuilder>.behaviorSubject( - stream: _appsBloc.appImplementations, - builder: (final context, final appImplementations) => StreamBuilder( + Widget build(final BuildContext context) { + const drawer = NeonDrawer(); + const appBar = NeonAppBar(); + + final appView = ResultBuilder>.behaviorSubject( + stream: _appsBloc.appImplementations, + builder: (final context, final appImplementations) { + if (!appImplementations.hasData) { + return const SizedBox(); + } + + if (appImplementations.requireData.isEmpty) { + return Center( + child: Text( + AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound, + textAlign: TextAlign.center, + ), + ); + } + + return StreamBuilder( stream: _appsBloc.activeApp, - builder: (final context, final activeAppSnapshot) => OptionBuilder( - option: _globalOptions.navigationMode, - builder: (final context, final navigationMode) { - final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible; - - const drawer = NeonDrawer(); - const appBar = NeonAppBar(); - - Widget body = Builder( - builder: (final context) => Column( - children: [ - if (appImplementations.hasData) ...[ - if (appImplementations.requireData.isEmpty) ...[ - Expanded( - child: Center( - child: Text( - AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound, - textAlign: TextAlign.center, - ), - ), - ), - ] else ...[ - if (activeAppSnapshot.hasData) ...[ - Expanded( - child: activeAppSnapshot.requireData.page, - ), - ], - ], - ], - ], - ), - ); - - body = MultiProvider( - providers: _appsBloc.appBlocProviders, - child: Scaffold( - key: _scaffoldKey, - resizeToAvoidBottomInset: false, - drawer: !drawerAlwaysVisible ? drawer : null, - appBar: appBar, - body: body, - ), - ); - - if (drawerAlwaysVisible) { - body = Row( - children: [ - drawer, - Expanded( - child: body, - ), - ], - ); - } - - return WillPopScope( - onWillPop: () async { - if (_scaffoldKey.currentState!.isDrawerOpen) { - Navigator.pop(context); - return true; - } - - _scaffoldKey.currentState!.openDrawer(); - return false; - }, + builder: (final context, final activeAppIDSnapshot) { + if (!activeAppIDSnapshot.hasData) { + return const SizedBox(); + } + + return activeAppIDSnapshot.requireData.page; + }, + ); + }, + ); + + final body = OptionBuilder( + option: _globalOptions.navigationMode, + builder: (final context, final navigationMode) { + final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible; + + final body = Scaffold( + key: _scaffoldKey, + resizeToAvoidBottomInset: false, + drawer: !drawerAlwaysVisible ? drawer : null, + appBar: appBar, + body: appView, + ); + + if (drawerAlwaysVisible) { + return Row( + children: [ + drawer, + Expanded( child: body, - ); - }, - ), - ), - ); + ), + ], + ); + } + + return body; + }, + ); + + return WillPopScope( + onWillPop: () async { + if (_scaffoldKey.currentState!.isDrawerOpen) { + Navigator.pop(context); + return true; + } + + _scaffoldKey.currentState!.openDrawer(); + return false; + }, + child: MultiProvider( + providers: _appsBloc.appBlocProviders, + child: body, + ), + ); + } }