Unverified Commit 19d113b0 authored by Justin McCandless's avatar Justin McCandless Committed by GitHub

resizeToAvoidBottomInset Cupertino without NavBar (#37319)

Fix a bug in CupertinoTextField where resizeToAvoidBottomInset didn't work.
parent cdefbef3
......@@ -137,6 +137,16 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
),
);
}
} else {
// If there is no navigation bar, still may need to add padding in order
// to support resizeToAvoidBottomInset.
final double bottomPadding = widget.resizeToAvoidBottomInset
? existingMediaQuery.viewInsets.bottom
: 0.0;
paddedContent = Padding(
padding: EdgeInsets.only(bottom: bottomPadding),
child: paddedContent,
);
}
// The main content being at the bottom is added to the stack first.
......
......@@ -25,7 +25,7 @@ void main() {
expect(tester.getTopLeft(find.byType(Center)), const Offset(0.0, 0.0));
});
testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async {
testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async {
BuildContext childContext;
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
......@@ -434,4 +434,51 @@ testWidgets('Opaque bar pushes contents down', (WidgetTester tester) async {
expect(tester.getTopLeft(find.text('6')).dy, 364);
expect(find.text('12'), findsNothing);
});
testWidgets('resizeToAvoidBottomInset is supported even when no navigationBar', (WidgetTester tester) async {
Widget buildFrame(bool showNavigationBar, bool showKeyboard) {
return CupertinoApp(
home: MediaQuery(
data: MediaQueryData(
padding: EdgeInsets.zero,
viewPadding: const EdgeInsets.only(bottom: 20),
viewInsets: EdgeInsets.only(bottom: showKeyboard ? 300 : 20),
),
child: CupertinoPageScaffold(
resizeToAvoidBottomInset: true,
navigationBar: showNavigationBar ? const CupertinoNavigationBar(
middle: Text('Title'),
) : null,
child: const Center(
child: CupertinoTextField(),
),
),
),
);
}
// When there is a nav bar and no keyboard.
await tester.pumpWidget(buildFrame(true, false));
final Offset positionNoInsetWithNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
// When there is a nav bar and keyboard, the CupertinoTextField moves up.
await tester.pumpWidget(buildFrame(true, true));
await tester.pumpAndSettle();
final Offset positionWithInsetWithNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
expect(positionWithInsetWithNavBar.dy, lessThan(positionNoInsetWithNavBar.dy));
// When there is no nav bar and no keyboard, the CupertinoTextField is still
// centered.
await tester.pumpWidget(buildFrame(false, false));
final Offset positionNoInsetNoNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
expect(positionNoInsetNoNavBar, equals(positionNoInsetWithNavBar));
// When there is a keyboard but no nav bar, the CupertinoTextField also
// moves up to the same position as when there is a keyboard and nav bar.
await tester.pumpWidget(buildFrame(false, true));
await tester.pumpAndSettle();
final Offset positionWithInsetNoNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
expect(positionWithInsetNoNavBar.dy, lessThan(positionNoInsetNoNavBar.dy));
expect(positionWithInsetNoNavBar, equals(positionWithInsetWithNavBar));
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment