Simplify SafeArea test for maintainBottomViewPadding to ensure maintainBottomViewPadding is always respected (#97646)
This commit is contained in:
@@ -71,10 +71,9 @@ class SafeArea extends StatelessWidget {
|
||||
/// The greater of the minimum insets and the media padding will be applied.
|
||||
final EdgeInsets minimum;
|
||||
|
||||
/// Specifies whether the [SafeArea] should maintain the
|
||||
/// [MediaQueryData.viewPadding] instead of the [MediaQueryData.padding] when
|
||||
/// consumed by the [MediaQueryData.viewInsets] of the current context's
|
||||
/// [MediaQuery], defaults to false.
|
||||
/// Specifies whether the [SafeArea] should maintain the bottom
|
||||
/// [MediaQueryData.viewPadding] instead of the bottom [MediaQueryData.padding],
|
||||
/// defaults to false.
|
||||
///
|
||||
/// For example, if there is an onscreen keyboard displayed above the
|
||||
/// SafeArea, the padding can be maintained below the obstruction rather than
|
||||
@@ -98,7 +97,7 @@ class SafeArea extends StatelessWidget {
|
||||
final MediaQueryData data = MediaQuery.of(context);
|
||||
EdgeInsets padding = data.padding;
|
||||
// Bottom padding has been consumed - i.e. by the keyboard
|
||||
if (data.padding.bottom == 0.0 && data.viewInsets.bottom != 0.0 && maintainBottomViewPadding)
|
||||
if (maintainBottomViewPadding)
|
||||
padding = padding.copyWith(bottom: data.viewPadding.bottom);
|
||||
|
||||
return Padding(
|
||||
|
||||
@@ -147,6 +147,39 @@ void main() {
|
||||
expect(initialPoint, finalPoint);
|
||||
});
|
||||
|
||||
testWidgets('SafeArea alone - partial ViewInsets consume Padding', (WidgetTester tester) async {
|
||||
final Widget child = boilerplate(SafeArea(
|
||||
maintainBottomViewPadding: true,
|
||||
child: Column(
|
||||
children: const <Widget>[
|
||||
Expanded(child: Placeholder()),
|
||||
],
|
||||
),
|
||||
));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
viewPadding: EdgeInsets.only(bottom: 20.0),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
final Offset initialPoint = tester.getCenter(find.byType(Placeholder));
|
||||
// Consume bottom padding - as if by the keyboard opening
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
viewPadding: EdgeInsets.only(bottom: 20.0),
|
||||
viewInsets: EdgeInsets.only(bottom: 10.0),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
final Offset finalPoint = tester.getCenter(find.byType(Placeholder));
|
||||
expect(initialPoint, finalPoint);
|
||||
});
|
||||
|
||||
testWidgets('SafeArea with nested Scaffold', (WidgetTester tester) async {
|
||||
final Widget child = boilerplate(SafeArea(
|
||||
maintainBottomViewPadding: true,
|
||||
@@ -184,6 +217,42 @@ void main() {
|
||||
final Offset finalPoint = tester.getCenter(find.byType(Placeholder));
|
||||
expect(initialPoint, finalPoint);
|
||||
});
|
||||
|
||||
testWidgets('SafeArea with nested Scaffold - partial ViewInsets consume Padding', (WidgetTester tester) async {
|
||||
final Widget child = boilerplate(SafeArea(
|
||||
maintainBottomViewPadding: true,
|
||||
child: Scaffold(
|
||||
resizeToAvoidBottomInset: false,
|
||||
body: Column(
|
||||
children: const <Widget>[
|
||||
Expanded(child: Placeholder()),
|
||||
],
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
viewPadding: EdgeInsets.only(bottom: 20.0),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
final Offset initialPoint = tester.getCenter(find.byType(Placeholder));
|
||||
// Consume bottom padding - as if by the keyboard opening
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(
|
||||
viewPadding: EdgeInsets.only(bottom: 20.0),
|
||||
viewInsets: EdgeInsets.only(bottom: 10.0),
|
||||
),
|
||||
child: child,
|
||||
),
|
||||
);
|
||||
final Offset finalPoint = tester.getCenter(find.byType(Placeholder));
|
||||
expect(initialPoint, finalPoint);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user