Want to test Flutter widgets on different screen sizes? You can specify custom surface size by using WidgetTester. The following code will run a test with a screen size of 42×42.
1 2 3 4 5 6 7 8 9 10 11 12 13 | import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { testWidgets("foo", (tester) async { tester.binding.window.physicalSizeTestValue = Size(42, 42); // resets the screen to its orinal size after the test end addTearDown(tester.binding.window.clearPhysicalSizeTestValue); // TODO: do something }); } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.