mirror of
https://github.com/Iconica-Development/flutter_chat.git
synced 2025-05-19 02:43:50 +02:00
feat: add onPopInvoked callback for a popscope inside the userstory
This commit is contained in:
parent
8b4ada7edc
commit
d13a8013ac
4 changed files with 56 additions and 39 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
- fix bug where you could make multiple groups quickly by routing back to the previous screen
|
- 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
|
- 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
|
## 3.0.0
|
||||||
|
|
||||||
|
|
|
@ -30,48 +30,53 @@ Widget _chatScreenRoute(
|
||||||
ChatUserStoryConfiguration configuration,
|
ChatUserStoryConfiguration configuration,
|
||||||
BuildContext context,
|
BuildContext context,
|
||||||
) =>
|
) =>
|
||||||
ChatScreen(
|
PopScope(
|
||||||
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
|
canPop: configuration.onPopInvoked == null,
|
||||||
service: configuration.chatService,
|
onPopInvoked: (didPop) =>
|
||||||
options: configuration.chatOptionsBuilder(context),
|
configuration.onPopInvoked?.call(didPop, context),
|
||||||
onNoChats: () async => Navigator.of(context).push(
|
child: ChatScreen(
|
||||||
MaterialPageRoute(
|
unreadMessageTextStyle: configuration.unreadMessageTextStyle,
|
||||||
builder: (context) => _newChatScreenRoute(
|
service: configuration.chatService,
|
||||||
configuration,
|
options: configuration.chatOptionsBuilder(context),
|
||||||
context,
|
onNoChats: () async => Navigator.of(context).push(
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
onPressStartChat: () async {
|
|
||||||
if (configuration.onPressStartChat != null) {
|
|
||||||
return await configuration.onPressStartChat?.call();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Navigator.of(context).push(
|
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _newChatScreenRoute(
|
builder: (context) => _newChatScreenRoute(
|
||||||
configuration,
|
configuration,
|
||||||
context,
|
context,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
},
|
onPressStartChat: () async {
|
||||||
onPressChat: (chat) async =>
|
if (configuration.onPressStartChat != null) {
|
||||||
configuration.onPressChat?.call(context, chat) ??
|
return await configuration.onPressStartChat?.call();
|
||||||
await Navigator.of(context).push(
|
}
|
||||||
|
|
||||||
|
return Navigator.of(context).push(
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
builder: (context) => _chatDetailScreenRoute(
|
builder: (context) => _newChatScreenRoute(
|
||||||
configuration,
|
configuration,
|
||||||
context,
|
context,
|
||||||
chat.id!,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
onDeleteChat: (chat) async =>
|
},
|
||||||
configuration.onDeleteChat?.call(context, chat) ??
|
onPressChat: (chat) async =>
|
||||||
configuration.chatService.chatOverviewService.deleteChat(chat),
|
configuration.onPressChat?.call(context, chat) ??
|
||||||
deleteChatDialog: configuration.deleteChatDialog,
|
await Navigator.of(context).push(
|
||||||
translations: configuration.translations,
|
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.
|
/// Constructs the chat detail screen route widget.
|
||||||
|
|
|
@ -43,14 +43,19 @@ List<GoRoute> getChatStoryRoutes(
|
||||||
return buildScreenWithoutTransition(
|
return buildScreenWithoutTransition(
|
||||||
context: context,
|
context: context,
|
||||||
state: state,
|
state: state,
|
||||||
child: configuration.chatPageBuilder?.call(
|
child: PopScope(
|
||||||
context,
|
canPop: configuration.onPopInvoked == null,
|
||||||
chatScreen,
|
onPopInvoked: (didPop) =>
|
||||||
) ??
|
configuration.onPopInvoked?.call(didPop, context),
|
||||||
Scaffold(
|
child: configuration.chatPageBuilder?.call(
|
||||||
backgroundColor: theme.colorScheme.surface,
|
context,
|
||||||
body: chatScreen,
|
chatScreen,
|
||||||
),
|
) ??
|
||||||
|
Scaffold(
|
||||||
|
backgroundColor: theme.colorScheme.surface,
|
||||||
|
body: chatScreen,
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
@ -21,6 +21,7 @@ class ChatUserStoryConfiguration {
|
||||||
this.onMessageSubmit,
|
this.onMessageSubmit,
|
||||||
this.onReadChat,
|
this.onReadChat,
|
||||||
this.onUploadImage,
|
this.onUploadImage,
|
||||||
|
this.onPopInvoked,
|
||||||
this.onPressCreateChat,
|
this.onPressCreateChat,
|
||||||
this.onPressCreateGroupChat,
|
this.onPressCreateGroupChat,
|
||||||
this.onPressCompleteGroupChatCreation,
|
this.onPressCompleteGroupChatCreation,
|
||||||
|
@ -118,6 +119,11 @@ class ChatUserStoryConfiguration {
|
||||||
/// Callback function triggered when user profile is pressed.
|
/// Callback function triggered when user profile is pressed.
|
||||||
final Function(BuildContext context, ChatUserModel user)? onPressUserProfile;
|
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 double? textfieldBottomPadding;
|
||||||
|
|
||||||
final Color? iconDisabledColor;
|
final Color? iconDisabledColor;
|
||||||
|
|
Loading…
Reference in a new issue