safeAreaTestValue property

set safeAreaTestValue (EdgeInsets safeArea)

Sets the view's padding and viewPadding to the same safe area, as a device with the keyboard down reports them.

safeArea specifies the safe area insets for all 4 edges that you wish to simulate, in physical pixels like FakeViewPadding.

Example

testWidgets('Test with safe area', (tester) async {
  tester.view.safeAreaTestValue = const EdgeInsets.all(10);
  await tester.pumpWidget(const TestApp());
  expect(find.text('Hello, World!'), findsOneWidget);
});

Implementation

set safeAreaTestValue(EdgeInsets safeArea) {
  final inset = FakeViewPadding(
    bottom: safeArea.bottom,
    left: safeArea.left,
    right: safeArea.right,
    top: safeArea.top,
  );
  padding = inset;
  // With the keyboard down a real device reports the same inset as
  // viewPadding. Setting only `padding` left viewPadding at zero, so widgets
  // that read it laid out as if there were no notch or home indicator.
  viewPadding = inset;
}