2024-11-09 03:16:14 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-11-10 10:37:34 +00:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
2024-11-09 03:16:14 +00:00
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:surface/providers/sn_network.dart';
|
|
|
|
import 'package:surface/widgets/universal_image.dart';
|
|
|
|
|
|
|
|
class AccountImage extends StatelessWidget {
|
2024-11-09 17:04:39 +00:00
|
|
|
final String? content;
|
2024-11-09 03:16:14 +00:00
|
|
|
final Color? backgroundColor;
|
|
|
|
final Color? foregroundColor;
|
|
|
|
final double? radius;
|
|
|
|
final Widget? fallbackWidget;
|
|
|
|
|
|
|
|
const AccountImage({
|
|
|
|
super.key,
|
|
|
|
required this.content,
|
|
|
|
this.backgroundColor,
|
|
|
|
this.foregroundColor,
|
|
|
|
this.radius,
|
|
|
|
this.fallbackWidget,
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
2024-11-09 17:04:39 +00:00
|
|
|
final url = sn.getAttachmentUrl(content ?? '');
|
2024-11-09 03:16:14 +00:00
|
|
|
|
|
|
|
final devicePixelRatio = MediaQuery.of(context).devicePixelRatio;
|
|
|
|
return CircleAvatar(
|
|
|
|
key: Key('attachment-${content.hashCode}'),
|
|
|
|
radius: radius,
|
|
|
|
backgroundColor: backgroundColor,
|
2024-11-09 17:04:39 +00:00
|
|
|
backgroundImage: (content?.isNotEmpty ?? false)
|
2024-11-09 03:16:14 +00:00
|
|
|
? ResizeImage(
|
|
|
|
UniversalImage.provider(url),
|
|
|
|
width: ((radius ?? 20) * devicePixelRatio * 2).round(),
|
|
|
|
height: ((radius ?? 20) * devicePixelRatio * 2).round(),
|
2024-11-11 13:30:05 +00:00
|
|
|
policy: ResizeImagePolicy.fit,
|
2024-11-09 03:16:14 +00:00
|
|
|
)
|
|
|
|
: null,
|
2024-11-09 17:04:39 +00:00
|
|
|
child: (content?.isEmpty ?? true)
|
2024-11-09 03:16:14 +00:00
|
|
|
? (fallbackWidget ??
|
|
|
|
Icon(
|
2024-11-10 10:37:34 +00:00
|
|
|
Symbols.account_circle,
|
2024-11-09 03:16:14 +00:00
|
|
|
size: radius != null ? radius! * 1.2 : 24,
|
|
|
|
color: foregroundColor,
|
|
|
|
))
|
|
|
|
: null,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|