diff --git a/CHANGELOG.md b/CHANGELOG.md index b138f09..626b76f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.0.0 + +- Add a serviceBuilder to the userstory configuration +- Add a translationsBuilder to the userstory configuration + ## 1.4.3 - Added default styling. diff --git a/packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart b/packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart index 0ea5323..02c70f6 100644 --- a/packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart +++ b/packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart @@ -4,7 +4,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_chat/flutter_chat.dart'; -import 'package:uuid/uuid.dart'; /// Navigates to the chat user story screen. /// diff --git a/packages/flutter_chat/lib/src/flutter_chat_userstory.dart b/packages/flutter_chat/lib/src/flutter_chat_userstory.dart index 2e00c9d..ce4406e 100644 --- a/packages/flutter_chat/lib/src/flutter_chat_userstory.dart +++ b/packages/flutter_chat/lib/src/flutter_chat_userstory.dart @@ -14,9 +14,11 @@ List getChatStoryRoutes( GoRoute( path: ChatUserStoryRoutes.chatScreen, pageBuilder: (context, state) { + var service = configuration.chatServiceBuilder?.call(context) ?? + configuration.chatService; var chatScreen = ChatScreen( unreadMessageTextStyle: configuration.unreadMessageTextStyle, - service: configuration.chatService, + service: service, options: configuration.chatOptionsBuilder(context), onNoChats: () async => context.push(ChatUserStoryRoutes.newChatScreen), @@ -34,7 +36,8 @@ List getChatStoryRoutes( configuration.onDeleteChat?.call(context, chat) ?? configuration.chatService.chatOverviewService.deleteChat(chat), deleteChatDialog: configuration.deleteChatDialog, - translations: configuration.translations, + translations: configuration.translationsBuilder?.call(context) ?? + configuration.translations, ); return buildScreenWithoutTransition( context: context, @@ -53,6 +56,8 @@ List getChatStoryRoutes( path: ChatUserStoryRoutes.chatDetailScreen, pageBuilder: (context, state) { var chatId = state.pathParameters['id']; + var service = configuration.chatServiceBuilder?.call(context) ?? + configuration.chatService; var chatDetailScreen = ChatDetailScreen( chatTitleBuilder: configuration.chatTitleBuilder, usernameBuilder: configuration.usernameBuilder, @@ -60,8 +65,9 @@ List getChatStoryRoutes( iconDisabledColor: configuration.iconDisabledColor, pageSize: configuration.messagePageSize, options: configuration.chatOptionsBuilder(context), - translations: configuration.translations, - service: configuration.chatService, + translations: configuration.translationsBuilder?.call(context) ?? + configuration.translations, + service: service, chatId: chatId!, textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0, onPressUserProfile: (userId) async { @@ -120,10 +126,13 @@ List getChatStoryRoutes( GoRoute( path: ChatUserStoryRoutes.newChatScreen, pageBuilder: (context, state) { + var service = configuration.chatServiceBuilder?.call(context) ?? + configuration.chatService; var newChatScreen = NewChatScreen( options: configuration.chatOptionsBuilder(context), - translations: configuration.translations, - service: configuration.chatService, + translations: configuration.translationsBuilder?.call(context) ?? + configuration.translations, + service: service, onPressCreateChat: (user) async { configuration.onPressCreateChat?.call(user); if (configuration.onPressCreateChat != null) return; @@ -163,10 +172,13 @@ List getChatStoryRoutes( GoRoute( path: ChatUserStoryRoutes.newGroupChatScreen, pageBuilder: (context, state) { + var service = configuration.chatServiceBuilder?.call(context) ?? + configuration.chatService; var newGroupChatScreen = NewGroupChatScreen( options: configuration.chatOptionsBuilder(context), - translations: configuration.translations, - service: configuration.chatService, + translations: configuration.translationsBuilder?.call(context) ?? + configuration.translations, + service: service, onPressGroupChatOverview: (users) async => context.push( ChatUserStoryRoutes.newGroupChatOverviewScreen, extra: users, @@ -188,11 +200,14 @@ List getChatStoryRoutes( GoRoute( path: ChatUserStoryRoutes.newGroupChatOverviewScreen, pageBuilder: (context, state) { + var service = configuration.chatServiceBuilder?.call(context) ?? + configuration.chatService; var users = state.extra! as List; var newGroupChatOverviewScreen = NewGroupChatOverviewScreen( options: configuration.chatOptionsBuilder(context), - translations: configuration.translations, - service: configuration.chatService, + translations: configuration.translationsBuilder?.call(context) ?? + configuration.translations, + service: service, users: users, onPressCompleteGroupChatCreation: (users, groupChatName) async { configuration.onPressCompleteGroupChatCreation @@ -232,9 +247,12 @@ List getChatStoryRoutes( var chatId = state.pathParameters['id']; var userId = state.pathParameters['userId']; var id = userId == 'null' ? null : userId; + var service = configuration.chatServiceBuilder?.call(context) ?? + configuration.chatService; var profileScreen = ChatProfileScreen( - translations: configuration.translations, - chatService: configuration.chatService, + translations: configuration.translationsBuilder?.call(context) ?? + configuration.translations, + chatService: service, chatId: chatId!, userId: id, onTapUser: (user) async { diff --git a/packages/flutter_chat/lib/src/models/chat_configuration.dart b/packages/flutter_chat/lib/src/models/chat_configuration.dart index cd47146..ed4fd77 100644 --- a/packages/flutter_chat/lib/src/models/chat_configuration.dart +++ b/packages/flutter_chat/lib/src/models/chat_configuration.dart @@ -14,6 +14,7 @@ class ChatUserStoryConfiguration { const ChatUserStoryConfiguration({ required this.chatService, required this.chatOptionsBuilder, + this.chatServiceBuilder, this.onPressStartChat, this.onPressChat, this.onDeleteChat, @@ -28,6 +29,7 @@ class ChatUserStoryConfiguration { this.disableDismissForPermanentChats = false, this.routeToNewChatIfEmpty = true, this.translations = const ChatTranslations(), + this.translationsBuilder, this.chatPageBuilder, this.onPressChatTitle, this.afterMessageSent, @@ -44,6 +46,9 @@ class ChatUserStoryConfiguration { /// The service responsible for handling chat-related functionalities. final ChatService chatService; + /// A method to get the chat service only when needed and with a context. + final ChatService Function(BuildContext context)? chatServiceBuilder; + /// Callback function triggered when a chat is pressed. final Function(BuildContext, ChatModel)? onPressChat; @@ -53,6 +58,9 @@ class ChatUserStoryConfiguration { /// Translations for internationalization/localization support. final ChatTranslations translations; + /// Translations builder because context might be needed for translations. + final ChatTranslations Function(BuildContext context)? translationsBuilder; + /// Determines whether dismissing is disabled for permanent chats. final bool disableDismissForPermanentChats; diff --git a/packages/flutter_chat/pubspec.yaml b/packages/flutter_chat/pubspec.yaml index 748478e..778afe6 100644 --- a/packages/flutter_chat/pubspec.yaml +++ b/packages/flutter_chat/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_chat description: A new Flutter package project. -version: 1.4.3 +version: 2.0.0 publish_to: none @@ -20,17 +20,17 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_chat path: packages/flutter_chat_view - ref: 1.4.3 + ref: 2.0.0 flutter_chat_interface: git: url: https://github.com/Iconica-Development/flutter_chat path: packages/flutter_chat_interface - ref: 1.4.3 + ref: 2.0.0 flutter_chat_local: git: url: https://github.com/Iconica-Development/flutter_chat path: packages/flutter_chat_local - ref: 1.4.3 + ref: 2.0.0 uuid: ^4.3.3 dev_dependencies: diff --git a/packages/flutter_chat_firebase/pubspec.yaml b/packages/flutter_chat_firebase/pubspec.yaml index 67c9eb5..d4ebeab 100644 --- a/packages/flutter_chat_firebase/pubspec.yaml +++ b/packages/flutter_chat_firebase/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_chat_firebase description: A new Flutter package project. -version: 1.4.3 +version: 2.0.0 publish_to: none environment: @@ -23,7 +23,7 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_chat path: packages/flutter_chat_interface - ref: 1.4.3 + ref: 2.0.0 dev_dependencies: flutter_iconica_analysis: diff --git a/packages/flutter_chat_interface/pubspec.yaml b/packages/flutter_chat_interface/pubspec.yaml index dfd6b0c..40d2480 100644 --- a/packages/flutter_chat_interface/pubspec.yaml +++ b/packages/flutter_chat_interface/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_chat_interface description: A new Flutter package project. -version: 1.4.3 +version: 2.0.0 publish_to: none environment: diff --git a/packages/flutter_chat_local/pubspec.yaml b/packages/flutter_chat_local/pubspec.yaml index 221a65b..c37efa4 100644 --- a/packages/flutter_chat_local/pubspec.yaml +++ b/packages/flutter_chat_local/pubspec.yaml @@ -1,8 +1,7 @@ name: flutter_chat_local description: "A new Flutter package project." -version: 1.4.3 +version: 2.0.0 publish_to: none -homepage: environment: sdk: ">=3.2.5 <4.0.0" @@ -15,7 +14,7 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_chat path: packages/flutter_chat_interface - ref: 1.4.3 + ref: 2.0.0 dev_dependencies: flutter_test: diff --git a/packages/flutter_chat_view/pubspec.yaml b/packages/flutter_chat_view/pubspec.yaml index 9791dae..06de508 100644 --- a/packages/flutter_chat_view/pubspec.yaml +++ b/packages/flutter_chat_view/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_chat_view description: A standard flutter package. -version: 1.4.3 +version: 2.0.0 publish_to: none @@ -20,7 +20,7 @@ dependencies: git: url: https://github.com/Iconica-Development/flutter_chat path: packages/flutter_chat_interface - ref: 1.4.3 + ref: 2.0.0 cached_network_image: ^3.2.2 flutter_image_picker: git: