Skip to content

Add extendBody parameter to Scaffold, body MediaQuery reflects BAB height - #27973

Merged
HansMuller merged 4 commits into
flutter:masterfrom
HansMuller:scaffold_extend_body
Feb 15, 2019
Merged

HansMuller merged 4 commits into
flutter:masterfrom
HansMuller:scaffold_extend_body

Conversation

@HansMuller

@HansMuller HansMuller commented Feb 15, 2019 •

Copy link
Copy Markdown
Contributor

Fixes #17555

This PR is based on #25654 which was contributed by @IKatsuba.

If Scaffold.extendedBody is true then the Scaffold's body extends to the bottom of the Scaffold, instead of only extending to the top of Scaffold.bottomNavigationBar. This ensures that the scaffold's body will appear behind a non-rectangular or sem-transparent bottom navigation bar of behind the Scaffold's persistentFooterButtons.

Scaffold.extendedBody is false by default.

This change corrects a long standing problem with "notched" bottom navigation bars.

Before

before

After

...
Scaffold(extendBody: true, ...)
...

after

If Scaffold.extendedBody is true and the bottom navigation bar is specified then a MediaQuery whose bottom padding matches the height of the bottom navigation bar will be added above the scaffold body. Children of the scaffold body that have been enclosed in a SafeArea or that are padded to match the MedaQuery's padding, can still avoid the bottom navigation bar.

Sample App

Here's a complete example that demonstrates how the body's MediaQuery can be used.

screenshot0

There are 25 (0 - 24) textfield items in the list. Scrolling to the end completely exposes the last one because the list's bottom padding matches the MediaQuery:

extendBody: true,
body: Builder(
  builder: (BuildContext context) {
    return ListView(
      padding: MediaQuery.of(context).padding,
      children: List<Widget>.generate(25, (int i) {
        ...
      })
    );
  }
  ...

screenshot1

When the keyboard appears the Scaffold's body is resized (the Scaffold's resizeToAvoidBottomInsets is true by default) and the body's MediaQuery no longer includes bottom padding.

screenshot2

@Hixie

Hixie commented Feb 15, 2019

Copy link
Copy Markdown
Contributor

@HansMuller Let's make sure Igor Katsuba is in the AUTHORS file as part of this.

bool operator ==(dynamic other) {
if (super != other)
return false;
if (other is! _BodyBoxConstraints)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can make this an assert -- the superclass should check the runtimeType is equals.
If the superclass doesn't do that (and uses is instead), then we should change the superclass to check runtimeType.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done that for BoxConstraints. Many of our 'operator ==' overloads use is rather than comparing runtimeType, perhaps we should make convert them all in a separate PR?

);

// extendBody locked when keyboard is open
final bool _extendBody = minInsets.bottom > 0 ? false : widget.extendBody;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if this is really correct in all cases...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of minInsets.bottom is just the media query's value of viewInsets.bottom (unless resizeToAvoidBottomInsets is false). It doesn't guarantee that the keyboard is up however if someone were to configure a MediaQuery that way we'd react the same was as if the keyboard is up.

I think this is OK, albeit complicated: we don't extend the bottom of the body if resizeToAvoidBottomInsets is true (the default) and viewInsets.bottom is non-zero.

@zoechi zoechi added framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages labels Feb 15, 2019
@vAugagneur

Copy link
Copy Markdown

Hi, do you know when it will be release ? in which version of flutter ?
best regards.

@gspencergoog

Copy link
Copy Markdown
Contributor

@vAugagneur, Unfortunately, it just missed the cutoff for the latest stable release. It is currently available in the dev branch. If you want to stay on the stable branch, it will be in the 1.3 release of stable.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 7, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels. p: material_ui material_ui package in flutter/packages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Floating Action Button (FAB) notch margin does not show content of body on scroll

7 participants