mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Fix CupertinoPageScaffold resizeToAvoidBottomInset (#142776)
Need to create a `MediaQuery` to expose the fact that the `viewInsets` have been consumed. Fixes #142775
This commit is contained in:
parent
83aca58fa7
commit
1aa6ff5614
@ -151,15 +151,17 @@ class _CupertinoPageScaffoldState extends State<CupertinoPageScaffold> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (widget.resizeToAvoidBottomInset) {
|
||||||
// If there is no navigation bar, still may need to add padding in order
|
// If there is no navigation bar, still may need to add padding in order
|
||||||
// to support resizeToAvoidBottomInset.
|
// to support resizeToAvoidBottomInset.
|
||||||
final double bottomPadding = widget.resizeToAvoidBottomInset
|
paddedContent = MediaQuery(
|
||||||
? existingMediaQuery.viewInsets.bottom
|
data: existingMediaQuery.copyWith(
|
||||||
: 0.0;
|
viewInsets: existingMediaQuery.viewInsets.copyWith(bottom: 0)
|
||||||
paddedContent = Padding(
|
),
|
||||||
padding: EdgeInsets.only(bottom: bottomPadding),
|
child: Padding(
|
||||||
child: paddedContent,
|
padding: EdgeInsets.only(bottom: existingMediaQuery.viewInsets.bottom),
|
||||||
|
child: paddedContent,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -495,29 +495,39 @@ void main() {
|
|||||||
navigationBar: showNavigationBar ? const CupertinoNavigationBar(
|
navigationBar: showNavigationBar ? const CupertinoNavigationBar(
|
||||||
middle: Text('Title'),
|
middle: Text('Title'),
|
||||||
) : null,
|
) : null,
|
||||||
child: const Center(
|
child: Builder(
|
||||||
child: CupertinoTextField(),
|
builder: (BuildContext context) => Center(
|
||||||
|
child: CupertinoTextField(
|
||||||
|
placeholder: MediaQuery.viewInsetsOf(context).toString(),
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CupertinoPageScaffold should consume the viewInsets in all cases
|
||||||
|
final String expectedViewInsets = EdgeInsets.zero.toString();
|
||||||
|
|
||||||
// When there is a nav bar and no keyboard.
|
// When there is a nav bar and no keyboard.
|
||||||
await tester.pumpWidget(buildFrame(true, false));
|
await tester.pumpWidget(buildFrame(true, false));
|
||||||
final Offset positionNoInsetWithNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
final Offset positionNoInsetWithNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
||||||
|
expect((find.byType(CupertinoTextField).evaluate().first.widget as CupertinoTextField).placeholder, expectedViewInsets);
|
||||||
|
|
||||||
// When there is a nav bar and keyboard, the CupertinoTextField moves up.
|
// When there is a nav bar and keyboard, the CupertinoTextField moves up.
|
||||||
await tester.pumpWidget(buildFrame(true, true));
|
await tester.pumpWidget(buildFrame(true, true));
|
||||||
await tester.pumpAndSettle();
|
await tester.pumpAndSettle();
|
||||||
final Offset positionWithInsetWithNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
final Offset positionWithInsetWithNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
||||||
expect(positionWithInsetWithNavBar.dy, lessThan(positionNoInsetWithNavBar.dy));
|
expect(positionWithInsetWithNavBar.dy, lessThan(positionNoInsetWithNavBar.dy));
|
||||||
|
expect((find.byType(CupertinoTextField).evaluate().first.widget as CupertinoTextField).placeholder, expectedViewInsets);
|
||||||
|
|
||||||
// When there is no nav bar and no keyboard, the CupertinoTextField is still
|
// When there is no nav bar and no keyboard, the CupertinoTextField is still
|
||||||
// centered.
|
// centered.
|
||||||
await tester.pumpWidget(buildFrame(false, false));
|
await tester.pumpWidget(buildFrame(false, false));
|
||||||
final Offset positionNoInsetNoNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
final Offset positionNoInsetNoNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
||||||
expect(positionNoInsetNoNavBar, equals(positionNoInsetWithNavBar));
|
expect(positionNoInsetNoNavBar, equals(positionNoInsetWithNavBar));
|
||||||
|
expect((find.byType(CupertinoTextField).evaluate().first.widget as CupertinoTextField).placeholder, expectedViewInsets);
|
||||||
|
|
||||||
// When there is a keyboard but no nav bar, the CupertinoTextField also
|
// 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.
|
// moves up to the same position as when there is a keyboard and nav bar.
|
||||||
@ -526,6 +536,7 @@ void main() {
|
|||||||
final Offset positionWithInsetNoNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
final Offset positionWithInsetNoNavBar = tester.getTopLeft(find.byType(CupertinoTextField));
|
||||||
expect(positionWithInsetNoNavBar.dy, lessThan(positionNoInsetNoNavBar.dy));
|
expect(positionWithInsetNoNavBar.dy, lessThan(positionNoInsetNoNavBar.dy));
|
||||||
expect(positionWithInsetNoNavBar, equals(positionWithInsetWithNavBar));
|
expect(positionWithInsetNoNavBar, equals(positionWithInsetWithNavBar));
|
||||||
|
expect((find.byType(CupertinoTextField).evaluate().first.widget as CupertinoTextField).placeholder, expectedViewInsets);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('textScaleFactor is set to 1.0', (WidgetTester tester) async {
|
testWidgets('textScaleFactor is set to 1.0', (WidgetTester tester) async {
|
||||||
|
Loading…
Reference in New Issue
Block a user