Browse Source

Merge pull request #360 from provokateurin/fix/account-selector-avatar

Fix account selector avatar
pull/341/head
Kate 1 year ago committed by GitHub
parent
commit
7c272ea4b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/neon/neon/lib/src/pages/home.dart
  2. 6
      packages/neon/neon/lib/src/widgets/account_tile.dart
  3. 82
      packages/neon/neon/lib/src/widgets/user_avatar.dart

6
packages/neon/neon/lib/src/pages/home.dart

@ -495,10 +495,8 @@ class _HomePageState extends State<HomePage> {
AccountSettingsRoute(accountid: account.id).go(context); AccountSettingsRoute(accountid: account.id).go(context);
}, },
tooltip: AppLocalizations.of(context).settingsAccount, tooltip: AppLocalizations.of(context).settingsAccount,
icon: IntrinsicWidth( icon: NeonUserAvatar(
child: NeonUserAvatar( account: account,
account: account,
),
), ),
), ),
], ],

6
packages/neon/neon/lib/src/widgets/account_tile.dart

@ -33,10 +33,8 @@ class NeonAccountTile extends StatelessWidget {
vertical: -4, vertical: -4,
) )
: null, : null,
leading: IntrinsicWidth( leading: NeonUserAvatar(
child: NeonUserAvatar( account: account,
account: account,
),
), ),
title: ResultBuilder<NextcloudProvisioningApiUserDetails>( title: ResultBuilder<NextcloudProvisioningApiUserDetails>(
stream: userDetailsBloc.userDetails, stream: userDetailsBloc.userDetails,

82
packages/neon/neon/lib/src/widgets/user_avatar.dart

@ -25,6 +25,7 @@ class NeonUserAvatar extends StatefulWidget {
class _UserAvatarState extends State<NeonUserAvatar> { class _UserAvatarState extends State<NeonUserAvatar> {
late final _userStatusBloc = Provider.of<AccountsBloc>(context, listen: false).getUserStatusesBloc(widget.account); late final _userStatusBloc = Provider.of<AccountsBloc>(context, listen: false).getUserStatusesBloc(widget.account);
late double size;
@override @override
void initState() { void initState() {
@ -34,47 +35,50 @@ class _UserAvatarState extends State<NeonUserAvatar> {
} }
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) => LayoutBuilder(
final isDark = Theme.of(context).brightness == Brightness.dark; builder: (final context, final constraints) {
final size = (widget.size * MediaQuery.of(context).devicePixelRatio).toInt(); final isDark = Theme.of(context).brightness == Brightness.dark;
return Stack( size = constraints.constrain(Size.square(widget.size)).shortestSide;
alignment: Alignment.center, final pixelSize = (size * MediaQuery.of(context).devicePixelRatio).toInt();
children: [ return Stack(
CircleAvatar( alignment: Alignment.center,
radius: widget.size / 2, children: [
child: ClipOval( CircleAvatar(
child: NeonCachedApiImage( radius: size / 2,
account: widget.account, child: ClipOval(
cacheKey: 'avatar-${widget.username}-${isDark ? 'dark' : 'light'}$size', child: NeonCachedApiImage(
download: () async { account: widget.account,
if (isDark) { cacheKey: 'avatar-${widget.username}-${isDark ? 'dark' : 'light'}$pixelSize',
return widget.account.client.core.getDarkAvatar( download: () async {
userId: widget.username, if (isDark) {
size: size, return widget.account.client.core.getDarkAvatar(
); userId: widget.username,
} else { size: pixelSize,
return widget.account.client.core.getAvatar( );
userId: widget.username, } else {
size: size, return widget.account.client.core.getAvatar(
); userId: widget.username,
} size: pixelSize,
}, );
), }
), },
), ),
if (widget.showStatus) ...[ ),
ResultBuilder<NextcloudUserStatusPublicStatus?>( ),
stream: _userStatusBloc.statuses.map((final statuses) => statuses[widget.username]), if (widget.showStatus) ...[
builder: _userStatusIconBuilder, ResultBuilder<NextcloudUserStatusPublicStatus?>(
), stream: _userStatusBloc.statuses.map((final statuses) => statuses[widget.username]),
], builder: _userStatusIconBuilder,
], ),
); ],
} ],
);
},
);
Widget _userStatusIconBuilder(final BuildContext context, final Result<NextcloudUserStatusPublicStatus?> result) { Widget _userStatusIconBuilder(final BuildContext context, final Result<NextcloudUserStatusPublicStatus?> result) {
final hasEmoji = result.data?.icon != null; final hasEmoji = result.data?.icon != null;
final scaledSize = widget.size / (hasEmoji ? 2 : 3); final scaledSize = size / (hasEmoji ? 2 : 3);
Widget? child; Widget? child;
Decoration? decoration; Decoration? decoration;
@ -104,7 +108,7 @@ class _UserAvatarState extends State<NeonUserAvatar> {
} }
return SizedBox.square( return SizedBox.square(
dimension: widget.size, dimension: size,
child: Align( child: Align(
alignment: Alignment.bottomRight, alignment: Alignment.bottomRight,
child: Container( child: Container(

Loading…
Cancel
Save