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. 16
      packages/neon/neon/lib/src/widgets/app_bar.dart
  2. 11
      packages/neon/neon/lib/src/widgets/app_implementation_icon.dart

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

@ -251,25 +251,19 @@ class _NotificationIconButtonState extends State<NotificationIconButton> {
final notificationsImplementationData = notificationsAppImplementation.data!;
final notificationBloc = notificationsImplementationData.getBloc(_account);
return StreamBuilder<int>(
stream: notificationsImplementationData.getUnreadCounter(notificationBloc),
builder: (final context, final unreadCounterSnapshot) {
final unreadCount = unreadCounterSnapshot.data ?? 0;
return IconButton(
key: Key('app-${notificationsImplementationData.id}'),
onPressed: () async {
await _openNotifications(notificationsImplementationData);
},
tooltip: AppLocalizations.of(context).appImplementationName(notificationsImplementationData.id),
icon: NeonAppImplementationIcon(
icon: StreamBuilder<int>(
stream: notificationsImplementationData.getUnreadCounter(notificationBloc),
builder: (final context, final unreadCounterSnapshot) => NeonAppImplementationIcon(
appImplementation: notificationsImplementationData,
unreadCount: unreadCount,
color: unreadCount > 0
? Theme.of(context).colorScheme.primary
: Theme.of(context).colorScheme.onBackground,
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:neon/src/models/app_implementation.dart';
@ -6,7 +6,7 @@ import 'package:neon/src/models/app_implementation.dart';
class NeonAppImplementationIcon extends StatelessWidget {
const NeonAppImplementationIcon({
required this.appImplementation,
this.unreadCount = 0,
this.unreadCount,
this.color,
this.size,
super.key,
@ -14,7 +14,7 @@ class NeonAppImplementationIcon extends StatelessWidget {
final AppImplementation appImplementation;
final int unreadCount;
final int? unreadCount;
final Color? color;
@ -22,6 +22,11 @@ class NeonAppImplementationIcon extends StatelessWidget {
@override
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(
margin: const EdgeInsets.all(5),
child: appImplementation.buildIcon(

Loading…
Cancel
Save