Skip to content

Conversation

@SPodjasek
Copy link
Contributor

Currently CupertinoPageScaffold doesn't use viewInsets to pad content as Material Scaffold does.

You can see actual master behavior below and fixed version next to it.

master fix
broken fixed

Repository for above PoC app: https://github.com/SPodjasek/flutter_scaffold_poc

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

Thanks for your addition. Please also add a test for this in test/cupertino/scaffold_test.dart. A mock MediaQuery with a viewInsets can be added above the scaffold.

data: existingMediaQuery.copyWith(
padding: existingMediaQuery.padding.copyWith(
top: topPadding,
bottom: bottomPadding,
Copy link
Member

Choose a reason for hiding this comment

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

Ah my apologies, I misread your previous code. You weren't adding the MediaQuery.padding.bottom as padding, you were just propagating it down. That was correct.

This should just be existingMediaQuery.padding.bottom + bottomPadding as you had it before.

@SPodjasek
Copy link
Contributor Author

I had to wrap CupertinoPageScaffold.child with SafeArea for tests to work as expected, and looking at the way it's done in Material there should be some Layout included in Scaffold.

@SPodjasek SPodjasek changed the title [WIP] Implement resizeToAvoidBottomPadding in CupertinoPageScaffold Implement resizeToAvoidBottomPadding in CupertinoPageScaffold Aug 24, 2018
Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

Thanks for making the changes. I see what's happening with the tests. A few more comments. Please bear with me.

@required this.child,
}) : assert(child != null),
super(key: key);
}) : assert(child != null),
Copy link
Member

Choose a reason for hiding this comment

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

Leave as before. There's 2 spaces now

/// prevents widgets inside the body from being obscured by the keyboard.
///
/// Defaults to true.
final bool resizeToAvoidBottomPadding;
Copy link
Member

Choose a reason for hiding this comment

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

Actually this is a good opportunity to make sure the API naming is current. Unfortunately the Material scaffold's name was created before we distinguished between full 'insets' where the usable view area shrinks due to things like keyboard and 'paddings' where it's obstructions from things like the home bar and notch etc.

Let's name this resizeToAvoidBottomInset

/// By default uses [CupertinoColors.white] color.
final Color backgroundColor;

/// Whether the [child] should size itself to avoid the window's bottom padding.
Copy link
Member

Choose a reason for hiding this comment

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

window's bottom inset.


// Propagate bottom padding and include viewInsets if appropriate
final double bottomPadding = resizeToAvoidBottomPadding
? existingMediaQuery.viewInsets.bottom
Copy link
Member

Choose a reason for hiding this comment

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

just 4 spaces

data: existingMediaQuery.copyWith(
padding: existingMediaQuery.padding.copyWith(
top: topPadding,
bottom: existingMediaQuery.padding.bottom + bottomPadding,
Copy link
Member

Choose a reason for hiding this comment

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

Reading this a bit more carefully, I see what's happening in the tests. Instead of converting MediaQuery insets into MediaQuery paddings, we want to directly apply the insets to the contents.

In other words, leave the MediaQuery part as is but wrap that whole thing with a Padding with a bottom padding from the inset. This matches the Material scaffold's behavior more and you can remove the SafeAreas in the test.

Copy link
Member

@xster xster left a comment

Choose a reason for hiding this comment

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

Cool, thanks for the changes! I'll merge it in when the build tree is green

),
),
child: child,
child: Padding(
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, the linter doesn't currently pop a warning for these but we're still using Dart1 syntax for the time being. new Padding here.

this.backgroundColor = CupertinoColors.white,
this.resizeToAvoidBottomInset = true,
@required this.child,
}) : assert(child != null),
Copy link
Member

Choose a reason for hiding this comment

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

assert that resizeToAvoidBottomInset is not null like child here

@xster xster merged commit f8a2fc7 into flutter:master Aug 27, 2018
@SPodjasek SPodjasek deleted the cupertino_scaffold_viewinsets branch August 27, 2018 19:59
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants