Skip to content

Commit bfcc2bb

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 adeebbb commit bfcc2bb

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

lib/widgets/message_list.dart

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

0 commit comments

Comments
 (0)