|
|
|
@ -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<AccountsBloc>(context, listen: false); |
|
|
|
|
final capabilitiesBloc = accountsBloc.activeCapabilitiesBloc; |
|
|
|
|
|
|
|
|
|
final accountSelecor = StreamBuilder<List<Account>>( |
|
|
|
|
stream: accountsBloc.accounts, |
|
|
|
|
builder: (final context, final accountsSnapshot) { |
|
|
|
|
final accounts = accountsSnapshot.data; |
|
|
|
|
if (accounts == null || accounts.length <= 1) { |
|
|
|
|
return const SizedBox.shrink(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
final items = accounts.map((final account) { |
|
|
|
|
final child = NeonAccountTile( |
|
|
|
|
account: account, |
|
|
|
|
dense: true, |
|
|
|
|
textColor: Theme.of(context).appBarTheme.foregroundColor, |
|
|
|
|
final branding = ResultBuilder<Capabilities>.behaviorSubject( |
|
|
|
|
stream: capabilitiesBloc.capabilities, |
|
|
|
|
builder: (final context, final capabilities) { |
|
|
|
|
if (!capabilities.hasData) { |
|
|
|
|
return NeonLinearProgressIndicator( |
|
|
|
|
visible: capabilities.isLoading, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return DropdownMenuItem( |
|
|
|
|
value: account, |
|
|
|
|
child: child, |
|
|
|
|
if (capabilities.hasError) { |
|
|
|
|
return NeonException( |
|
|
|
|
capabilities.error, |
|
|
|
|
onRetry: capabilitiesBloc.refresh, |
|
|
|
|
); |
|
|
|
|
}).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<Capabilities>.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) ...[ |
|
|
|
|
if (theme.name != null) ...[ |
|
|
|
|
Text( |
|
|
|
|
capabilities.requireData.capabilities.theming!.name!, |
|
|
|
|
theme.name!, |
|
|
|
|
style: DefaultTextStyle.of(context).style.copyWith( |
|
|
|
|
color: Theme.of(context).appBarTheme.foregroundColor, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
if (capabilities.requireData.capabilities.theming?.logo != null) ...[ |
|
|
|
|
if (theme.logo != null) ...[ |
|
|
|
|
Flexible( |
|
|
|
|
child: NeonCachedImage.url( |
|
|
|
|
url: capabilities.requireData.capabilities.theming!.logo!, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
] else ...[ |
|
|
|
|
NeonException( |
|
|
|
|
capabilities.error, |
|
|
|
|
onRetry: capabilitiesBloc.refresh, |
|
|
|
|
url: theme.logo!, |
|
|
|
|
), |
|
|
|
|
NeonLinearProgressIndicator( |
|
|
|
|
visible: capabilities.isLoading, |
|
|
|
|
), |
|
|
|
|
], |
|
|
|
|
accountSelecor, |
|
|
|
|
], |
|
|
|
|
); |
|
|
|
|
}, |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return DrawerHeader( |
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
|
), |
|
|
|
|
), |
|
|
|
|
child: branding, |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|