From e55185897af59affdc610a62dbcffa926c051dee Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 28 Aug 2022 11:31:06 +0200 Subject: [PATCH] neon: Fix multi-account text color --- packages/neon/lib/src/pages/home/home.dart | 5 +- .../neon/lib/src/widgets/account_tile.dart | 147 +++++++++--------- 2 files changed, 74 insertions(+), 78 deletions(-) diff --git a/packages/neon/lib/src/pages/home/home.dart b/packages/neon/lib/src/pages/home/home.dart index aada62fe..db63043b 100644 --- a/packages/neon/lib/src/pages/home/home.dart +++ b/packages/neon/lib/src/pages/home/home.dart @@ -378,7 +378,9 @@ class _HomePageState extends State with tray.TrayListener, WindowListe if (accounts.length > 1) ...[ Text( account.client.humanReadableID, - style: Theme.of(context).textTheme.bodySmall, + style: Theme.of(context).textTheme.bodySmall!.copyWith( + color: Theme.of(context).colorScheme.onPrimary, + ), ), ], ], @@ -478,6 +480,7 @@ class _HomePageState extends State with tray.TrayListener, WindowListe child: AccountTile( account: account, dense: true, + textColor: Theme.of(context).colorScheme.onPrimary, ), ), ) diff --git a/packages/neon/lib/src/widgets/account_tile.dart b/packages/neon/lib/src/widgets/account_tile.dart index 88545565..ad661553 100644 --- a/packages/neon/lib/src/widgets/account_tile.dart +++ b/packages/neon/lib/src/widgets/account_tile.dart @@ -1,11 +1,12 @@ part of '../neon.dart'; -class AccountTile extends StatefulWidget { +class AccountTile extends StatelessWidget { const AccountTile({ required this.account, this.color, this.trailing, this.onTap, + this.textColor, this.dense = false, super.key, }); @@ -14,88 +15,80 @@ class AccountTile extends StatefulWidget { final Color? color; final Widget? trailing; final VoidCallback? onTap; + final Color? textColor; final bool dense; @override - State createState() => _AccountTileState(); -} - -class _AccountTileState extends State { - late final UserDetailsBloc _userDetailsBloc; - - @override - void initState() { - super.initState(); - - _userDetailsBloc = RxBlocProvider.of(context).getUserDetailsBloc(widget.account); - } + Widget build(final BuildContext context) { + final userDetailsBloc = RxBlocProvider.of(context).getUserDetailsBloc(account); - @override - Widget build(final BuildContext context) => ListTile( - onTap: widget.onTap, - dense: widget.dense, - contentPadding: widget.dense ? EdgeInsets.zero : null, - visualDensity: widget.dense - ? const VisualDensity( - horizontal: -4, - vertical: -4, - ) - : null, - leading: AccountAvatar( - account: widget.account, - requestManager: Provider.of(context), - ), - title: StandardRxResultBuilder( - bloc: _userDetailsBloc, - state: (final bloc) => bloc.userDetails, - builder: ( - final context, - final userDetailsData, - final userDetailsError, - final userDetailsLoading, - final _, - ) => - Row( - children: [ - if (userDetailsData != null) ...[ - Text( - userDetailsData.getDisplayName()!, - style: Theme.of(context).textTheme.bodyLarge!.copyWith( - color: widget.color, - ), - ), - ], - if (userDetailsLoading) ...[ - const SizedBox( - width: 5, - ), - SizedBox( - height: 10, - width: 10, - child: CircularProgressIndicator( - strokeWidth: 1, - color: widget.color, - ), - ), - ], - if (userDetailsError != null) ...[ - const SizedBox( - width: 5, - ), - Icon( - Icons.error_outline, - size: 20, - color: widget.color, + return ListTile( + textColor: textColor, + onTap: onTap, + dense: dense, + contentPadding: dense ? EdgeInsets.zero : null, + visualDensity: dense + ? const VisualDensity( + horizontal: -4, + vertical: -4, + ) + : null, + leading: AccountAvatar( + account: account, + requestManager: Provider.of(context), + ), + title: StandardRxResultBuilder( + bloc: userDetailsBloc, + state: (final bloc) => bloc.userDetails, + builder: ( + final context, + final userDetailsData, + final userDetailsError, + final userDetailsLoading, + final _, + ) => + Row( + children: [ + if (userDetailsData != null) ...[ + Text( + userDetailsData.getDisplayName()!, + style: Theme.of(context).textTheme.bodyLarge!.copyWith( + color: textColor, + ), + ), + ], + if (userDetailsLoading) ...[ + const SizedBox( + width: 5, + ), + SizedBox( + height: 10, + width: 10, + child: CircularProgressIndicator( + strokeWidth: 1, + color: color, ), - ], + ), ], - ), - ), - subtitle: Text( - widget.account.client.humanReadableID, - style: Theme.of(context).textTheme.bodySmall!.copyWith( - color: widget.color, + if (userDetailsError != null) ...[ + const SizedBox( + width: 5, + ), + Icon( + Icons.error_outline, + size: 20, + color: color, ), + ], + ], ), - ); + ), + subtitle: Text( + account.client.humanReadableID, + style: Theme.of(context).textTheme.bodySmall!.copyWith( + color: textColor, + ), + ), + ); + } }