Skip to content

Commit ef58571

Browse files
committed
feat(chat): close reply bar when reply success
Closes #207
1 parent a9cfc1b commit ef58571

File tree

3 files changed

+15
-23
lines changed

3 files changed

+15
-23
lines changed

lib/features/chat/view/chat_history_page.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:easy_refresh/easy_refresh.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
4+
import 'package:go_router/go_router.dart';
45
import 'package:tsdm_client/constants/layout.dart';
56
import 'package:tsdm_client/extensions/build_context.dart';
67
import 'package:tsdm_client/features/chat/bloc/chat_history_bloc.dart';
@@ -127,9 +128,13 @@ final class _ChatHistoryPageState extends State<ChatHistoryPage> {
127128
listenWhen: (prev, curr) => prev.status != curr.status,
128129
listener: (context, state) {
129130
if (state.status == ReplyStatus.success) {
130-
showSnackBar(context: context, message: tr.success, avoidKeyboard: true);
131+
showSnackBar(context: context, message: tr.success);
132+
// Close the reply bar when sent success.
133+
if (_replyBarController.showingEditor) {
134+
context.pop();
135+
}
131136
} else if (state.status == ReplyStatus.failure && state.failedReason != null) {
132-
showSnackBar(context: context, message: tr.failed(message: state.failedReason!), avoidKeyboard: true);
137+
showSnackBar(context: context, message: tr.failed(message: state.failedReason!));
133138
}
134139
},
135140
),

lib/features/chat/view/chat_page.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:easy_refresh/easy_refresh.dart';
22
import 'package:flutter/material.dart';
33
import 'package:flutter_bloc/flutter_bloc.dart';
4+
import 'package:go_router/go_router.dart';
45
import 'package:tsdm_client/constants/layout.dart';
56
import 'package:tsdm_client/extensions/build_context.dart';
67
import 'package:tsdm_client/features/chat/bloc/chat_bloc.dart';
@@ -126,9 +127,13 @@ final class _ChatPageState extends State<ChatPage> {
126127
listenWhen: (prev, curr) => prev.status != curr.status,
127128
listener: (context, state) {
128129
if (state.status == ReplyStatus.success) {
129-
showSnackBar(context: context, message: tr.success, avoidKeyboard: true);
130+
showSnackBar(context: context, message: tr.success);
131+
// Close the reply bar when sent success.
132+
if (_replyBarController.showingEditor) {
133+
context.pop();
134+
}
130135
} else if (state.status == ReplyStatus.failure && state.failedReason != null) {
131-
showSnackBar(context: context, message: tr.failed(message: state.failedReason!), avoidKeyboard: true);
136+
showSnackBar(context: context, message: tr.failed(message: state.failedReason!));
132137
}
133138
},
134139
),

lib/utils/show_toast.dart

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,13 @@ void showFailedToLoadSnackBar(BuildContext context, {bool floating = true}) {
1616
}
1717

1818
/// Show a snack bar with given [message].
19-
///
20-
/// Set [avoidKeyboard] to true if want to act like resizeToAvoidBottomInset
21-
/// which is useful in places where the snack bar is covered by keyboard such as
22-
/// chat_bottom_container.
2319
void showSnackBar({
2420
required BuildContext context,
2521
required String message,
2622
bool floating = true,
2723
SnackBarAction? action,
28-
bool avoidKeyboard = false,
2924
}) {
3025
ScaffoldMessenger.of(context).showSnackBar(
31-
SnackBar(
32-
behavior: floating ? SnackBarBehavior.floating : null,
33-
content: Text(message),
34-
action: action,
35-
margin:
36-
avoidKeyboard
37-
// Merge a default edge insets of (15, 5, 15, 10) in LTRB, it is the
38-
// default insets padding of M3 snack bar theme that can be found in
39-
// snack_bar.dart in flutter source code.
40-
// Make a copy instead of referencing it because it's internal in pkg
41-
// and also generated code.
42-
? EdgeInsets.fromLTRB(15, 5, 15, 10 + MediaQuery.viewInsetsOf(context).bottom)
43-
: null,
44-
),
26+
SnackBar(behavior: floating ? SnackBarBehavior.floating : null, content: Text(message), action: action),
4527
);
4628
}

0 commit comments

Comments
 (0)