2024-05-03 04:15:54 +00:00
|
|
|
import 'package:cached_network_image/cached_network_image.dart';
|
2024-04-26 12:49:21 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-05-03 04:15:54 +00:00
|
|
|
import 'package:solian/utils/platform.dart';
|
2024-04-26 12:49:21 +00:00
|
|
|
import 'package:solian/utils/service_url.dart';
|
|
|
|
|
|
|
|
class AccountAvatar extends StatelessWidget {
|
|
|
|
final String source;
|
|
|
|
final double? radius;
|
|
|
|
final bool? direct;
|
|
|
|
final Color? backgroundColor;
|
|
|
|
|
|
|
|
const AccountAvatar({
|
|
|
|
super.key,
|
|
|
|
required this.source,
|
|
|
|
this.radius,
|
|
|
|
this.direct,
|
|
|
|
this.backgroundColor,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final detectRegex = RegExp(r'https://.*/api/avatar/');
|
|
|
|
|
|
|
|
if (source.isEmpty || source.replaceAll(detectRegex, '').isEmpty) {
|
|
|
|
return CircleAvatar(
|
|
|
|
radius: radius,
|
|
|
|
backgroundColor: backgroundColor,
|
|
|
|
child: const Icon(Icons.account_circle),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (direct == true) {
|
2024-05-03 04:15:54 +00:00
|
|
|
final image = PlatformInfo.canCacheImage ? CachedNetworkImageProvider(source) : NetworkImage(source);
|
2024-04-26 12:49:21 +00:00
|
|
|
return CircleAvatar(
|
|
|
|
radius: radius,
|
|
|
|
backgroundColor: backgroundColor,
|
2024-05-03 04:15:54 +00:00
|
|
|
backgroundImage: image as ImageProvider,
|
2024-04-26 12:49:21 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
final url = getRequestUri('passport', '/api/avatar/$source').toString();
|
2024-05-03 04:15:54 +00:00
|
|
|
final image = PlatformInfo.canCacheImage ? CachedNetworkImageProvider(url) : NetworkImage(url);
|
2024-04-26 12:49:21 +00:00
|
|
|
return CircleAvatar(
|
|
|
|
radius: radius,
|
|
|
|
backgroundColor: backgroundColor,
|
2024-05-03 04:15:54 +00:00
|
|
|
backgroundImage: image as ImageProvider,
|
2024-04-26 12:49:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|