2
0
mirror of https://gitlab.com/famedly/fluffychat.git synced 2024-12-19 11:22:35 +01:00
fluffychat/lib/widgets/unread_badge_back_button.dart

57 lines
1.7 KiB
Dart
Raw Normal View History

2021-03-28 09:20:34 +02:00
import 'package:flutter/material.dart';
2021-10-26 18:50:34 +02:00
import 'package:matrix/matrix.dart';
2021-05-22 08:53:52 +02:00
import '../config/app_config.dart';
2021-03-28 09:20:34 +02:00
import 'matrix.dart';
class UnreadBadgeBackButton extends StatelessWidget {
final String roomId;
const UnreadBadgeBackButton({
2022-01-28 18:21:20 +01:00
Key? key,
required this.roomId,
2021-03-28 09:20:34 +02:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Stack(
children: [
2021-10-14 18:09:30 +02:00
const Center(child: BackButton()),
2021-03-28 09:20:34 +02:00
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(
2021-10-14 18:09:30 +02:00
padding: const EdgeInsets.all(4),
margin: const EdgeInsets.only(bottom: 4, right: 8),
2021-03-28 09:20:34 +02:00
decoration: BoxDecoration(
2021-03-28 09:21:39 +02:00
color: Theme.of(context).primaryColor,
2021-03-28 09:20:34 +02:00
borderRadius:
BorderRadius.circular(AppConfig.borderRadius),
),
child: Text(
'$unreadCount',
2021-10-14 18:09:30 +02:00
style: const TextStyle(
2021-03-28 09:21:39 +02:00
fontSize: 12,
color: Colors.white,
),
2021-03-28 09:20:34 +02:00
),
),
)
: Container();
}),
],
);
}
}