|
|
@ -7,10 +7,8 @@ import 'package:neon/src/bloc/result_builder.dart'; |
|
|
|
import 'package:neon/src/blocs/accounts.dart'; |
|
|
|
import 'package:neon/src/blocs/accounts.dart'; |
|
|
|
import 'package:neon/src/blocs/apps.dart'; |
|
|
|
import 'package:neon/src/blocs/apps.dart'; |
|
|
|
import 'package:neon/src/blocs/capabilities.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/models/app_implementation.dart'; |
|
|
|
import 'package:neon/src/router.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/cached_image.dart'; |
|
|
|
import 'package:neon/src/widgets/drawer_destination.dart'; |
|
|
|
import 'package:neon/src/widgets/drawer_destination.dart'; |
|
|
|
import 'package:neon/src/widgets/exception.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 accountsBloc = Provider.of<AccountsBloc>(context, listen: false); |
|
|
|
final capabilitiesBloc = accountsBloc.activeCapabilitiesBloc; |
|
|
|
final capabilitiesBloc = accountsBloc.activeCapabilitiesBloc; |
|
|
|
|
|
|
|
|
|
|
|
final accountSelecor = StreamBuilder<List<Account>>( |
|
|
|
final branding = ResultBuilder<Capabilities>.behaviorSubject( |
|
|
|
stream: accountsBloc.accounts, |
|
|
|
stream: capabilitiesBloc.capabilities, |
|
|
|
builder: (final context, final accountsSnapshot) { |
|
|
|
builder: (final context, final capabilities) { |
|
|
|
final accounts = accountsSnapshot.data; |
|
|
|
if (!capabilities.hasData) { |
|
|
|
if (accounts == null || accounts.length <= 1) { |
|
|
|
return NeonLinearProgressIndicator( |
|
|
|
return const SizedBox.shrink(); |
|
|
|
visible: capabilities.isLoading, |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final items = accounts.map((final account) { |
|
|
|
|
|
|
|
final child = NeonAccountTile( |
|
|
|
|
|
|
|
account: account, |
|
|
|
|
|
|
|
dense: true, |
|
|
|
|
|
|
|
textColor: Theme.of(context).appBarTheme.foregroundColor, |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return DropdownMenuItem( |
|
|
|
if (capabilities.hasError) { |
|
|
|
value: account, |
|
|
|
return NeonException( |
|
|
|
child: child, |
|
|
|
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( |
|
|
|
if (theme == null) { |
|
|
|
stream: capabilitiesBloc.capabilities, |
|
|
|
return const SizedBox(); |
|
|
|
builder: (final context, final capabilities) => DrawerHeader( |
|
|
|
} |
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
return Column( |
|
|
|
), |
|
|
|
|
|
|
|
child: Column( |
|
|
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween, |
|
|
|
children: [ |
|
|
|
children: [ |
|
|
|
if (capabilities.hasData) ...[ |
|
|
|
if (theme.name != null) ...[ |
|
|
|
if (capabilities.requireData.capabilities.theming?.name != null) ...[ |
|
|
|
|
|
|
|
Text( |
|
|
|
Text( |
|
|
|
capabilities.requireData.capabilities.theming!.name!, |
|
|
|
theme.name!, |
|
|
|
style: DefaultTextStyle.of(context).style.copyWith( |
|
|
|
style: DefaultTextStyle.of(context).style.copyWith( |
|
|
|
color: Theme.of(context).appBarTheme.foregroundColor, |
|
|
|
color: Theme.of(context).appBarTheme.foregroundColor, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
if (capabilities.requireData.capabilities.theming?.logo != null) ...[ |
|
|
|
if (theme.logo != null) ...[ |
|
|
|
Flexible( |
|
|
|
Flexible( |
|
|
|
child: NeonCachedImage.url( |
|
|
|
child: NeonCachedImage.url( |
|
|
|
url: capabilities.requireData.capabilities.theming!.logo!, |
|
|
|
url: theme.logo!, |
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
] else ...[ |
|
|
|
|
|
|
|
NeonException( |
|
|
|
|
|
|
|
capabilities.error, |
|
|
|
|
|
|
|
onRetry: capabilitiesBloc.refresh, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
NeonLinearProgressIndicator( |
|
|
|
|
|
|
|
visible: capabilities.isLoading, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
], |
|
|
|
accountSelecor, |
|
|
|
|
|
|
|
], |
|
|
|
], |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DrawerHeader( |
|
|
|
|
|
|
|
decoration: BoxDecoration( |
|
|
|
|
|
|
|
color: Theme.of(context).colorScheme.primary, |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
child: branding, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|