From 7c3c3ca8e631f8b5af24ffc4622db2d75bd6300f Mon Sep 17 00:00:00 2001 From: jld3103 Date: Thu, 28 Sep 2023 06:48:08 +0200 Subject: [PATCH] refactor(neon): Use Stacks conditionally Signed-off-by: jld3103 --- .../src/widgets/app_implementation_icon.dart | 46 ++++++++------ .../neon/lib/src/widgets/user_avatar.dart | 63 ++++++++++--------- 2 files changed, 60 insertions(+), 49 deletions(-) diff --git a/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart b/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart index 240584f7..6a3ba25c 100644 --- a/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart +++ b/packages/neon/neon/lib/src/widgets/app_implementation_icon.dart @@ -21,25 +21,31 @@ class NeonAppImplementationIcon extends StatelessWidget { final double? size; @override - Widget build(final BuildContext context) => Stack( - alignment: Alignment.bottomRight, - children: [ - Container( - margin: const EdgeInsets.all(5), - child: appImplementation.buildIcon( - size: size, - color: color, - ), + Widget build(final BuildContext context) { + final icon = Container( + margin: const EdgeInsets.all(5), + child: appImplementation.buildIcon( + size: size, + color: color, + ), + ); + + if (unreadCount == 0) { + return icon; + } + + return Stack( + alignment: Alignment.bottomRight, + children: [ + icon, + Text( + unreadCount.toString(), + style: TextStyle( + color: color, + fontWeight: FontWeight.bold, ), - if (unreadCount > 0) ...[ - Text( - unreadCount.toString(), - style: TextStyle( - color: color, - fontWeight: FontWeight.bold, - ), - ), - ], - ], - ); + ), + ], + ); + } } diff --git a/packages/neon/neon/lib/src/widgets/user_avatar.dart b/packages/neon/neon/lib/src/widgets/user_avatar.dart index 6e7c3f16..f4277785 100644 --- a/packages/neon/neon/lib/src/widgets/user_avatar.dart +++ b/packages/neon/neon/lib/src/widgets/user_avatar.dart @@ -56,39 +56,44 @@ class _UserAvatarState extends State { final brightness = Theme.of(context).brightness; size = constraints.constrain(Size.square(widget.size ?? largeIconSize)).shortestSide; final pixelSize = (size * MediaQuery.of(context).devicePixelRatio).toInt(); + + final avatar = CircleAvatar( + radius: size / 2, + backgroundColor: widget.backgroundColor, + child: ClipOval( + child: NeonCachedImage.custom( + cacheKey: '${widget.account.id}-avatar-${widget.username}-$brightness$pixelSize', + getImage: () async { + if (brightness == Brightness.dark) { + return (await widget.account.client.core.avatar.getAvatarDark( + userId: widget.username, + size: pixelSize, + )) + .data; + } else { + return (await widget.account.client.core.avatar.getAvatar( + userId: widget.username, + size: pixelSize, + )) + .data; + } + }, + ), + ), + ); + + if (!widget.showStatus) { + return avatar; + } + return Stack( alignment: Alignment.center, children: [ - CircleAvatar( - radius: size / 2, - backgroundColor: widget.backgroundColor, - child: ClipOval( - child: NeonCachedImage.custom( - cacheKey: '${widget.account.id}-avatar-${widget.username}-$brightness$pixelSize', - getImage: () async { - if (brightness == Brightness.dark) { - return (await widget.account.client.core.avatar.getAvatarDark( - userId: widget.username, - size: pixelSize, - )) - .data; - } else { - return (await widget.account.client.core.avatar.getAvatar( - userId: widget.username, - size: pixelSize, - )) - .data; - } - }, - ), - ), + avatar, + ResultBuilder( + stream: _userStatusBloc.statuses.mapNotNull((final statuses) => statuses[widget.username]), + builder: _userStatusIconBuilder, ), - if (widget.showStatus) ...[ - ResultBuilder( - stream: _userStatusBloc.statuses.mapNotNull((final statuses) => statuses[widget.username]), - builder: _userStatusIconBuilder, - ), - ], ], ); },