|
|
@ -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) { |
|
|
|
if (capabilities.hasError) { |
|
|
|
final child = NeonAccountTile( |
|
|
|
return NeonException( |
|
|
|
account: account, |
|
|
|
capabilities.error, |
|
|
|
dense: true, |
|
|
|
onRetry: capabilitiesBloc.refresh, |
|
|
|
textColor: Theme.of(context).appBarTheme.foregroundColor, |
|
|
|
|
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return DropdownMenuItem( |
|
|
|
final theme = capabilities.requireData.capabilities.theming; |
|
|
|
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); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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( |
|
|
|
theme.name!, |
|
|
|
capabilities.requireData.capabilities.theming!.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) ...[ |
|
|
|
|
|
|
|
Flexible( |
|
|
|
|
|
|
|
child: NeonCachedImage.url( |
|
|
|
|
|
|
|
url: capabilities.requireData.capabilities.theming!.logo!, |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
), |
|
|
|
|
|
|
|
], |
|
|
|
|
|
|
|
] else ...[ |
|
|
|
|
|
|
|
NeonException( |
|
|
|
|
|
|
|
capabilities.error, |
|
|
|
|
|
|
|
onRetry: capabilitiesBloc.refresh, |
|
|
|
|
|
|
|
), |
|
|
|
), |
|
|
|
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, |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|