mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 10:53:51 +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 {
|
class ChatTranslations {
|
||||||
const ChatTranslations({
|
const ChatTranslations({
|
||||||
this.chatsTitle = 'Chats',
|
this.chatsTitle = 'Chats',
|
||||||
|
this.chatsUnread = 'unread',
|
||||||
this.newChatButton = 'Start chat',
|
this.newChatButton = 'Start chat',
|
||||||
this.newChatTitle = 'Start chat',
|
this.newChatTitle = 'Start chat',
|
||||||
this.image = 'Image',
|
this.image = 'Image',
|
||||||
|
@ -22,6 +23,7 @@ class ChatTranslations {
|
||||||
});
|
});
|
||||||
|
|
||||||
final String chatsTitle;
|
final String chatsTitle;
|
||||||
|
final String chatsUnread;
|
||||||
final String newChatButton;
|
final String newChatButton;
|
||||||
final String newChatTitle;
|
final String newChatTitle;
|
||||||
final String deleteChatButton;
|
final String deleteChatButton;
|
||||||
|
|
|
@ -13,6 +13,7 @@ class ChatScreen extends StatefulWidget {
|
||||||
required this.onPressStartChat,
|
required this.onPressStartChat,
|
||||||
required this.onPressChat,
|
required this.onPressChat,
|
||||||
required this.onDeleteChat,
|
required this.onDeleteChat,
|
||||||
|
this.unreadChats,
|
||||||
this.translations = const ChatTranslations(),
|
this.translations = const ChatTranslations(),
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
@ -20,6 +21,7 @@ class ChatScreen extends StatefulWidget {
|
||||||
final ChatOptions options;
|
final ChatOptions options;
|
||||||
final ChatTranslations translations;
|
final ChatTranslations translations;
|
||||||
final Stream<List<ChatModel>> chats;
|
final Stream<List<ChatModel>> chats;
|
||||||
|
final Stream<int>? unreadChats;
|
||||||
final VoidCallback? onPressStartChat;
|
final VoidCallback? onPressStartChat;
|
||||||
final void Function(ChatModel chat) onDeleteChat;
|
final void Function(ChatModel chat) onDeleteChat;
|
||||||
final void Function(ChatModel chat) onPressChat;
|
final void Function(ChatModel chat) onPressChat;
|
||||||
|
@ -37,6 +39,27 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||||
return widget.options.scaffoldBuilder(
|
return widget.options.scaffoldBuilder(
|
||||||
AppBar(
|
AppBar(
|
||||||
title: Text(translations.chatsTitle),
|
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(
|
Column(
|
||||||
children: [
|
children: [
|
||||||
|
|
Loading…
Reference in a new issue