From 62f04e2d9b78ebfc0b982ae1fc7f723e13f90ab6 Mon Sep 17 00:00:00 2001 From: Freek van de Ven Date: Wed, 19 Feb 2025 15:40:24 +0100 Subject: [PATCH] feat: add chatScreenBuilder to use instead of baseScreenBuilder on the ChatDetailScreen --- CHANGELOG.md | 1 + .../lib/src/config/chat_builders.dart | 15 ++++++++++ .../chat_detail/chat_detail_screen.dart | 30 ++++++++++++------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98b3b39..9744590 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ - Added sender and chatId to uploadImage in the ChatRepositoryInterface - Added imagePickerBuilder to the builders in the ChatOptions to override the image picker with a custom implementation that needs to return a Future - Changed the ChatBottomInputSection to be multiline and go from 45px to 120px in height depending on how many lines are in the textfield +- Added chatScreenBuilder to the userstory configuration to customize the specific chat screen with a ChatModel as argument ## 4.0.0 - Move to the new user story architecture diff --git a/packages/flutter_chat/lib/src/config/chat_builders.dart b/packages/flutter_chat/lib/src/config/chat_builders.dart index ae300a2..9928b0b 100644 --- a/packages/flutter_chat/lib/src/config/chat_builders.dart +++ b/packages/flutter_chat/lib/src/config/chat_builders.dart @@ -13,6 +13,7 @@ class ChatBuilders { /// The chat builders constructor const ChatBuilders({ this.baseScreenBuilder, + this.chatScreenBuilder, this.messageInputBuilder, this.chatRowContainerBuilder, this.groupAvatarBuilder, @@ -45,6 +46,11 @@ class ChatBuilders { /// ``` final BaseScreenBuilder? baseScreenBuilder; + /// The chat screen builder + /// This builder is used instead of the [baseScreenBuilder] when building the + /// chat screen. While the chat is still loading the [chat] will be null + final ChatScreenBuilder? chatScreenBuilder; + /// The message input builder final TextInputBuilder? messageInputBuilder; @@ -133,6 +139,15 @@ typedef BaseScreenBuilder = Widget Function( Widget body, ); +/// The chat screen builder +typedef ChatScreenBuilder = Widget Function( + BuildContext context, + ChatModel? chat, + PreferredSizeWidget appBar, + String? title, + Widget body, +); + /// The container builder typedef ContainerBuilder = Widget Function( BuildContext context, diff --git a/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart b/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart index 382fe50..2c451e6 100644 --- a/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart +++ b/packages/flutter_chat/lib/src/screens/chat_detail/chat_detail_screen.dart @@ -108,19 +108,29 @@ class ChatDetailScreen extends HookWidget { onReadChat: onReadChat, ); - if (options.builders.baseScreenBuilder == null) { - return Scaffold( - appBar: appBar, - body: body, + if (options.builders.chatScreenBuilder != null) { + return options.builders.chatScreenBuilder!.call( + context, + chat, + appBar, + chatTitle.value, + body, ); } - return options.builders.baseScreenBuilder!.call( - context, - mapScreenType, - appBar, - chatTitle.value, - body, + if (options.builders.baseScreenBuilder != null) { + return options.builders.baseScreenBuilder!.call( + context, + mapScreenType, + appBar, + chatTitle.value, + body, + ); + } + + return Scaffold( + appBar: appBar, + body: body, ); }