From 146ec3a1a92864c88b5f044145708ddd96129129 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Wed, 22 May 2024 11:59:21 +0200 Subject: [PATCH] feat: make all transltions required for ChatTranslations and provide an .empty() alternative --- CHANGELOG.md | 1 + .../lib/src/config/chat_translations.dart | 99 +++++++++++++++++++ .../lib/src/screens/chat_detail_screen.dart | 2 +- .../lib/src/screens/chat_screen.dart | 2 +- .../lib/src/screens/new_chat_screen.dart | 2 +- .../new_group_chat_overview_screen.dart | 2 +- .../src/screens/new_group_chat_screen.dart | 2 +- 7 files changed, 105 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ac7d60..acb7b46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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 8b603a1..77ba758 100644 --- a/packages/flutter_chat_view/lib/src/config/chat_translations.dart +++ b/packages/flutter_chat_view/lib/src/config/chat_translations.dart @@ -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, + ); } 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 649aa13..3fc852d 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 @@ -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, 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 9e56321..bfddd58 100644 --- a/packages/flutter_chat_view/lib/src/screens/chat_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/chat_screen.dart @@ -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, }); 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 50bdd79..0be987b 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 @@ -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, }); diff --git a/packages/flutter_chat_view/lib/src/screens/new_group_chat_overview_screen.dart b/packages/flutter_chat_view/lib/src/screens/new_group_chat_overview_screen.dart index 64bf286..22ff727 100644 --- a/packages/flutter_chat_view/lib/src/screens/new_group_chat_overview_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/new_group_chat_overview_screen.dart @@ -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, }); diff --git a/packages/flutter_chat_view/lib/src/screens/new_group_chat_screen.dart b/packages/flutter_chat_view/lib/src/screens/new_group_chat_screen.dart index a7e6c07..d527e22 100644 --- a/packages/flutter_chat_view/lib/src/screens/new_group_chat_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/new_group_chat_screen.dart @@ -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, });