From 86c50f47f6ce3f7b7bb71f3256e18f715cf93d8c Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Thu, 9 May 2024 19:46:31 +0200 Subject: [PATCH] feat: change onPressUserProfile callback to use the ChatUserModel --- CHANGELOG.md | 1 + .../lib/src/flutter_chat_navigator_userstory.dart | 8 ++++---- .../flutter_chat/lib/src/flutter_chat_userstory.dart | 10 +++++----- .../lib/src/models/chat_configuration.dart | 12 +++++++++++- .../lib/src/components/chat_detail_row.dart | 4 ++-- .../lib/src/screens/chat_detail_screen.dart | 2 +- .../lib/src/screens/chat_profile_screen.dart | 4 ++-- 7 files changed, 26 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 626b76f..c500418 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Add a serviceBuilder to the userstory configuration - Add a translationsBuilder to the userstory configuration +- Change onPressUserProfile callback to use a ChatUserModel instead of a String ## 1.4.3 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 02c70f6..df03fb3 100644 --- a/packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart +++ b/packages/flutter_chat/lib/src/flutter_chat_navigator_userstory.dart @@ -95,9 +95,9 @@ Widget _chatDetailScreenRoute( service: configuration.chatService, chatId: chatId, textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0, - onPressUserProfile: (userId) async { + onPressUserProfile: (user) async { if (configuration.onPressUserProfile != null) { - return configuration.onPressUserProfile?.call(); + return configuration.onPressUserProfile?.call(context, user); } return Navigator.of(context).push( MaterialPageRoute( @@ -105,7 +105,7 @@ Widget _chatDetailScreenRoute( configuration, context, chatId, - userId, + user.id, ), ), ); @@ -171,7 +171,7 @@ Widget _chatProfileScreenRoute( userId: userId, onTapUser: (user) async { if (configuration.onPressUserProfile != null) { - return configuration.onPressUserProfile!.call(); + return configuration.onPressUserProfile!.call(context, user); } return Navigator.of(context).push( diff --git a/packages/flutter_chat/lib/src/flutter_chat_userstory.dart b/packages/flutter_chat/lib/src/flutter_chat_userstory.dart index ce4406e..e41b519 100644 --- a/packages/flutter_chat/lib/src/flutter_chat_userstory.dart +++ b/packages/flutter_chat/lib/src/flutter_chat_userstory.dart @@ -70,12 +70,12 @@ List getChatStoryRoutes( service: service, chatId: chatId!, textfieldBottomPadding: configuration.textfieldBottomPadding ?? 0, - onPressUserProfile: (userId) async { + onPressUserProfile: (user) async { if (configuration.onPressUserProfile != null) { - return configuration.onPressUserProfile?.call(); + return configuration.onPressUserProfile?.call(context, user); } return context.push( - ChatUserStoryRoutes.chatProfileScreenPath(chatId, userId), + ChatUserStoryRoutes.chatProfileScreenPath(chatId, user.id), ); }, onMessageSubmit: (message) async { @@ -257,11 +257,11 @@ List getChatStoryRoutes( userId: id, onTapUser: (user) async { if (configuration.onPressUserProfile != null) { - return configuration.onPressUserProfile!.call(); + return configuration.onPressUserProfile!.call(context, user); } return context.push( - ChatUserStoryRoutes.chatProfileScreenPath(chatId, user), + ChatUserStoryRoutes.chatProfileScreenPath(chatId, user.id), ); }, ); diff --git a/packages/flutter_chat/lib/src/models/chat_configuration.dart b/packages/flutter_chat/lib/src/models/chat_configuration.dart index ed4fd77..7e22843 100644 --- a/packages/flutter_chat/lib/src/models/chat_configuration.dart +++ b/packages/flutter_chat/lib/src/models/chat_configuration.dart @@ -82,7 +82,10 @@ class ChatUserStoryConfiguration { /// Builder for chat options based on context. final Function(List, String)? onPressCompleteGroupChatCreation; + final Function()? onPressCreateGroupChat; + + /// Builder for the chat options which can be used to style the UI of the chat final ChatOptions Function(BuildContext context) chatOptionsBuilder; /// If true, the user will be routed to the new chat screen if there are @@ -108,11 +111,18 @@ class ChatUserStoryConfiguration { final Function()? onPressStartChat; /// Callback function triggered when user profile is pressed. - final Function()? onPressUserProfile; + final Function(BuildContext context, ChatUserModel user)? onPressUserProfile; + final double? textfieldBottomPadding; + final Color? iconDisabledColor; + + /// The text style used for the unread message counter. final TextStyle? unreadMessageTextStyle; + final Widget? Function(BuildContext context)? loadingWidgetBuilder; + final Widget Function(String userFullName)? usernameBuilder; + final Widget Function(String chatTitle)? chatTitleBuilder; } diff --git a/packages/flutter_chat_view/lib/src/components/chat_detail_row.dart b/packages/flutter_chat_view/lib/src/components/chat_detail_row.dart index 75b9838..107a855 100644 --- a/packages/flutter_chat_view/lib/src/components/chat_detail_row.dart +++ b/packages/flutter_chat_view/lib/src/components/chat_detail_row.dart @@ -31,7 +31,7 @@ class ChatDetailRow extends StatefulWidget { /// The previous chat message model. final ChatMessageModel? previousMessage; - final Function(String? userId) onPressUserProfile; + final Function(ChatUserModel user) onPressUserProfile; final Widget Function(String userFullName)? usernameBuilder; /// Flag indicating whether to show the time. @@ -65,7 +65,7 @@ class _ChatDetailRowState extends State { if (isNewDate || isSameSender) ...[ GestureDetector( onTap: () => widget.onPressUserProfile( - widget.message.sender.id, + widget.message.sender, ), child: Padding( padding: const EdgeInsets.only(left: 10.0), 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 234325c..649aa13 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 @@ -53,7 +53,7 @@ class ChatDetailScreen extends StatefulWidget { final int pageSize; final double textfieldBottomPadding; final Color? iconDisabledColor; - final Function(String? userId) onPressUserProfile; + final Function(ChatUserModel user) onPressUserProfile; // ignore: avoid_positional_boolean_parameters final Widget? Function(BuildContext context)? loadingWidgetBuilder; final Widget Function(String userFullName)? usernameBuilder; diff --git a/packages/flutter_chat_view/lib/src/screens/chat_profile_screen.dart b/packages/flutter_chat_view/lib/src/screens/chat_profile_screen.dart index 5e92b55..a6bfa9a 100644 --- a/packages/flutter_chat_view/lib/src/screens/chat_profile_screen.dart +++ b/packages/flutter_chat_view/lib/src/screens/chat_profile_screen.dart @@ -26,7 +26,7 @@ class ChatProfileScreen extends StatefulWidget { final String? userId; /// Callback function for tapping on a user. - final Function(String userId) onTapUser; + final Function(ChatUserModel user) onTapUser; @override State createState() => _ProfileScreenState(); @@ -124,7 +124,7 @@ class _ProfileScreenState extends State { return Padding( padding: const EdgeInsets.symmetric(vertical: 4.0), child: GestureDetector( - onTap: () => widget.onTapUser.call(e.id!), + onTap: () => widget.onTapUser.call(e), child: Column( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min,