2023-08-18 06:26:12 +02:00
|
|
|
import 'dart:math';
|
|
|
|
|
2023-10-30 19:17:34 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2023-08-18 06:26:12 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/user.dart';
|
|
|
|
import 'package:immich_mobile/shared/ui/transparent_image.dart';
|
|
|
|
|
|
|
|
// ignore: must_be_immutable
|
|
|
|
class UserCircleAvatar extends ConsumerWidget {
|
|
|
|
final User user;
|
|
|
|
double radius;
|
|
|
|
double size;
|
|
|
|
|
|
|
|
UserCircleAvatar({
|
|
|
|
super.key,
|
|
|
|
this.radius = 22,
|
|
|
|
this.size = 44,
|
|
|
|
required this.user,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-11-14 05:10:35 +02:00
|
|
|
bool isDarkTheme = Theme.of(context).brightness == Brightness.dark;
|
2023-08-18 06:26:12 +02:00
|
|
|
final profileImageUrl =
|
|
|
|
'${Store.get(StoreKey.serverEndpoint)}/user/profile-image/${user.id}?d=${Random().nextInt(1024)}';
|
2023-11-06 17:46:26 +02:00
|
|
|
|
|
|
|
final textIcon = Text(
|
2023-11-12 03:03:32 +02:00
|
|
|
user.name[0].toUpperCase(),
|
2023-11-06 17:46:26 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
2023-11-14 05:10:35 +02:00
|
|
|
fontSize: 12,
|
|
|
|
color: isDarkTheme && user.avatarColor == AvatarColorEnum.primary
|
|
|
|
? Colors.black
|
|
|
|
: Colors.white,
|
2023-11-06 17:46:26 +02:00
|
|
|
),
|
|
|
|
);
|
2023-08-18 06:26:12 +02:00
|
|
|
return CircleAvatar(
|
2023-12-10 17:56:39 +02:00
|
|
|
backgroundColor: user.avatarColor.toColor(),
|
2023-08-18 06:26:12 +02:00
|
|
|
radius: radius,
|
2023-11-14 05:10:35 +02:00
|
|
|
child: user.profileImagePath.isEmpty
|
2023-11-06 17:46:26 +02:00
|
|
|
? textIcon
|
2023-08-18 06:26:12 +02:00
|
|
|
: ClipRRect(
|
2023-12-10 04:32:39 +02:00
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(50)),
|
2023-10-30 19:17:34 +02:00
|
|
|
child: CachedNetworkImage(
|
2023-08-18 06:26:12 +02:00
|
|
|
fit: BoxFit.cover,
|
2023-10-30 19:17:34 +02:00
|
|
|
cacheKey: user.profileImagePath,
|
2023-08-18 06:26:12 +02:00
|
|
|
width: size,
|
|
|
|
height: size,
|
2023-10-30 19:17:34 +02:00
|
|
|
placeholder: (_, __) => Image.memory(kTransparentImage),
|
|
|
|
imageUrl: profileImageUrl,
|
|
|
|
httpHeaders: {
|
2024-02-04 22:35:13 +02:00
|
|
|
"x-immich-user-token": Store.get(StoreKey.accessToken),
|
2023-10-30 19:17:34 +02:00
|
|
|
},
|
|
|
|
fadeInDuration: const Duration(milliseconds: 300),
|
2023-11-06 17:46:26 +02:00
|
|
|
errorWidget: (context, error, stackTrace) => textIcon,
|
2023-08-18 06:26:12 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|