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 17:19:53 +01:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/user.entity.dart';
|
2024-06-26 21:31:55 +02:00
|
|
|
import 'package:immich_mobile/services/api.service.dart';
|
2023-05-25 05:52:43 +02:00
|
|
|
|
|
|
|
Widget userAvatar(BuildContext context, User u, {double? radius}) {
|
|
|
|
final url =
|
2024-05-22 20:31:12 +02:00
|
|
|
"${Store.get(StoreKey.serverEndpoint)}/users/${u.id}/profile-image";
|
2023-11-12 02:03:32 +01:00
|
|
|
final nameFirstLetter = u.name.isNotEmpty ? u.name[0] : "";
|
2023-05-25 05:52:43 +02:00
|
|
|
return CircleAvatar(
|
|
|
|
radius: radius,
|
2023-11-09 17:19:53 +01:00
|
|
|
backgroundColor: context.primaryColor.withAlpha(50),
|
2023-05-25 05:52:43 +02:00
|
|
|
foregroundImage: CachedNetworkImageProvider(
|
|
|
|
url,
|
2024-06-26 21:31:55 +02:00
|
|
|
headers: ApiService.getRequestHeaders(),
|
2023-05-25 05:52:43 +02:00
|
|
|
cacheKey: "user-${u.id}-profile",
|
|
|
|
),
|
|
|
|
// silence errors if user has no profile image, use initials as fallback
|
|
|
|
onForegroundImageError: (exception, stackTrace) {},
|
2023-11-12 02:03:32 +01:00
|
|
|
child: Text(nameFirstLetter.toUpperCase()),
|
2023-05-25 05:52:43 +02:00
|
|
|
);
|
|
|
|
}
|