2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:solian/services.dart';
|
2024-10-11 16:41:03 +00:00
|
|
|
import 'package:solian/widgets/account/account_profile_popup.dart';
|
2024-09-10 13:53:05 +00:00
|
|
|
import 'package:solian/widgets/auto_cache_image.dart';
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-10-11 16:41:03 +00:00
|
|
|
class AttachedCircleAvatar extends StatelessWidget {
|
2024-05-20 15:11:26 +00:00
|
|
|
final dynamic content;
|
2024-05-28 16:14:41 +00:00
|
|
|
final Color? bgColor;
|
|
|
|
final Color? feColor;
|
2024-05-18 10:17:16 +00:00
|
|
|
final double? radius;
|
2024-10-05 06:25:57 +00:00
|
|
|
final Widget? fallbackWidget;
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-10-11 16:41:03 +00:00
|
|
|
const AttachedCircleAvatar({
|
2024-05-28 16:14:41 +00:00
|
|
|
super.key,
|
|
|
|
required this.content,
|
|
|
|
this.bgColor,
|
|
|
|
this.feColor,
|
|
|
|
this.radius,
|
2024-10-05 06:25:57 +00:00
|
|
|
this.fallbackWidget,
|
2024-05-28 16:14:41 +00:00
|
|
|
});
|
2024-05-18 10:17:16 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-20 15:11:26 +00:00
|
|
|
bool direct = false;
|
|
|
|
bool isEmpty = content == null;
|
|
|
|
if (content is String) {
|
|
|
|
direct = content.startsWith('http');
|
2024-05-25 16:11:00 +00:00
|
|
|
if (!isEmpty) isEmpty = content.isEmpty;
|
2024-05-20 15:11:26 +00:00
|
|
|
}
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-06-01 13:39:28 +00:00
|
|
|
final url = direct
|
|
|
|
? content
|
2024-07-16 11:46:53 +00:00
|
|
|
: ServiceFinder.buildUrl('files', '/attachments/$content');
|
2024-06-01 13:39:28 +00:00
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
return CircleAvatar(
|
2024-05-19 10:01:00 +00:00
|
|
|
key: Key('a$content'),
|
2024-05-18 10:17:16 +00:00
|
|
|
radius: radius,
|
2024-05-28 16:14:41 +00:00
|
|
|
backgroundColor: bgColor,
|
2024-09-10 13:53:05 +00:00
|
|
|
backgroundImage: !isEmpty ? AutoCacheImage.provider(url) : null,
|
2024-05-22 12:56:10 +00:00
|
|
|
child: isEmpty
|
2024-10-05 06:25:57 +00:00
|
|
|
? (fallbackWidget ??
|
|
|
|
Icon(
|
2024-10-11 16:41:03 +00:00
|
|
|
Icons.image,
|
2024-10-05 06:25:57 +00:00
|
|
|
size: radius != null ? radius! * 1.2 : 24,
|
|
|
|
color: feColor,
|
|
|
|
))
|
2024-05-22 12:56:10 +00:00
|
|
|
: null,
|
2024-05-18 10:17:16 +00:00
|
|
|
);
|
|
|
|
}
|
2024-05-20 15:11:26 +00:00
|
|
|
}
|
2024-06-03 15:36:46 +00:00
|
|
|
|
2024-10-11 16:41:03 +00:00
|
|
|
class AccountAvatar extends StatelessWidget {
|
|
|
|
final dynamic content;
|
|
|
|
final String username;
|
|
|
|
final Color? bgColor;
|
|
|
|
final Color? feColor;
|
|
|
|
final double? radius;
|
|
|
|
final Widget? fallbackWidget;
|
|
|
|
|
|
|
|
const AccountAvatar({
|
|
|
|
super.key,
|
|
|
|
required this.content,
|
|
|
|
required this.username,
|
|
|
|
this.bgColor,
|
|
|
|
this.feColor,
|
|
|
|
this.radius,
|
|
|
|
this.fallbackWidget,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
|
|
|
child: AttachedCircleAvatar(
|
|
|
|
content: content,
|
|
|
|
bgColor: bgColor,
|
|
|
|
feColor: feColor,
|
|
|
|
radius: radius,
|
|
|
|
fallbackWidget: (fallbackWidget ??
|
|
|
|
Icon(
|
|
|
|
Icons.account_circle,
|
|
|
|
size: radius != null ? radius! * 1.2 : 24,
|
|
|
|
color: feColor,
|
|
|
|
)),
|
|
|
|
),
|
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
isScrollControlled: true,
|
|
|
|
backgroundColor: Theme.of(context).colorScheme.surface,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AccountProfilePopup(
|
|
|
|
name: username,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-03 15:36:46 +00:00
|
|
|
class AccountProfileImage extends StatelessWidget {
|
|
|
|
final dynamic content;
|
|
|
|
final BoxFit fit;
|
|
|
|
|
|
|
|
const AccountProfileImage({
|
|
|
|
super.key,
|
|
|
|
required this.content,
|
|
|
|
this.fit = BoxFit.cover,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
bool direct = false;
|
|
|
|
bool isEmpty = content == null;
|
|
|
|
if (content is String) {
|
|
|
|
direct = content.startsWith('http');
|
|
|
|
if (!isEmpty) isEmpty = content.isEmpty;
|
2024-07-16 11:46:53 +00:00
|
|
|
if (!isEmpty) isEmpty = content.endsWith('/attachments/0');
|
2024-06-03 15:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
final url = direct
|
|
|
|
? content
|
2024-07-16 11:46:53 +00:00
|
|
|
: ServiceFinder.buildUrl('files', '/attachments/$content');
|
2024-06-03 15:36:46 +00:00
|
|
|
|
2024-09-10 13:53:05 +00:00
|
|
|
return AutoCacheImage(url, fit: fit, noErrorWidget: true);
|
2024-06-03 15:36:46 +00:00
|
|
|
}
|
|
|
|
}
|