2023-05-25 05:52:43 +02:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
import 'package:immich_mobile/shared/models/store.dart';
|
|
|
|
import 'package:immich_mobile/shared/models/user.dart';
|
|
|
|
|
|
|
|
Widget userAvatar(BuildContext context, User u, {double? radius}) {
|
|
|
|
final url =
|
|
|
|
"${Store.get(StoreKey.serverEndpoint)}/user/profile-image/${u.id}";
|
2023-11-12 03:03:32 +02:00
|
|
|
final nameFirstLetter = u.name.isNotEmpty ? u.name[0] : "";
|
2023-05-25 05:52:43 +02:00
|
|
|
return CircleAvatar(
|
|
|
|
radius: radius,
|
2023-11-09 18:19:53 +02:00
|
|
|
backgroundColor: context.primaryColor.withAlpha(50),
|
2023-05-25 05:52:43 +02:00
|
|
|
foregroundImage: CachedNetworkImageProvider(
|
|
|
|
url,
|
|
|
|
headers: {"Authorization": "Bearer ${Store.get(StoreKey.accessToken)}"},
|
|
|
|
cacheKey: "user-${u.id}-profile",
|
|
|
|
),
|
|
|
|
// silence errors if user has no profile image, use initials as fallback
|
|
|
|
onForegroundImageError: (exception, stackTrace) {},
|
2023-11-12 03:03:32 +02:00
|
|
|
child: Text(nameFirstLetter.toUpperCase()),
|
2023-05-25 05:52:43 +02:00
|
|
|
);
|
|
|
|
}
|