From a46c5706f1e88cad083b55ee8b04571901390150 Mon Sep 17 00:00:00 2001 From: Nikolas Rimikis Date: Tue, 11 Jul 2023 18:39:39 +0200 Subject: [PATCH] neon: remove account switcher from drawer --- .../neon/neon/lib/src/widgets/drawer.dart | 106 +++++++----------- 1 file changed, 38 insertions(+), 68 deletions(-) diff --git a/packages/neon/neon/lib/src/widgets/drawer.dart b/packages/neon/neon/lib/src/widgets/drawer.dart index 12fcb937..47779a76 100644 --- a/packages/neon/neon/lib/src/widgets/drawer.dart +++ b/packages/neon/neon/lib/src/widgets/drawer.dart @@ -7,10 +7,8 @@ import 'package:neon/src/bloc/result_builder.dart'; import 'package:neon/src/blocs/accounts.dart'; import 'package:neon/src/blocs/apps.dart'; import 'package:neon/src/blocs/capabilities.dart'; -import 'package:neon/src/models/account.dart'; import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/router.dart'; -import 'package:neon/src/widgets/account_tile.dart'; import 'package:neon/src/widgets/cached_image.dart'; import 'package:neon/src/widgets/drawer_destination.dart'; import 'package:neon/src/widgets/exception.dart'; @@ -123,85 +121,57 @@ class NeonDrawerHeader extends StatelessWidget { final accountsBloc = Provider.of(context, listen: false); final capabilitiesBloc = accountsBloc.activeCapabilitiesBloc; - final accountSelecor = StreamBuilder>( - stream: accountsBloc.accounts, - builder: (final context, final accountsSnapshot) { - final accounts = accountsSnapshot.data; - if (accounts == null || accounts.length <= 1) { - return const SizedBox.shrink(); + final branding = ResultBuilder.behaviorSubject( + stream: capabilitiesBloc.capabilities, + builder: (final context, final capabilities) { + if (!capabilities.hasData) { + return NeonLinearProgressIndicator( + visible: capabilities.isLoading, + ); } - final items = accounts.map((final account) { - final child = NeonAccountTile( - account: account, - dense: true, - textColor: Theme.of(context).appBarTheme.foregroundColor, + if (capabilities.hasError) { + return NeonException( + capabilities.error, + onRetry: capabilitiesBloc.refresh, ); + } - return DropdownMenuItem( - value: account, - child: child, - ); - }).toList(); - - return DropdownButtonHideUnderline( - child: DropdownButton( - isExpanded: true, - dropdownColor: Theme.of(context).colorScheme.primary, - iconEnabledColor: Theme.of(context).colorScheme.onBackground, - value: accountsBloc.activeAccount.value, - items: items, - onChanged: (final account) { - if (account == null) { - return; - } - - accountsBloc.setActiveAccount(account); - }, - ), - ); - }, - ); + final theme = capabilities.requireData.capabilities.theming; - return ResultBuilder.behaviorSubject( - stream: capabilitiesBloc.capabilities, - builder: (final context, final capabilities) => DrawerHeader( - decoration: BoxDecoration( - color: Theme.of(context).colorScheme.primary, - ), - child: Column( + if (theme == null) { + return const SizedBox(); + } + + return Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - if (capabilities.hasData) ...[ - if (capabilities.requireData.capabilities.theming?.name != null) ...[ - Text( - capabilities.requireData.capabilities.theming!.name!, - style: DefaultTextStyle.of(context).style.copyWith( - color: Theme.of(context).appBarTheme.foregroundColor, - ), - ), - ], - if (capabilities.requireData.capabilities.theming?.logo != null) ...[ - Flexible( - child: NeonCachedImage.url( - url: capabilities.requireData.capabilities.theming!.logo!, - ), - ), - ], - ] else ...[ - NeonException( - capabilities.error, - onRetry: capabilitiesBloc.refresh, + if (theme.name != null) ...[ + Text( + theme.name!, + style: DefaultTextStyle.of(context).style.copyWith( + color: Theme.of(context).appBarTheme.foregroundColor, + ), ), - NeonLinearProgressIndicator( - visible: capabilities.isLoading, + ], + if (theme.logo != null) ...[ + Flexible( + child: NeonCachedImage.url( + url: theme.logo!, + ), ), ], - accountSelecor, ], - ), + ); + }, + ); + + return DrawerHeader( + decoration: BoxDecoration( + color: Theme.of(context).colorScheme.primary, ), + child: branding, ); } }