Since flutter's testing environment does not contain system status bar like the emulator, I would like to add padding at the top using MediaQuery
.
Here's my testing code:
void main() {
testWidgets('MediaQuery padding test', (WidgetTester tester) async {
const double statusBarHeight = 24.0;
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: const MediaQueryData(
viewInsets: EdgeInsets.only(top: statusBarHeight),
),
child: Scaffold(
appBar: AppBar(
title: const Text('PopupMenu Test'),
),
),
),
),
);
expect(find.byType(AppBar), findsOneWidget);
expect(tester.getTopLeft(find.byType(AppBar)).dy, windowPaddingTop);
});
}
Since I added 24.0
of top padding using MediaQueryData.viewInsets
, I expected the AppBar top left y axis is 24.0
, but the result is zero.
I have also tried testing with viewPadding
instead of viewInsets
, but it has produced the same result.
I want to know the reason why top padding is not applied in my test, and how to solve this problem. I would appreciate any help. Thanks.