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,48 +30,53 @@ Widget _chatScreenRoute(
ChatUserStoryConfiguration configuration,
BuildContext context,
) =>
ChatScreen(
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
service: configuration.chatService,
options: configuration.chatOptionsBuilder(context),
onNoChats: () async => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _newChatScreenRoute(
configuration,
context,
),
),
),
onPressStartChat: () async {
if (configuration.onPressStartChat != null) {
return await configuration.onPressStartChat?.call();
}
return Navigator.of(context).push(
PopScope(
canPop: configuration.onPopInvoked == null,
onPopInvoked: (didPop) =>
configuration.onPopInvoked?.call(didPop, context),
child: ChatScreen(
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
service: configuration.chatService,
options: configuration.chatOptionsBuilder(context),
onNoChats: () async => Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _newChatScreenRoute(
configuration,
context,
),
),
);
},
onPressChat: (chat) async =>
configuration.onPressChat?.call(context, chat) ??
await Navigator.of(context).push(
),
onPressStartChat: () async {
if (configuration.onPressStartChat != null) {
return await configuration.onPressStartChat?.call();
}
return Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _chatDetailScreenRoute(
builder: (context) => _newChatScreenRoute(
configuration,
context,
chat.id!,
),
),
),
onDeleteChat: (chat) async =>
configuration.onDeleteChat?.call(context, chat) ??
configuration.chatService.chatOverviewService.deleteChat(chat),
deleteChatDialog: configuration.deleteChatDialog,
translations: configuration.translations,
);
},
onPressChat: (chat) async =>
configuration.onPressChat?.call(context, chat) ??
await Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => _chatDetailScreenRoute(
configuration,
context,
chat.id!,
),
),
),
onDeleteChat: (chat) async =>
configuration.onDeleteChat?.call(context, chat) ??
configuration.chatService.chatOverviewService.deleteChat(chat),
deleteChatDialog: configuration.deleteChatDialog,
translations: configuration.translations,
),
);
/// Constructs the chat detail screen route widget.

View file

@ -43,14 +43,19 @@ List<GoRoute> getChatStoryRoutes(
return buildScreenWithoutTransition(
context: context,
state: state,
child: configuration.chatPageBuilder?.call(
context,
chatScreen,
) ??
Scaffold(
backgroundColor: theme.colorScheme.surface,
body: chatScreen,
),
child: PopScope(
canPop: configuration.onPopInvoked == null,
onPopInvoked: (didPop) =>
configuration.onPopInvoked?.call(didPop, context),
child: configuration.chatPageBuilder?.call(
context,
chatScreen,
) ??
Scaffold(
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;