Skip to content

Commit 99c15db

Browse files
fix: add back button to chatOverviewScreen when onExit is not null
1 parent 33d790b commit 99c15db

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## 6.0.1
22
- Added proper implementation for getAllUsersForChat in Firebase repository
33
- Removed cast which throws an error in ChatProfileScreen
4+
- Added BackButton to ChatOverviewScreen when onExit is not null
45

56
## 6.0.0
67
- Added pending message repository to temporarily store messages that are not yet received by the backend

packages/flutter_chat/lib/src/flutter_chat_navigator_userstories.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ abstract class _BaseChatNavigatorUserstory extends HookWidget {
7878
final ChatOptions options;
7979

8080
/// Callback for when the user wants to navigate back.
81+
///
82+
/// This will also show the back button in the appbar when not null
8183
final VoidCallback? onExit;
8284

8385
/// Implemented by subclasses to provide the initial route of the userstory.
@@ -108,7 +110,7 @@ abstract class _BaseChatNavigatorUserstory extends HookWidget {
108110
service: service,
109111
popHandler: popHandler,
110112
child: NavigatorPopHandler(
111-
onPop: () => popHandler.handlePop(),
113+
onPop: popHandler.handlePop,
112114
child: Navigator(
113115
key: nestedNavigatorKey,
114116
onGenerateInitialRoutes: (_, __) => [

packages/flutter_chat/lib/src/screens/chat_screen.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class ChatScreen extends HookWidget {
4646

4747
if (options.builders.baseScreenBuilder == null) {
4848
return Scaffold(
49-
appBar: const _AppBar(),
49+
appBar: _AppBar(onExit),
5050
body: _Body(
5151
onPressChat: onPressChat,
5252
onPressStartChat: onPressStartChat,
@@ -58,7 +58,7 @@ class ChatScreen extends HookWidget {
5858
return options.builders.baseScreenBuilder!.call(
5959
context,
6060
mapScreenType,
61-
const _AppBar(),
61+
_AppBar(onExit),
6262
translations.chatsTitle,
6363
_Body(
6464
onPressChat: onPressChat,
@@ -70,7 +70,9 @@ class ChatScreen extends HookWidget {
7070
}
7171

7272
class _AppBar extends StatelessWidget implements PreferredSizeWidget {
73-
const _AppBar();
73+
const _AppBar(this.onExit);
74+
75+
final VoidCallback? onExit;
7476

7577
@override
7678
Widget build(BuildContext context) {
@@ -81,6 +83,11 @@ class _AppBar extends StatelessWidget implements PreferredSizeWidget {
8183
var theme = Theme.of(context);
8284

8385
return AppBar(
86+
leading: onExit != null
87+
? BackButton(
88+
onPressed: () => onExit?.call(),
89+
)
90+
: null,
8491
title: Text(
8592
translations.chatsTitle,
8693
),

0 commit comments

Comments
 (0)