feat: add onPopInvoked callback for a popscope inside the userstory

This commit is contained in:
Freek van de Ven 2024-06-13 09:33:11 +02:00
parent 8b4ada7edc
commit d13a8013ac
4 changed files with 56 additions and 39 deletions

View file

@ -2,6 +2,7 @@
- fix bug where you could make multiple groups quickly by routing back to the previous screen
- fix bug where you would route back to the user selection screen insterad of routing back to the chat overview screen
- Add onPopInvoked callback to the userstory to add custom behaviour for the back button on the chatscreen
## 3.0.0

View file

@ -30,7 +30,11 @@ Widget _chatScreenRoute(
ChatUserStoryConfiguration configuration,
BuildContext context,
) =>
ChatScreen(
PopScope(
canPop: configuration.onPopInvoked == null,
onPopInvoked: (didPop) =>
configuration.onPopInvoked?.call(didPop, context),
child: ChatScreen(
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
service: configuration.chatService,
options: configuration.chatOptionsBuilder(context),
@ -72,6 +76,7 @@ Widget _chatScreenRoute(
configuration.chatService.chatOverviewService.deleteChat(chat),
deleteChatDialog: configuration.deleteChatDialog,
translations: configuration.translations,
),
);
/// Constructs the chat detail screen route widget.

View file

@ -43,6 +43,10 @@ List<GoRoute> getChatStoryRoutes(
return buildScreenWithoutTransition(
context: context,
state: state,
child: PopScope(
canPop: configuration.onPopInvoked == null,
onPopInvoked: (didPop) =>
configuration.onPopInvoked?.call(didPop, context),
child: configuration.chatPageBuilder?.call(
context,
chatScreen,
@ -51,6 +55,7 @@ List<GoRoute> getChatStoryRoutes(
backgroundColor: theme.colorScheme.surface,
body: chatScreen,
),
),
);
},
),

View file

@ -21,6 +21,7 @@ class ChatUserStoryConfiguration {
this.onMessageSubmit,
this.onReadChat,
this.onUploadImage,
this.onPopInvoked,
this.onPressCreateChat,
this.onPressCreateGroupChat,
this.onPressCompleteGroupChatCreation,
@ -118,6 +119,11 @@ class ChatUserStoryConfiguration {
/// Callback function triggered when user profile is pressed.
final Function(BuildContext context, ChatUserModel user)? onPressUserProfile;
/// Callback function triggered when the popscope on the chat
/// homepage is triggered.
// ignore: avoid_positional_boolean_parameters
final Function(bool didPop, BuildContext context)? onPopInvoked;
final double? textfieldBottomPadding;
final Color? iconDisabledColor;