Skip to content

Commit 68acee8

Browse files
committed
compose: Show a progress bar when sending message
This progress bar shifts the message list because it increases the height of the compose box. This is undesirable, but a fix can be implemented in the future. Signed-off-by: Zixuan James Li <[email protected]>
1 parent 010212f commit 68acee8

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

lib/widgets/compose_box.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@ abstract class _ComposeBoxBody extends StatelessWidget {
11251125
@override
11261126
Widget build(BuildContext context) {
11271127
final themeData = Theme.of(context);
1128+
final designVariables = DesignVariables.of(context);
11281129

11291130
final inputThemeData = themeData.copyWith(
11301131
inputDecorationTheme: const InputDecorationTheme(
@@ -1141,6 +1142,16 @@ abstract class _ComposeBoxBody extends StatelessWidget {
11411142

11421143
final topicInput = buildTopicInput();
11431144
return Column(children: [
1145+
ValueListenableBuilder(
1146+
valueListenable: controller._enabled,
1147+
builder: (context, enabled, child) {
1148+
return (!enabled) ? child! : const SizedBox.shrink();
1149+
},
1150+
child: LinearProgressIndicator(
1151+
minHeight: 2.0,
1152+
backgroundColor: designVariables.foreground.withFadedAlpha(0.2),
1153+
color: designVariables.foreground.withFadedAlpha(0.5),
1154+
)),
11441155
Padding(
11451156
padding: const EdgeInsets.symmetric(horizontal: 8),
11461157
child: Theme(

test/widgets/compose_box_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,19 @@ void main() {
467467
check(controller!.content.text).equals(oldText);
468468
});
469469

470+
testWidgets('show progress bar while pending', (tester) async {
471+
await setupAndTapSend(tester, prepareResponse: (int messageId) {
472+
connection.prepare(json: SendMessageResult(
473+
id: messageId).toJson(), delay: const Duration(seconds: 2));
474+
});
475+
check(controller!.enabled).isFalse();
476+
check(find.byType(LinearProgressIndicator)).findsOne();
477+
478+
await tester.pump(const Duration(seconds: 2));
479+
check(controller!.enabled).isTrue();
480+
check(find.byType(LinearProgressIndicator)).findsNothing();
481+
});
482+
470483
testWidgets('ZulipApiException', (tester) async {
471484
await setupAndTapSend(tester, prepareResponse: (message) {
472485
connection.prepare(

test/widgets/message_list_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import '../api/fake_api.dart';
2929
import '../example_data.dart' as eg;
3030
import '../model/binding.dart';
3131
import '../model/content_test.dart';
32+
import '../model/message_list_test.dart';
3233
import '../model/test_store.dart';
3334
import '../flutter_checks.dart';
3435
import '../stdlib_checks.dart';
@@ -680,10 +681,16 @@ void main() {
680681
..decoration.isNotNull().hintText.equals('Message #${otherChannel.name} > new topic')
681682
..controller.isNotNull().text.equals('Some text');
682683

684+
connection.takeRequests();
683685
connection.prepare(json: SendMessageResult(id: 1).toJson());
686+
// Prepare for the progress indicator that shifts the message list
687+
// and triggers a message fetch as soon as we send the message.
688+
connection.prepare(json: olderResult(
689+
anchor: message.id, foundOldest: true, messages: []).toJson());
684690
await tester.tap(find.byIcon(ZulipIcons.send));
685691
await tester.pump();
686-
check(connection.lastRequest).isA<http.Request>()
692+
final requests = connection.takeRequests();
693+
check(requests.first).isA<http.Request>()
687694
..method.equals('POST')
688695
..url.path.equals('/api/v1/messages')
689696
..bodyFields.deepEquals({

0 commit comments

Comments
 (0)