mirror of
https://github.com/immich-app/immich.git
synced 2026-02-28 01:29:04 +03:00
Some widgets, like Icon widgets, automatically inherit opacity from the icon theme in the context. Many other widgets however, do not. The Immich logo, profile picture, and backup badge are examples of widgets of this. All unsupported toolbar widgets have been updated to support inheriting the opacity from the icon theme. IconButtons internally animate properties like opacity, which is kind of nice, but means we have to do more work to replicate that behaviour for other widgets. In most cases, we can simply use an IconButton widget and forward the correct opacity. The Immich logo however is not a button, and therefore we need to use a custom TweenAnimationBuilder. All widgets are using efficient, native opacity rather than the heavy Opacity widget.
62 lines
2.3 KiB
Dart
62 lines
2.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/domain/models/store.model.dart';
|
|
import 'package:immich_mobile/domain/models/user.model.dart';
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
|
import 'package:immich_mobile/presentation/widgets/images/remote_image_provider.dart';
|
|
|
|
// ignore: must_be_immutable
|
|
class UserCircleAvatar extends ConsumerWidget {
|
|
final UserDto user;
|
|
double size;
|
|
bool hasBorder;
|
|
double opacity;
|
|
|
|
UserCircleAvatar({super.key, this.size = 44, this.hasBorder = false, this.opacity = 1, required this.user});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final userAvatarColor = user.avatarColor.toColor().withValues(alpha: opacity);
|
|
final profileImageUrl =
|
|
'${Store.get(StoreKey.serverEndpoint)}/users/${user.id}/profile-image?d=${user.profileChangedAt.millisecondsSinceEpoch}';
|
|
|
|
final textColor = (user.avatarColor.toColor().computeLuminance() > 0.5 ? Colors.black : Colors.white).withValues(
|
|
alpha: opacity,
|
|
);
|
|
|
|
final textIcon = DefaultTextStyle(
|
|
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 12, color: textColor),
|
|
child: Text(user.name[0].toUpperCase()),
|
|
);
|
|
|
|
return Tooltip(
|
|
message: user.name,
|
|
child: UnconstrainedBox(
|
|
child: Container(
|
|
width: size,
|
|
height: size,
|
|
decoration: BoxDecoration(
|
|
color: userAvatarColor,
|
|
shape: BoxShape.circle,
|
|
border: hasBorder ? Border.all(color: Colors.grey[500]!.withValues(alpha: opacity), width: 1) : null,
|
|
),
|
|
child: user.hasProfileImage
|
|
? ClipRRect(
|
|
borderRadius: BorderRadius.all(Radius.circular(size / 2)),
|
|
child: Image(
|
|
fit: BoxFit.cover,
|
|
width: size,
|
|
height: size,
|
|
image: RemoteImageProvider(url: profileImageUrl),
|
|
errorBuilder: (context, error, stackTrace) => textIcon,
|
|
color: Colors.white.withValues(alpha: opacity),
|
|
colorBlendMode: BlendMode.modulate,
|
|
),
|
|
)
|
|
: Center(child: textIcon),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|