Browse Source

perf(neon): prevent rebuilds in NotificationIconButton

Signed-off-by: Nikolas Rimikis <leptopoda@users.noreply.github.com>
pull/886/head
Nikolas Rimikis 1 year ago
parent
commit
978af26629
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 30
      packages/neon/neon/lib/src/widgets/app_bar.dart
  2. 11
      packages/neon/neon/lib/src/widgets/app_implementation_icon.dart

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

@ -251,25 +251,19 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
final notificationsImplementationData = notificationsAppImplementation.data!; final notificationsImplementationData = notificationsAppImplementation.data!;
final notificationBloc = notificationsImplementationData.getBloc(_account); final notificationBloc = notificationsImplementationData.getBloc(_account);
return StreamBuilder<int>( return IconButton(
stream: notificationsImplementationData.getUnreadCounter(notificationBloc), key: Key('app-${notificationsImplementationData.id}'),
builder: (final context, final unreadCounterSnapshot) { onPressed: () async {
final unreadCount = unreadCounterSnapshot.data ?? 0; await _openNotifications(notificationsImplementationData);
return IconButton(
key: Key('app-${notificationsImplementationData.id}'),
onPressed: () async {
await _openNotifications(notificationsImplementationData);
},
tooltip: AppLocalizations.of(context).appImplementationName(notificationsImplementationData.id),
icon: NeonAppImplementationIcon(
appImplementation: notificationsImplementationData,
unreadCount: unreadCount,
color: unreadCount > 0
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onBackground,
),
);
}, },
tooltip: AppLocalizations.of(context).appImplementationName(notificationsImplementationData.id),
icon: StreamBuilder<int>(
stream: notificationsImplementationData.getUnreadCounter(notificationBloc),
builder: (final context, final unreadCounterSnapshot) => NeonAppImplementationIcon(
appImplementation: notificationsImplementationData,
unreadCount: unreadCounterSnapshot.data,
),
),
); );
}, },
); );

11
packages/neon/neon/lib/src/widgets/app_implementation_icon.dart

@ -1,4 +1,4 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/material.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:neon/src/models/app_implementation.dart'; import 'package:neon/src/models/app_implementation.dart';
@ -6,7 +6,7 @@ import 'package:neon/src/models/app_implementation.dart';
class NeonAppImplementationIcon extends StatelessWidget { class NeonAppImplementationIcon extends StatelessWidget {
const NeonAppImplementationIcon({ const NeonAppImplementationIcon({
required this.appImplementation, required this.appImplementation,
this.unreadCount = 0, this.unreadCount,
this.color, this.color,
this.size, this.size,
super.key, super.key,
@ -14,7 +14,7 @@ class NeonAppImplementationIcon extends StatelessWidget {
final AppImplementation appImplementation; final AppImplementation appImplementation;
final int unreadCount; final int? unreadCount;
final Color? color; final Color? color;
@ -22,6 +22,11 @@ class NeonAppImplementationIcon extends StatelessWidget {
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) {
final unreadCount = this.unreadCount ?? 0;
final color = this.color ??
(unreadCount > 0 ? Theme.of(context).colorScheme.primary : Theme.of(context).colorScheme.onBackground);
final icon = Container( final icon = Container(
margin: const EdgeInsets.all(5), margin: const EdgeInsets.all(5),
child: appImplementation.buildIcon( child: appImplementation.buildIcon(

Loading…
Cancel
Save