Browse Source

neon: Display user avatars according to size constraints

pull/360/head
jld3103 1 year ago
parent
commit
fad22bf9df
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  1. 4
      packages/neon/neon/lib/src/pages/home.dart
  2. 4
      packages/neon/neon/lib/src/widgets/account_tile.dart
  3. 22
      packages/neon/neon/lib/src/widgets/user_avatar.dart

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

@ -495,12 +495,10 @@ 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,
), ),
), ),
),
], ],
); );

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

@ -33,11 +33,9 @@ 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,
builder: (final context, final userDetails) => Row( builder: (final context, final userDetails) => Row(

22
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,28 +35,30 @@ class _UserAvatarState extends State<NeonUserAvatar> {
} }
@override @override
Widget build(final BuildContext context) { Widget build(final BuildContext context) => LayoutBuilder(
builder: (final context, final constraints) {
final isDark = Theme.of(context).brightness == Brightness.dark; final isDark = Theme.of(context).brightness == Brightness.dark;
final size = (widget.size * MediaQuery.of(context).devicePixelRatio).toInt(); size = constraints.constrain(Size.square(widget.size)).shortestSide;
final pixelSize = (size * MediaQuery.of(context).devicePixelRatio).toInt();
return Stack( return Stack(
alignment: Alignment.center, alignment: Alignment.center,
children: [ children: [
CircleAvatar( CircleAvatar(
radius: widget.size / 2, radius: size / 2,
child: ClipOval( child: ClipOval(
child: NeonCachedApiImage( child: NeonCachedApiImage(
account: widget.account, account: widget.account,
cacheKey: 'avatar-${widget.username}-${isDark ? 'dark' : 'light'}$size', cacheKey: 'avatar-${widget.username}-${isDark ? 'dark' : 'light'}$pixelSize',
download: () async { download: () async {
if (isDark) { if (isDark) {
return widget.account.client.core.getDarkAvatar( return widget.account.client.core.getDarkAvatar(
userId: widget.username, userId: widget.username,
size: size, size: pixelSize,
); );
} else { } else {
return widget.account.client.core.getAvatar( return widget.account.client.core.getAvatar(
userId: widget.username, userId: widget.username,
size: size, size: pixelSize,
); );
} }
}, },
@ -70,11 +73,12 @@ class _UserAvatarState extends State<NeonUserAvatar> {
], ],
], ],
); );
} },
);
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