feat: make all transltions required for ChatTranslations and provide an .empty() alternative

This commit is contained in:
Freek van de Ven 2024-05-22 11:59:21 +02:00
parent b5656d5f3a
commit 146ec3a1a9
7 changed files with 105 additions and 5 deletions

View file

@ -4,6 +4,7 @@
- Add a translationsBuilder to the userstory configuration
- Change onPressUserProfile callback to use a ChatUserModel instead of a String
- Add a enableGroupChatCreation boolean to the userstory configuration to enable or disable group chat creation
- Change the ChatTranslations constructor to require all translations or use the ChatTranslations.empty constructor if you don't want to specify all translations
## 1.4.3

View file

@ -2,8 +2,44 @@
//
// SPDX-License-Identifier: BSD-3-Clause
/// Class that holds all the translations for the chat component view and
/// the corresponding userstory
class ChatTranslations {
/// ChatTranslations constructor where everything is required use this
/// if you want to be sure to have all translations specified
/// If you just want the default values use the empty constructor
/// and optionally override the values with the copyWith method
const ChatTranslations({
required this.chatsTitle,
required this.chatsUnread,
required this.newChatButton,
required this.newGroupChatButton,
required this.newChatTitle,
required this.deleteChatButton,
required this.image,
required this.searchPlaceholder,
required this.startTyping,
required this.cancelImagePickerBtn,
required this.messagePlaceholder,
required this.writeMessageToStartChat,
required this.writeFirstMessageInGroupChat,
required this.imageUploading,
required this.deleteChatModalTitle,
required this.deleteChatModalDescription,
required this.deleteChatModalCancel,
required this.deleteChatModalConfirm,
required this.noUsersFound,
required this.noChatsFound,
required this.chatCantBeDeleted,
required this.chatProfileUsers,
required this.imagePickerTitle,
required this.uploadFile,
required this.takePicture,
required this.anonymousUser,
});
/// Default translations for the chat component view
const ChatTranslations.empty({
this.chatsTitle = 'Chats',
this.chatsUnread = 'unread',
this.newChatButton = 'Start a chat',
@ -62,4 +98,67 @@ class ChatTranslations {
/// Shown when the user has no name
final String anonymousUser;
// copyWith method to override the default values
ChatTranslations copyWith({
String? chatsTitle,
String? chatsUnread,
String? newChatButton,
String? newGroupChatButton,
String? newChatTitle,
String? deleteChatButton,
String? image,
String? searchPlaceholder,
String? startTyping,
String? cancelImagePickerBtn,
String? messagePlaceholder,
String? writeMessageToStartChat,
String? writeFirstMessageInGroupChat,
String? imageUploading,
String? deleteChatModalTitle,
String? deleteChatModalDescription,
String? deleteChatModalCancel,
String? deleteChatModalConfirm,
String? noUsersFound,
String? noChatsFound,
String? chatCantBeDeleted,
String? chatProfileUsers,
String? imagePickerTitle,
String? uploadFile,
String? takePicture,
String? anonymousUser,
}) =>
ChatTranslations(
chatsTitle: chatsTitle ?? this.chatsTitle,
chatsUnread: chatsUnread ?? this.chatsUnread,
newChatButton: newChatButton ?? this.newChatButton,
newGroupChatButton: newGroupChatButton ?? this.newGroupChatButton,
newChatTitle: newChatTitle ?? this.newChatTitle,
deleteChatButton: deleteChatButton ?? this.deleteChatButton,
image: image ?? this.image,
searchPlaceholder: searchPlaceholder ?? this.searchPlaceholder,
startTyping: startTyping ?? this.startTyping,
cancelImagePickerBtn: cancelImagePickerBtn ?? this.cancelImagePickerBtn,
messagePlaceholder: messagePlaceholder ?? this.messagePlaceholder,
writeMessageToStartChat:
writeMessageToStartChat ?? this.writeMessageToStartChat,
writeFirstMessageInGroupChat:
writeFirstMessageInGroupChat ?? this.writeFirstMessageInGroupChat,
imageUploading: imageUploading ?? this.imageUploading,
deleteChatModalTitle: deleteChatModalTitle ?? this.deleteChatModalTitle,
deleteChatModalDescription:
deleteChatModalDescription ?? this.deleteChatModalDescription,
deleteChatModalCancel:
deleteChatModalCancel ?? this.deleteChatModalCancel,
deleteChatModalConfirm:
deleteChatModalConfirm ?? this.deleteChatModalConfirm,
noUsersFound: noUsersFound ?? this.noUsersFound,
noChatsFound: noChatsFound ?? this.noChatsFound,
chatCantBeDeleted: chatCantBeDeleted ?? this.chatCantBeDeleted,
chatProfileUsers: chatProfileUsers ?? this.chatProfileUsers,
imagePickerTitle: imagePickerTitle ?? this.imagePickerTitle,
uploadFile: uploadFile ?? this.uploadFile,
takePicture: takePicture ?? this.takePicture,
anonymousUser: anonymousUser ?? this.anonymousUser,
);
}

View file

@ -26,7 +26,7 @@ class ChatDetailScreen extends StatefulWidget {
this.chatTitleBuilder,
this.usernameBuilder,
this.loadingWidgetBuilder,
this.translations = const ChatTranslations(),
this.translations = const ChatTranslations.empty(),
this.iconColor,
this.iconDisabledColor,
this.showTime = false,

View file

@ -20,7 +20,7 @@ class ChatScreen extends StatefulWidget {
this.unreadMessageTextStyle,
this.onNoChats,
this.deleteChatDialog,
this.translations = const ChatTranslations(),
this.translations = const ChatTranslations.empty(),
this.disableDismissForPermanentChats = false,
super.key,
});

View file

@ -12,7 +12,7 @@ class NewChatScreen extends StatefulWidget {
required this.service,
required this.onPressCreateGroupChat,
this.showGroupChatButton = true,
this.translations = const ChatTranslations(),
this.translations = const ChatTranslations.empty(),
super.key,
});

View file

@ -11,7 +11,7 @@ class NewGroupChatOverviewScreen extends StatefulWidget {
required this.onPressCompleteGroupChatCreation,
required this.service,
required this.users,
this.translations = const ChatTranslations(),
this.translations = const ChatTranslations.empty(),
super.key,
});

View file

@ -8,7 +8,7 @@ class NewGroupChatScreen extends StatefulWidget {
required this.options,
required this.onPressGroupChatOverview,
required this.service,
this.translations = const ChatTranslations(),
this.translations = const ChatTranslations.empty(),
super.key,
});