diff --git a/packages/flutter_chat/example/lib/main.dart b/packages/flutter_chat/example/lib/main.dart index 8c8d809..f8e92cc 100644 --- a/packages/flutter_chat/example/lib/main.dart +++ b/packages/flutter_chat/example/lib/main.dart @@ -24,7 +24,12 @@ class Home extends StatelessWidget { @override Widget build(BuildContext context) { return Center( - child: chatNavigatorUserStory(context), - ); + child: chatNavigatorUserStory(context, + configuration: ChatUserStoryConfiguration( + chatService: LocalChatService(), + chatOptionsBuilder: (ctx) => ChatOptions( + noChatsPlaceholderBuilder: (translations) => + Text(translations.noUsersFound), + )))); } } diff --git a/packages/flutter_chat_view/lib/src/config/chat_options.dart b/packages/flutter_chat_view/lib/src/config/chat_options.dart index 78a757f..00e8b05 100644 --- a/packages/flutter_chat_view/lib/src/config/chat_options.dart +++ b/packages/flutter_chat_view/lib/src/config/chat_options.dart @@ -18,6 +18,7 @@ class ChatOptions { this.userAvatarBuilder = _createUserAvatar, this.groupAvatarBuilder = _createGroupAvatar, this.noChatsPlaceholderBuilder = _createNoChatsPlaceholder, + this.noUsersPlaceholderBuilder = _createNoUsersPlaceholder, }); /// Builder function for the new chat button. @@ -43,6 +44,9 @@ class ChatOptions { /// Builder function for the placeholder shown when no chats are available. final NoChatsPlaceholderBuilder noChatsPlaceholderBuilder; + + /// Builder function for the placeholder shown when no users are available. + final NoUsersPlaceholderBuilder noUsersPlaceholderBuilder; } Widget _createNewChatButton( @@ -179,6 +183,20 @@ Widget _createGroupAvatar( Widget _createNoChatsPlaceholder( ChatTranslations translations, +) => + Center( + child: Text( + translations.noChatsFound, + textAlign: TextAlign.center, + style: const TextStyle( + color: Colors.white, + fontSize: 18, + ), + ), + ); + +Widget _createNoUsersPlaceholder( + ChatTranslations translations, ) => Center( child: Text( @@ -231,3 +249,7 @@ typedef GroupAvatarBuilder = Widget Function( typedef NoChatsPlaceholderBuilder = Widget Function( ChatTranslations translations, ); + +typedef NoUsersPlaceholderBuilder = Widget Function( + ChatTranslations translations, +); diff --git a/packages/flutter_chat_view/lib/src/config/chat_translations.dart b/packages/flutter_chat_view/lib/src/config/chat_translations.dart index d877205..85a2a8f 100644 --- a/packages/flutter_chat_view/lib/src/config/chat_translations.dart +++ b/packages/flutter_chat_view/lib/src/config/chat_translations.dart @@ -20,7 +20,8 @@ class ChatTranslations { 'Are you sure you want to delete this chat?', this.deleteChatModalCancel = 'Cancel', this.deleteChatModalConfirm = 'Delete', - this.noUsersFound = 'No users found', + this.noUsersFound = 'No users were found to start a chat with.', + this.noChatsFound = 'Click on \'Start a chat\' to create a new chat.', this.anonymousUser = 'Anonymous user', this.chatCantBeDeleted = 'This chat can\'t be deleted', this.chatProfileUsers = 'Users:', @@ -42,6 +43,7 @@ class ChatTranslations { final String deleteChatModalCancel; final String deleteChatModalConfirm; final String noUsersFound; + final String noChatsFound; final String chatCantBeDeleted; final String chatProfileUsers; diff --git a/packages/flutter_chat_view/lib/src/screens/chat_detail_screen.dart b/packages/flutter_chat_view/lib/src/screens/chat_detail_screen.dart index 15ee954..ee0937b 100644 --- a/packages/flutter_chat_view/lib/src/screens/chat_detail_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/chat_detail_screen.dart @@ -196,28 +196,38 @@ class _ChatDetailScreenState extends State { 36.0, ), ] else if (chatModel is PersonalChatModel) ...[ - Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - widget.options.userAvatarBuilder( - chatModel.user, - 36.0, - ), - const SizedBox(width: 8), - Text( - chatModel.user.firstName ?? - widget.translations.anonymousUser, - style: theme.appBarTheme.titleTextStyle ?? - const TextStyle( - fontSize: 18, - fontWeight: FontWeight.w800, - color: Colors.white, - ), - ), - ], + widget.options.userAvatarBuilder( + chatModel.user, + 36.0, ), ] else ...[], + Padding( + padding: const EdgeInsets.only(left: 15.5), + child: widget.chatTitleBuilder != null + ? widget.chatTitleBuilder!.call( + (chatModel is GroupChatModel) + ? chatModel.title + : (chatModel is PersonalChatModel) + ? chatModel.user.fullName ?? + widget.translations.anonymousUser + : '', + ) + : Text( + (chatModel is GroupChatModel) + ? chatModel.title + : (chatModel is PersonalChatModel) + ? chatModel.user.fullName ?? + widget.translations.anonymousUser + : '', + style: theme.appBarTheme.titleTextStyle ?? + const TextStyle( + fontWeight: FontWeight.w800, + fontSize: 18.0, + color: Colors.white, + ), + ), + ), ], ), ), diff --git a/packages/flutter_chat_view/lib/src/screens/chat_screen.dart b/packages/flutter_chat_view/lib/src/screens/chat_screen.dart index 3ad2069..444f1ac 100644 --- a/packages/flutter_chat_view/lib/src/screens/chat_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/chat_screen.dart @@ -287,57 +287,59 @@ class ChatListItem extends StatelessWidget { @override Widget build(BuildContext context) => Column( - children: [ - GestureDetector( - onTap: () => widget.onPressChat(chat), - child: Container( - color: Colors.transparent, - child: widget.options.chatRowContainerBuilder( - (chat is PersonalChatModel) - ? ChatRow( - unreadMessages: chat.unreadMessages ?? 0, - avatar: widget.options.userAvatarBuilder( - (chat as PersonalChatModel).user, - 40.0, + children: [ + GestureDetector( + onTap: () => widget.onPressChat(chat), + child: Container( + color: Colors.transparent, + child: widget.options.chatRowContainerBuilder( + (chat is PersonalChatModel) + ? ChatRow( + unreadMessages: chat.unreadMessages ?? 0, + avatar: widget.options.userAvatarBuilder( + (chat as PersonalChatModel).user, + 40.0, + ), + title: (chat as PersonalChatModel).user.fullName ?? + translations.anonymousUser, + subTitle: chat.lastMessage != null + ? chat.lastMessage is ChatTextMessageModel + ? (chat.lastMessage! as ChatTextMessageModel) + .text + : '📷 ' + '${translations.image}' + : '', + lastUsed: chat.lastUsed != null + ? _dateFormatter.format( + date: chat.lastUsed!, + ) + : null, + ) + : ChatRow( + title: (chat as GroupChatModel).title, + unreadMessages: chat.unreadMessages ?? 0, + subTitle: chat.lastMessage != null + ? chat.lastMessage is ChatTextMessageModel + ? (chat.lastMessage! as ChatTextMessageModel) + .text + : '📷 ' + '${translations.image}' + : '', + avatar: widget.options.groupAvatarBuilder( + (chat as GroupChatModel).title, + (chat as GroupChatModel).imageUrl, + 40.0, + ), + lastUsed: chat.lastUsed != null + ? _dateFormatter.format( + date: chat.lastUsed!, + ) + : null, + ), ), - title: (chat as PersonalChatModel).user.fullName ?? - translations.anonymousUser, - subTitle: chat.lastMessage != null - ? chat.lastMessage is ChatTextMessageModel - ? (chat.lastMessage! as ChatTextMessageModel).text - : '📷 ' - '${translations.image}' - : '', - lastUsed: chat.lastUsed != null - ? _dateFormatter.format( - date: chat.lastUsed!, - ) - : null, - ) - : ChatRow( - title: (chat as GroupChatModel).title, - unreadMessages: chat.unreadMessages ?? 0, - subTitle: chat.lastMessage != null - ? chat.lastMessage is ChatTextMessageModel - ? (chat.lastMessage! as ChatTextMessageModel).text - : '📷 ' - '${translations.image}' - : '', - avatar: widget.options.groupAvatarBuilder( - (chat as GroupChatModel).title, - (chat as GroupChatModel).imageUrl, - 40.0, - ), - lastUsed: chat.lastUsed != null - ? _dateFormatter.format( - date: chat.lastUsed!, - ) - : null, ), ), - ), - ), - const Divider(), - ], - ); + const Divider(), + ], + ); } diff --git a/packages/flutter_chat_view/lib/src/screens/new_chat_screen.dart b/packages/flutter_chat_view/lib/src/screens/new_chat_screen.dart index 0ec6196..d5b5f60 100644 --- a/packages/flutter_chat_view/lib/src/screens/new_chat_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/new_chat_screen.dart @@ -106,8 +106,10 @@ class _NewChatScreenState extends State { } else if (snapshot.hasData) { return _buildUserList(snapshot.data!); } else { - return widget.options - .noChatsPlaceholderBuilder(widget.translations); + return Padding( + padding: const EdgeInsets.only(top: 20.0), + child: Text(widget.translations.noUsersFound), + ); } }, ),