Skip to content

Commit d808699

Browse files
gnpricechrisbobbe
andcommitted
msglist: Suppress bottom inset in top sliver, too
Fixes #1523. Chris reported the issue, debugged, and wrote the core of the fix. I added the test, found that the left and right insets reappeared, debugged why, and added removeLeft and removeRight to fix those. Co-authored-by: Chris Bobbe <[email protected]>
1 parent b49ebf1 commit d808699

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/widgets/message_list.dart

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
10691069

10701070
// The top sliver has its child 0 as the item just before the
10711071
// sliver boundary, child 1 as the item before that, and so on.
1072-
final topSliver = SliverStickyHeaderList(
1072+
Widget topSliver = SliverStickyHeaderList(
10731073
headerPlacement: HeaderPlacement.scrollingStart,
10741074
delegate: SliverChildBuilderDelegate(
10751075
// To preserve state across rebuilds for individual [MessageItem]
@@ -1148,6 +1148,15 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
11481148
// TODO(#311) If we have a bottom nav, it will pad the bottom inset,
11491149
// and this can be removed; also remove mention in MessageList dartdoc
11501150
bottomSliver = SliverSafeArea(key: bottomSliver.key, sliver: bottomSliver);
1151+
topSliver = MediaQuery.removePadding(context: context,
1152+
// In the top sliver, forget the bottom inset;
1153+
// we're having the bottom sliver take care of it.
1154+
removeBottom: true,
1155+
// (Also forget the left and right insets; the outer SafeArea, above,
1156+
// does that, but the `context` we're passing to this `removePadding`
1157+
// is from outside that SafeArea, so we need to repeat it.)
1158+
removeLeft: true, removeRight: true,
1159+
child: topSliver);
11511160
}
11521161

11531162
return MessageListScrollView(

test/widgets/message_list_test.dart

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,31 @@ void main() {
405405
});
406406

407407
group('presents message content appropriately', () {
408-
testWidgets('content not asked to consume insets (including bottom), even without compose box', (tester) async {
408+
testWidgets('content not asked to consume insets (including bottom), even without compose box, in top sliver', (tester) async {
409+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/1523
410+
const fakePadding = FakeViewPadding(left: 10, top: 10, right: 10, bottom: 10);
411+
tester.view.viewInsets = fakePadding;
412+
tester.view.padding = fakePadding;
413+
414+
await setupMessageListPage(tester, narrow: const CombinedFeedNarrow(),
415+
messages: [
416+
eg.streamMessage(content: ContentExample.codeBlockPlain.html),
417+
eg.streamMessage(),
418+
]);
419+
420+
// Verify this message list lacks a compose box.
421+
// (The original bug wouldn't reproduce with a compose box present.)
422+
final state = MessageListPage.ancestorOf(tester.element(find.text("verb\natim")));
423+
check(state.composeBoxState).isNull();
424+
// Also verify that the first message is in the top sliver.
425+
check(state.model!.middleMessage).equals(1);
426+
427+
final element = tester.element(find.byType(CodeBlock));
428+
final padding = MediaQuery.of(element).padding;
429+
check(padding).equals(EdgeInsets.zero);
430+
});
431+
432+
testWidgets('content not asked to consume insets (including bottom), even without compose box, in bottom sliver', (tester) async {
409433
// Regression test for: https://github.com/zulip/zulip-flutter/issues/736
410434
const fakePadding = FakeViewPadding(left: 10, top: 10, right: 10, bottom: 10);
411435
tester.view.viewInsets = fakePadding;
@@ -418,6 +442,8 @@ void main() {
418442
// (The original bug wouldn't reproduce with a compose box present.)
419443
final state = MessageListPage.ancestorOf(tester.element(find.text("verb\natim")));
420444
check(state.composeBoxState).isNull();
445+
// Also verify that the message is in the bottom sliver.
446+
check(state.model!.middleMessage).equals(0);
421447

422448
final element = tester.element(find.byType(CodeBlock));
423449
final padding = MediaQuery.of(element).padding;

0 commit comments

Comments
 (0)