Skip to content

Commit

Permalink
feat: make all transltions required for ChatTranslations and provide …
Browse files Browse the repository at this point in the history
…an .empty() alternative
  • Loading branch information
freekvandeven committed May 22, 2024
1 parent b5656d5 commit 146ec3a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
99 changes: 99 additions & 0 deletions packages/flutter_chat_view/lib/src/config/chat_translations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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,
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down

0 comments on commit 146ec3a

Please sign in to comment.