Browse Source

neon: NeonAppBar use convenience methods of Result

pull/397/head
Nikolas Rimikis 2 years ago
parent
commit
41f12343e2
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 24
      packages/neon/neon/lib/src/widgets/app_bar.dart

24
packages/neon/neon/lib/src/widgets/app_bar.dart

@ -31,14 +31,14 @@ class NeonAppBar extends StatelessWidget implements PreferredSizeWidget {
children: [ children: [
Row( Row(
children: [ children: [
if (appImplementations.data != null && activeAppIDSnapshot.hasData) ...[ if (appImplementations.hasData && activeAppIDSnapshot.hasData) ...[
Flexible( Flexible(
child: Text( child: Text(
appImplementations.data!.find(activeAppIDSnapshot.data!)!.name(context), appImplementations.requireData.find(activeAppIDSnapshot.data!)!.name(context),
), ),
), ),
], ],
if (appImplementations.error != null) ...[ if (appImplementations.hasError) ...[
const SizedBox( const SizedBox(
width: 8, width: 8,
), ),
@ -113,7 +113,7 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
notificationSubscription = _appsBloc.openNotifications.listen((final _) async { notificationSubscription = _appsBloc.openNotifications.listen((final _) async {
final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull; final notificationsAppImplementation = _appsBloc.notificationsAppImplementation.valueOrNull;
if (notificationsAppImplementation != null) { if (notificationsAppImplementation != null && notificationsAppImplementation.hasData) {
await _openNotifications(notificationsAppImplementation.data!); await _openNotifications(notificationsAppImplementation.data!);
} }
}); });
@ -163,23 +163,25 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
Widget build(final BuildContext context) => ResultBuilder<NotificationsAppInterface?>.behaviorSubject( Widget build(final BuildContext context) => ResultBuilder<NotificationsAppInterface?>.behaviorSubject(
stream: _appsBloc.notificationsAppImplementation, stream: _appsBloc.notificationsAppImplementation,
builder: (final context, final notificationsAppImplementation) { builder: (final context, final notificationsAppImplementation) {
if (notificationsAppImplementation.data == null) { if (!notificationsAppImplementation.hasData) {
return const SizedBox.shrink(); return const SizedBox.shrink();
} }
final notificationsImplementationData = notificationsAppImplementation.data!;
final notificationBloc = notificationsImplementationData.getBloc(_account);
return StreamBuilder<int>( return StreamBuilder<int>(
stream: notificationsAppImplementation.data! stream: notificationsImplementationData.getUnreadCounter(notificationBloc),
.getUnreadCounter(notificationsAppImplementation.data!.getBloc(_account)),
builder: (final context, final unreadCounterSnapshot) { builder: (final context, final unreadCounterSnapshot) {
final unreadCount = unreadCounterSnapshot.data ?? 0; final unreadCount = unreadCounterSnapshot.data ?? 0;
return IconButton( return IconButton(
key: Key('app-${notificationsAppImplementation.data!.id}'), key: Key('app-${notificationsImplementationData.id}'),
onPressed: () async { onPressed: () async {
await _openNotifications(notificationsAppImplementation.data!); await _openNotifications(notificationsImplementationData);
}, },
tooltip: AppLocalizations.of(context).appImplementationName(notificationsAppImplementation.data!.id), tooltip: AppLocalizations.of(context).appImplementationName(notificationsImplementationData.id),
icon: NeonAppImplementationIcon( icon: NeonAppImplementationIcon(
appImplementation: notificationsAppImplementation.data!, appImplementation: notificationsImplementationData,
unreadCount: unreadCount, unreadCount: unreadCount,
color: unreadCount > 0 color: unreadCount > 0
? Theme.of(context).colorScheme.primary ? Theme.of(context).colorScheme.primary

Loading…
Cancel
Save