Browse Source

neon: remove unused builders from HomePage

pull/397/head
Nikolas Rimikis 1 year ago
parent
commit
ed618cab0b
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 162
      packages/neon/neon/lib/src/pages/home.dart

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

@ -11,16 +11,13 @@ class HomePage extends StatefulWidget {
State<HomePage> createState() => _HomePageState(); State<HomePage> createState() => _HomePageState();
} }
// ignore: prefer_mixin
class _HomePageState extends State<HomePage> { class _HomePageState extends State<HomePage> {
final _scaffoldKey = GlobalKey<ScaffoldState>(); final _scaffoldKey = GlobalKey<ScaffoldState>();
final drawerScrollController = ScrollController();
late Account _account; late Account _account;
late GlobalOptions _globalOptions; late GlobalOptions _globalOptions;
late AccountsBloc _accountsBloc; late AccountsBloc _accountsBloc;
late AppsBloc _appsBloc; late AppsBloc _appsBloc;
late CapabilitiesBloc _capabilitiesBloc;
@override @override
void initState() { void initState() {
@ -29,7 +26,6 @@ class _HomePageState extends State<HomePage> {
_accountsBloc = Provider.of<AccountsBloc>(context, listen: false); _accountsBloc = Provider.of<AccountsBloc>(context, listen: false);
_account = _accountsBloc.activeAccount.value!; _account = _accountsBloc.activeAccount.value!;
_appsBloc = _accountsBloc.activeAppsBloc; _appsBloc = _accountsBloc.activeAppsBloc;
_capabilitiesBloc = _accountsBloc.activeCapabilitiesBloc;
_appsBloc.appVersions.listen((final values) { _appsBloc.appVersions.listen((final values) {
if (values == null || !mounted) { if (values == null || !mounted) {
@ -98,100 +94,78 @@ class _HomePageState extends State<HomePage> {
} }
@override @override
void dispose() { Widget build(final BuildContext context) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
drawerScrollController.dispose(); stream: _appsBloc.appImplementations,
super.dispose(); builder: (final context, final appImplementations) => StreamBuilder<String?>(
} stream: _appsBloc.activeAppID,
builder: (final context, final activeAppIDSnapshot) => OptionBuilder<NavigationMode>(
@override option: _globalOptions.navigationMode,
Widget build(final BuildContext context) => ResultBuilder<Capabilities>.behaviorSubject( builder: (final context, final navigationMode) {
stream: _capabilitiesBloc.capabilities, final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible;
builder: (final context, final capabilities) => ResultBuilder<Iterable<AppImplementation>>.behaviorSubject(
stream: _appsBloc.appImplementations, const drawer = NeonDrawer();
builder: (final context, final appImplementations) => const appBar = NeonAppBar();
ResultBuilder<NotificationsAppInterface?>.behaviorSubject(
stream: _appsBloc.notificationsAppImplementation, Widget body = Builder(
builder: (final context, final notificationsAppImplementation) => StreamBuilder<String?>( builder: (final context) => Column(
stream: _appsBloc.activeAppID, children: [
builder: (final context, final activeAppIDSnapshot) => StreamBuilder<List<Account>>( if (appImplementations.data != null) ...[
stream: _accountsBloc.accounts, if (appImplementations.data!.isEmpty) ...[
builder: (final context, final accountsSnapshot) => OptionBuilder<NavigationMode>( Expanded(
option: _globalOptions.navigationMode, child: Center(
builder: (final context, final navigationMode) { child: Text(
final accounts = accountsSnapshot.data; AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound,
final account = accounts?.find(_account.id); textAlign: TextAlign.center,
if (accounts == null || account == null) { ),
return const Scaffold(); ),
} ),
] else ...[
final drawerAlwaysVisible = navigationMode == NavigationMode.drawerAlwaysVisible; if (activeAppIDSnapshot.hasData) ...[
const drawer = NeonDrawer();
const appBar = NeonAppBar();
Widget body = Builder(
builder: (final context) => Column(
children: [
if (appImplementations.data != null) ...[
if (appImplementations.data!.isEmpty) ...[
Expanded(
child: Center(
child: Text(
AppLocalizations.of(context).errorNoCompatibleNextcloudAppsFound,
textAlign: TextAlign.center,
),
),
),
] else ...[
if (activeAppIDSnapshot.hasData) ...[
Expanded(
child: appImplementations.data!.find(activeAppIDSnapshot.data!)!.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( Expanded(
child: body, child: appImplementations.data!.find(activeAppIDSnapshot.data!)!.page,
), ),
], ],
); ],
} ],
],
return WillPopScope(
onWillPop: () async {
if (_scaffoldKey.currentState!.isDrawerOpen) {
Navigator.pop(context);
return true;
}
_scaffoldKey.currentState!.openDrawer();
return false;
},
child: body,
);
},
), ),
), );
),
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;
},
child: body,
);
},
), ),
), ),
); );

Loading…
Cancel
Save