Browse Source

Merge pull request #402 from Leptopoda/refactor/homePage

neon: refactor page loading
pull/415/head
Nikolas Rimikis 2 years ago committed by GitHub
parent
commit
ff8979ccc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 76
      packages/neon/neon/lib/src/pages/home.dart

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

@ -98,56 +98,54 @@ class _HomePageState extends State<HomePage> {
}
@override
Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: _appsBloc.appImplementations,
builder: (final context, final appImplementations) => StreamBuilder<AppImplementation>(
stream: _appsBloc.activeApp,
builder: (final context, final activeAppSnapshot) => OptionBuilder<NavigationMode>(
option: _globalOptions.navigationMode,
builder: (final context, final navigationMode) {
final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible;
Widget build(final BuildContext context) {
const drawer = NeonDrawer();
const appBar = NeonAppBar();
Widget body = Builder(
builder: (final context) => Column(
children: [
if (appImplementations.hasData) ...[
if (appImplementations.requireData.isEmpty) ...[
Expanded(
child: Center(
final appView = ResultBuilder<Iterable<AppImplementation>>.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,
),
),
),
] else ...[
if (activeAppSnapshot.hasData) ...[
Expanded(
child: activeAppSnapshot.requireData.page,
),
],
],
],
],
),
);
}
body = MultiProvider(
providers: _appsBloc.appBlocProviders,
child: Scaffold(
return StreamBuilder<AppImplementation>(
stream: _appsBloc.activeApp,
builder: (final context, final activeAppIDSnapshot) {
if (!activeAppIDSnapshot.hasData) {
return const SizedBox();
}
return activeAppIDSnapshot.requireData.page;
},
);
},
);
final body = OptionBuilder<NavigationMode>(
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: body,
),
body: appView,
);
if (drawerAlwaysVisible) {
body = Row(
return Row(
children: [
drawer,
Expanded(
@ -157,6 +155,10 @@ class _HomePageState extends State<HomePage> {
);
}
return body;
},
);
return WillPopScope(
onWillPop: () async {
if (_scaffoldKey.currentState!.isDrawerOpen) {
@ -167,10 +169,10 @@ class _HomePageState extends State<HomePage> {
_scaffoldKey.currentState!.openDrawer();
return false;
},
child: MultiProvider(
providers: _appsBloc.appBlocProviders,
child: body,
);
},
),
),
);
}
}

Loading…
Cancel
Save