mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 02:43:50 +02:00
feat: show unread chats in appbar
This commit is contained in:
parent
5e41f3885f
commit
5d4aadc62e
2 changed files with 25 additions and 0 deletions
|
@ -5,6 +5,7 @@
|
|||
class ChatTranslations {
|
||||
const ChatTranslations({
|
||||
this.chatsTitle = 'Chats',
|
||||
this.chatsUnread = 'unread',
|
||||
this.newChatButton = 'Start chat',
|
||||
this.newChatTitle = 'Start chat',
|
||||
this.image = 'Image',
|
||||
|
@ -22,6 +23,7 @@ class ChatTranslations {
|
|||
});
|
||||
|
||||
final String chatsTitle;
|
||||
final String chatsUnread;
|
||||
final String newChatButton;
|
||||
final String newChatTitle;
|
||||
final String deleteChatButton;
|
||||
|
|
|
@ -13,6 +13,7 @@ class ChatScreen extends StatefulWidget {
|
|||
required this.onPressStartChat,
|
||||
required this.onPressChat,
|
||||
required this.onDeleteChat,
|
||||
this.unreadChats,
|
||||
this.translations = const ChatTranslations(),
|
||||
super.key,
|
||||
});
|
||||
|
@ -20,6 +21,7 @@ class ChatScreen extends StatefulWidget {
|
|||
final ChatOptions options;
|
||||
final ChatTranslations translations;
|
||||
final Stream<List<ChatModel>> chats;
|
||||
final Stream<int>? unreadChats;
|
||||
final VoidCallback? onPressStartChat;
|
||||
final void Function(ChatModel chat) onDeleteChat;
|
||||
final void Function(ChatModel chat) onPressChat;
|
||||
|
@ -37,6 +39,27 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||
return widget.options.scaffoldBuilder(
|
||||
AppBar(
|
||||
title: Text(translations.chatsTitle),
|
||||
centerTitle: true,
|
||||
actions: widget.unreadChats != null
|
||||
? [
|
||||
StreamBuilder<int>(
|
||||
stream: widget.unreadChats,
|
||||
builder: (BuildContext context, snapshot) => Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(right: 22.0),
|
||||
child: Text(
|
||||
'${snapshot.data ?? 0} ${translations.chatsUnread}',
|
||||
style: const TextStyle(
|
||||
color: Color(0xFFBBBBBB),
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
]
|
||||
: [],
|
||||
),
|
||||
Column(
|
||||
children: [
|
||||
|
|
Loading…
Reference in a new issue