mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 10:53:51 +02:00
refactor: add translation option and builder for no chats case
This commit is contained in:
parent
89edfdd18c
commit
f2e6875630
6 changed files with 117 additions and 74 deletions
|
@ -24,7 +24,12 @@ class Home extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Center(
|
return Center(
|
||||||
child: chatNavigatorUserStory(context),
|
child: chatNavigatorUserStory(context,
|
||||||
);
|
configuration: ChatUserStoryConfiguration(
|
||||||
|
chatService: LocalChatService(),
|
||||||
|
chatOptionsBuilder: (ctx) => ChatOptions(
|
||||||
|
noChatsPlaceholderBuilder: (translations) =>
|
||||||
|
Text(translations.noUsersFound),
|
||||||
|
))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@ class ChatOptions {
|
||||||
this.userAvatarBuilder = _createUserAvatar,
|
this.userAvatarBuilder = _createUserAvatar,
|
||||||
this.groupAvatarBuilder = _createGroupAvatar,
|
this.groupAvatarBuilder = _createGroupAvatar,
|
||||||
this.noChatsPlaceholderBuilder = _createNoChatsPlaceholder,
|
this.noChatsPlaceholderBuilder = _createNoChatsPlaceholder,
|
||||||
|
this.noUsersPlaceholderBuilder = _createNoUsersPlaceholder,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// Builder function for the new chat button.
|
/// Builder function for the new chat button.
|
||||||
|
@ -43,6 +44,9 @@ class ChatOptions {
|
||||||
|
|
||||||
/// Builder function for the placeholder shown when no chats are available.
|
/// Builder function for the placeholder shown when no chats are available.
|
||||||
final NoChatsPlaceholderBuilder noChatsPlaceholderBuilder;
|
final NoChatsPlaceholderBuilder noChatsPlaceholderBuilder;
|
||||||
|
|
||||||
|
/// Builder function for the placeholder shown when no users are available.
|
||||||
|
final NoUsersPlaceholderBuilder noUsersPlaceholderBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _createNewChatButton(
|
Widget _createNewChatButton(
|
||||||
|
@ -179,6 +183,20 @@ Widget _createGroupAvatar(
|
||||||
|
|
||||||
Widget _createNoChatsPlaceholder(
|
Widget _createNoChatsPlaceholder(
|
||||||
ChatTranslations translations,
|
ChatTranslations translations,
|
||||||
|
) =>
|
||||||
|
Center(
|
||||||
|
child: Text(
|
||||||
|
translations.noChatsFound,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 18,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _createNoUsersPlaceholder(
|
||||||
|
ChatTranslations translations,
|
||||||
) =>
|
) =>
|
||||||
Center(
|
Center(
|
||||||
child: Text(
|
child: Text(
|
||||||
|
@ -231,3 +249,7 @@ typedef GroupAvatarBuilder = Widget Function(
|
||||||
typedef NoChatsPlaceholderBuilder = Widget Function(
|
typedef NoChatsPlaceholderBuilder = Widget Function(
|
||||||
ChatTranslations translations,
|
ChatTranslations translations,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
typedef NoUsersPlaceholderBuilder = Widget Function(
|
||||||
|
ChatTranslations translations,
|
||||||
|
);
|
||||||
|
|
|
@ -20,7 +20,8 @@ class ChatTranslations {
|
||||||
'Are you sure you want to delete this chat?',
|
'Are you sure you want to delete this chat?',
|
||||||
this.deleteChatModalCancel = 'Cancel',
|
this.deleteChatModalCancel = 'Cancel',
|
||||||
this.deleteChatModalConfirm = 'Delete',
|
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.anonymousUser = 'Anonymous user',
|
||||||
this.chatCantBeDeleted = 'This chat can\'t be deleted',
|
this.chatCantBeDeleted = 'This chat can\'t be deleted',
|
||||||
this.chatProfileUsers = 'Users:',
|
this.chatProfileUsers = 'Users:',
|
||||||
|
@ -42,6 +43,7 @@ class ChatTranslations {
|
||||||
final String deleteChatModalCancel;
|
final String deleteChatModalCancel;
|
||||||
final String deleteChatModalConfirm;
|
final String deleteChatModalConfirm;
|
||||||
final String noUsersFound;
|
final String noUsersFound;
|
||||||
|
final String noChatsFound;
|
||||||
final String chatCantBeDeleted;
|
final String chatCantBeDeleted;
|
||||||
final String chatProfileUsers;
|
final String chatProfileUsers;
|
||||||
|
|
||||||
|
|
|
@ -196,28 +196,38 @@ class _ChatDetailScreenState extends State<ChatDetailScreen> {
|
||||||
36.0,
|
36.0,
|
||||||
),
|
),
|
||||||
] else if (chatModel is PersonalChatModel) ...[
|
] else if (chatModel is PersonalChatModel) ...[
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
widget.options.userAvatarBuilder(
|
widget.options.userAvatarBuilder(
|
||||||
chatModel.user,
|
chatModel.user,
|
||||||
36.0,
|
36.0,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
] else
|
||||||
Text(
|
...[],
|
||||||
chatModel.user.firstName ??
|
Padding(
|
||||||
widget.translations.anonymousUser,
|
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 ??
|
style: theme.appBarTheme.titleTextStyle ??
|
||||||
const TextStyle(
|
const TextStyle(
|
||||||
fontSize: 18,
|
|
||||||
fontWeight: FontWeight.w800,
|
fontWeight: FontWeight.w800,
|
||||||
|
fontSize: 18.0,
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
] else
|
|
||||||
...[],
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
@ -304,7 +304,8 @@ class ChatListItem extends StatelessWidget {
|
||||||
translations.anonymousUser,
|
translations.anonymousUser,
|
||||||
subTitle: chat.lastMessage != null
|
subTitle: chat.lastMessage != null
|
||||||
? chat.lastMessage is ChatTextMessageModel
|
? chat.lastMessage is ChatTextMessageModel
|
||||||
? (chat.lastMessage! as ChatTextMessageModel).text
|
? (chat.lastMessage! as ChatTextMessageModel)
|
||||||
|
.text
|
||||||
: '📷 '
|
: '📷 '
|
||||||
'${translations.image}'
|
'${translations.image}'
|
||||||
: '',
|
: '',
|
||||||
|
@ -319,7 +320,8 @@ class ChatListItem extends StatelessWidget {
|
||||||
unreadMessages: chat.unreadMessages ?? 0,
|
unreadMessages: chat.unreadMessages ?? 0,
|
||||||
subTitle: chat.lastMessage != null
|
subTitle: chat.lastMessage != null
|
||||||
? chat.lastMessage is ChatTextMessageModel
|
? chat.lastMessage is ChatTextMessageModel
|
||||||
? (chat.lastMessage! as ChatTextMessageModel).text
|
? (chat.lastMessage! as ChatTextMessageModel)
|
||||||
|
.text
|
||||||
: '📷 '
|
: '📷 '
|
||||||
'${translations.image}'
|
'${translations.image}'
|
||||||
: '',
|
: '',
|
||||||
|
|
|
@ -106,8 +106,10 @@ class _NewChatScreenState extends State<NewChatScreen> {
|
||||||
} else if (snapshot.hasData) {
|
} else if (snapshot.hasData) {
|
||||||
return _buildUserList(snapshot.data!);
|
return _buildUserList(snapshot.data!);
|
||||||
} else {
|
} else {
|
||||||
return widget.options
|
return Padding(
|
||||||
.noChatsPlaceholderBuilder(widget.translations);
|
padding: const EdgeInsets.only(top: 20.0),
|
||||||
|
child: Text(widget.translations.noUsersFound),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
Loading…
Reference in a new issue