Skip to content

Commit 2efb06c

Browse files
committed
msglist [nfc]: Simplify safe-area handling
This addresses Greg's TODO in 88f3b73: // TODO have MessageListPage adjust the MediaQuery so we don't // have to worry about this here Not seeing (experimentally) any more bugs like the one fixed in the previous commit, I'm marking this NFC.
1 parent 41f9a2d commit 2efb06c

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

lib/widgets/app.dart

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,23 @@ class MessageListPage extends StatelessWidget {
150150
return Scaffold(
151151
appBar: AppBar(title: const Text("All messages")),
152152
body: Center(
153-
child: Column(children: const [
154-
Expanded(child: MessageList()),
155-
SizedBox(
153+
child: Column(children: [
154+
MediaQuery.removePadding(
155+
context: context,
156+
157+
// The app bar pads the top inset. (If `context` were for a
158+
// location under Scaffold's `body`, we wouldn't have to
159+
// `removeTop`. Scaffold, which knows about the app bar,
160+
// already applies `removeTop` on `body`:
161+
// https://github.com/flutter/flutter/blob/3.7.0-1.2.pre/packages/flutter/lib/src/material/scaffold.dart#L2778
162+
// )
163+
removeTop: true,
164+
165+
// The compose box pads the bottom inset.
166+
removeBottom: true,
167+
168+
child: const Expanded(child: MessageList())),
169+
const SizedBox(
156170
height: 80,
157171
child: Center(child: Text("(Compose box goes here.)"))),
158172
])));

lib/widgets/message_list.dart

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ class _MessageListState extends State<MessageList> {
6868

6969
// Pad the left and right insets, for small devices in landscape.
7070
child: SafeArea(
71-
// A non-ancestor (the compose box) pads the bottom inset;
72-
// prevent extra padding here.
73-
// TODO have MessageListPage adjust the MediaQuery so we don't
74-
// have to worry about this here
75-
bottom: false,
76-
77-
// A non-ancestor (the app bar) pads the top inset. But no
78-
// need to prevent extra padding with `top: false`, because
79-
// Scaffold, which knows about the app bar, sets `body`'s
80-
// ambient `MediaQueryData.padding` to have `top: 0`:
81-
// https://github.com/flutter/flutter/blob/3.7.0-1.2.pre/packages/flutter/lib/src/material/scaffold.dart#L2778
82-
8371
// Keep some padding when there are no horizontal insets,
8472
// which is usual in portrait mode.
8573
minimum: const EdgeInsets.symmetric(horizontal: 8),
@@ -93,24 +81,6 @@ class _MessageListState extends State<MessageList> {
9381
final length = model!.messages.length;
9482
assert(model!.contents.length == length);
9583
return StickyHeaderListView.builder(
96-
// If the `padding` param is omitted or null, StickyHeaderListView pads
97-
// the content area (the part that moves when you scroll) with
98-
// `MediaQueryData.padding`. It inherits this behavior from
99-
// BoxScrollView:
100-
// https://github.com/flutter/flutter/blob/3.7.0-1.2.pre/packages/flutter/lib/src/widgets/scroll_view.dart#L665-L687
101-
//
102-
// A non-ancestor (the compose box) pads the bottom inset, so the
103-
// ambient `MediaQueryData.padding` might be nonzero. So, prevent double
104-
// padding at the bottom by supplying a `padding` param.
105-
//
106-
// (A non-ancestor, the app bar, pads the top inset, but we don't
107-
// need the remedy of a non-null `padding` for the top because the
108-
// ambient `MediaQueryData.padding` has `top: 0` thanks to Scaffold
109-
// setting that on its `body`, since it knows about the app bar:
110-
// https://github.com/flutter/flutter/blob/3.7.0-1.2.pre/packages/flutter/lib/src/material/scaffold.dart#L2778
111-
// )
112-
padding: const EdgeInsets.all(0),
113-
11484
itemCount: length,
11585
// Setting reverse: true means the scroll starts at the bottom.
11686
// Flipping the indexes (in itemBuilder) means the start/bottom

0 commit comments

Comments
 (0)