2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:solian/services.dart';
|
|
|
|
|
|
|
|
class AccountAvatar extends StatelessWidget {
|
2024-05-20 15:11:26 +00:00
|
|
|
final dynamic content;
|
2024-05-18 10:17:16 +00:00
|
|
|
final Color? color;
|
|
|
|
final double? radius;
|
|
|
|
|
2024-05-22 12:56:10 +00:00
|
|
|
const AccountAvatar(
|
|
|
|
{super.key, required this.content, this.color, this.radius});
|
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;
|
|
|
|
if (!isEmpty) isEmpty = content.endsWith('/api/attachments/0');
|
2024-05-20 15:11:26 +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,
|
|
|
|
backgroundColor: color,
|
2024-05-22 12:56:10 +00:00
|
|
|
backgroundImage: !isEmpty
|
|
|
|
? NetworkImage(
|
|
|
|
direct
|
|
|
|
? content
|
|
|
|
: '${ServiceFinder.services['paperclip']}/api/attachments/$content',
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
child: isEmpty
|
|
|
|
? Icon(
|
|
|
|
Icons.account_circle,
|
|
|
|
size: radius != null ? radius! * 1.2 : 24,
|
|
|
|
)
|
|
|
|
: null,
|
2024-05-18 10:17:16 +00:00
|
|
|
);
|
|
|
|
}
|
2024-05-20 15:11:26 +00:00
|
|
|
}
|