fluffychat/lib/widgets/unread_rooms_badge.dart

53 lines
1.2 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
2023-01-26 08:47:30 +00:00
import 'package:badges/badges.dart' as b;
import 'package:matrix/matrix.dart';
import 'matrix.dart';
class UnreadRoomsBadge extends StatelessWidget {
final bool Function(Room) filter;
2023-01-26 08:47:30 +00:00
final b.BadgePosition? badgePosition;
final Widget? child;
const UnreadRoomsBadge({
super.key,
required this.filter,
this.badgePosition,
this.child,
});
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
2024-07-15 19:14:49 +00:00
final unreadCount = Matrix.of(context)
.client
.rooms
.where(filter)
.where((r) => (r.isUnread || r.membership == Membership.invite))
.length;
return b.Badge(
badgeStyle: b.BadgeStyle(
badgeColor: theme.colorScheme.primary,
2024-07-15 19:14:49 +00:00
elevation: 4,
borderSide: BorderSide(
color: theme.colorScheme.surface,
2024-07-15 19:14:49 +00:00
width: 2,
),
),
badgeContent: Text(
unreadCount.toString(),
style: TextStyle(
color: theme.colorScheme.onPrimary,
2024-07-15 19:14:49 +00:00
fontSize: 12,
),
),
showBadge: unreadCount != 0,
badgeAnimation: const b.BadgeAnimation.scale(),
position: badgePosition ?? b.BadgePosition.bottomEnd(),
child: child,
);
}
}