Skip to content

Commit e693588

Browse files
committed
msglist: Pad left and right insets
On some small devices in landscape mode, the `maxWidth: 760` constraint doesn't (and isn't meant to) prevent the content from extending into the left and right insets. So, use a SafeArea widget for that. In contrast to the SafeAreaView component from react-native-safe-area-context in the RN app, this SafeArea widget: - knows when an ancestor has declared the given inset(s) consumed (by reading the ambient MediaQueryData.padding), and - declares the given inset(s) consumed (by changing its descendants' ambient MediaQueryData.padding). It's left unaware of non-ancestors that consume insets. It turns out that some insets are consumed by non-ancestors in this case; study how that's done and add a few lines to adapt. See the doc: https://api.flutter.dev/flutter/widgets/SafeArea-class.html The `minimum: 8` should preserve the existing 8px padding in all the places we want it, including: - phones with no notches/etc. - notched phones in portrait mode where the norm is to have no notches/etc. on the left or right.
1 parent 90bba5d commit e693588

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/widgets/message_list.dart

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,22 @@ class _MessageListState extends State<MessageList> {
6666
child: ColoredBox(
6767
color: Colors.white,
6868
child: Center(
69-
child: Padding(
70-
padding: const EdgeInsets.symmetric(horizontal: 8),
69+
// Pad the left and right insets, for small devices in landscape.
70+
child: SafeArea(
71+
// A non-ancestor (the compose box) pads the bottom inset;
72+
// prevent extra padding here.
73+
bottom: false,
74+
75+
// A non-ancestor (the app bar) pads the top inset. But no
76+
// need to prevent extra padding with `top: false`, because
77+
// Scaffold, which knows about the app bar, sets `body`'s
78+
// ambient `MediaQueryData.padding` to have `top: 0`:
79+
// https://github.com/flutter/flutter/blob/3.7.0-1.2.pre/packages/flutter/lib/src/material/scaffold.dart#L2778
80+
81+
// Keep some padding when there are no horizontal insets,
82+
// which is usual in portrait mode.
83+
minimum: const EdgeInsets.symmetric(horizontal: 8),
84+
7185
child: ConstrainedBox(
7286
constraints: const BoxConstraints(maxWidth: 760),
7387
child: _buildListView(context))))));

0 commit comments

Comments
 (0)