2023-06-21 17:44:28 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
import 'package:badges/badges.dart' as badges;
|
2024-04-09 17:23:28 +08:00
|
|
|
|
|
|
|
import '/common/constants.dart';
|
2023-06-21 17:44:28 +08:00
|
|
|
|
2023-08-15 10:53:30 +08:00
|
|
|
class BadgeAvatar extends StatelessWidget {
|
2023-06-21 17:44:28 +08:00
|
|
|
const BadgeAvatar({
|
|
|
|
super.key,
|
2023-08-15 10:53:30 +08:00
|
|
|
required this.unreadCount,
|
2023-06-21 17:44:28 +08:00
|
|
|
required this.radius,
|
|
|
|
required this.backgroundImage,
|
|
|
|
});
|
|
|
|
|
2023-08-15 10:53:30 +08:00
|
|
|
final int unreadCount;
|
2023-06-21 17:44:28 +08:00
|
|
|
final double radius;
|
|
|
|
final ImageProvider<Object> backgroundImage;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return badges.Badge(
|
2023-08-15 10:53:30 +08:00
|
|
|
showBadge: unreadCount > 0,
|
2023-06-21 17:44:28 +08:00
|
|
|
badgeStyle: const badges.BadgeStyle(
|
|
|
|
badgeColor: kErrorColor,
|
|
|
|
elevation: 12,
|
|
|
|
),
|
|
|
|
badgeContent: Text(
|
2023-08-15 10:53:30 +08:00
|
|
|
unreadCount > 99 ? '$unreadCount+' : '$unreadCount',
|
2023-06-21 17:44:28 +08:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 11,
|
|
|
|
color: Theme.of(context).colorScheme.inversePrimary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
badgeAnimation: const badges.BadgeAnimation.scale(),
|
2023-08-10 19:08:46 +08:00
|
|
|
position: badges.BadgePosition.topEnd(top: -12, end: -16),
|
2023-06-21 17:44:28 +08:00
|
|
|
child: CircleAvatar(
|
2023-08-15 10:53:30 +08:00
|
|
|
backgroundImage: backgroundImage,
|
2023-06-21 17:44:28 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|