chore: Add unread badge to navigation rail and adjust design
parent
cdd5a9e821
commit
17dc6ee3a8
@ -1,58 +0,0 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import '../config/app_config.dart';
|
||||
import 'matrix.dart';
|
||||
|
||||
class UnreadBadgeBackButton extends StatelessWidget {
|
||||
final String roomId;
|
||||
|
||||
const UnreadBadgeBackButton({
|
||||
Key? key,
|
||||
required this.roomId,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
children: [
|
||||
StreamBuilder(
|
||||
stream: Matrix.of(context).client.onSync.stream,
|
||||
builder: (context, _) {
|
||||
final unreadCount = Matrix.of(context)
|
||||
.client
|
||||
.rooms
|
||||
.where((r) =>
|
||||
r.id != roomId &&
|
||||
(r.isUnread || r.membership == Membership.invite))
|
||||
.length;
|
||||
return unreadCount > 0
|
||||
? Align(
|
||||
alignment: Alignment.bottomRight,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(4),
|
||||
margin: const EdgeInsets.only(bottom: 4, right: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: Theme.of(context).colorScheme.primaryContainer,
|
||||
borderRadius:
|
||||
BorderRadius.circular(AppConfig.borderRadius),
|
||||
),
|
||||
child: Text(
|
||||
'$unreadCount',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.onPrimaryContainer,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Container();
|
||||
}),
|
||||
const Center(child: BackButton()),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:badges/badges.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
import 'matrix.dart';
|
||||
|
||||
class UnreadRoomsBadge extends StatelessWidget {
|
||||
final bool Function(Room) filter;
|
||||
final BadgePosition? badgePosition;
|
||||
final Widget? child;
|
||||
|
||||
const UnreadRoomsBadge({
|
||||
Key? key,
|
||||
required this.filter,
|
||||
this.badgePosition,
|
||||
this.child,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return StreamBuilder(
|
||||
stream: Matrix.of(context)
|
||||
.client
|
||||
.onSync
|
||||
.stream
|
||||
.where((syncUpdate) => syncUpdate.hasRoomUpdate),
|
||||
builder: (context, _) {
|
||||
final unreadCount = Matrix.of(context)
|
||||
.client
|
||||
.rooms
|
||||
.where(filter)
|
||||
.where((r) => (r.isUnread || r.membership == Membership.invite))
|
||||
.length;
|
||||
return Badge(
|
||||
alignment: Alignment.bottomRight,
|
||||
badgeContent: Text(
|
||||
unreadCount.toString(),
|
||||
style: TextStyle(
|
||||
color: Theme.of(context).colorScheme.onPrimary,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
showBadge: unreadCount != 0,
|
||||
animationType: BadgeAnimationType.scale,
|
||||
badgeColor: Theme.of(context).colorScheme.primary,
|
||||
position: badgePosition,
|
||||
elevation: 4,
|
||||
borderSide: BorderSide(
|
||||
color: Theme.of(context).colorScheme.background,
|
||||
width: 2,
|
||||
strokeAlign: StrokeAlign.outside,
|
||||
),
|
||||
child: child,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue