Repository navigation
Add an example to test Landscape orientation in a widget test #2005
Copy link
Copy link
Closed
Labels
e1-hoursEffort: < 8 hrsEffort: < 8 hrsfix.examplesAdds or changes exampleAdds or changes examplep2-mediumNecessary but not urgent concern. Resolve when possible.Necessary but not urgent concern. Resolve when possible.t.ui.generalRelates to general Flutter app UI topicsRelates to general Flutter app UI topicstest.generalRelates to unit, integration, perf testingRelates to unit, integration, perf testingtest.widgetRelates to widget testingRelates to widget testing
Description
Activity
We have this, but could still use the info in the testing doc.
- addede1-hoursEffort: < 8 hrsEffort: < 8 hrsp1-highMajor but not urgent concern: Resolve in months. Update each month.Major but not urgent concern: Resolve in months. Update each month.
on Jan 29, 2019 Orientation in testing is entirely different. See for example the last 2 links in the initial comment.
There is no easy to find way how to specify screen dimension/orientation for tests.There is no easy to find way how to specify screen dimension/orientation for tests.
This works just fine for me:
const double PORTRAIT_WIDTH = 400.0; const double PORTRAIT_HEIGHT = 800.0; const double LANDSCAPE_WIDTH = PORTRAIT_HEIGHT; const double LANDSCAPE_HEIGHT = PORTRAIT_WIDTH; final TestWidgetsFlutterBinding binding = TestWidgetsFlutterBinding.ensureInitialized(); await binding.setSurfaceSize(Size(PORTRAIT_WIDTH, PORTRAIT_HEIGHT)); await tester.pumpWidget(MyWidget()); // test in portrait await binding.setSurfaceSize(Size(LANDSCAPE_WIDTH, LANDSCAPE_HEIGHT)); await tester.pumpAndSettle(); // OrientationBuilder gets triggered // test in landscapeReacted by Ioana Alexandru- addedtest.generalRelates to unit, integration, perf testingRelates to unit, integration, perf testingfix.examplesAdds or changes exampleAdds or changes example
on May 30, 2023 - changed the title
[-]Would like an example of testing for Landscape in a widget test[/-][+]Add an example to test Landscape orientation in a widget test[/+]on Jun 2, 2023 - addedt.ui.generalRelates to general Flutter app UI topicsRelates to general Flutter app UI topicsp2-mediumNecessary but not urgent concern. Resolve when possible.Necessary but not urgent concern. Resolve when possible.test.widgetRelates to widget testingRelates to widget testingand removedp1-highMajor but not urgent concern: Resolve in months. Update each month.Major but not urgent concern: Resolve in months. Update each month.
on Jun 2, 2023 - added a commit that references this issue
on Feb 3, 2025
Metadata
Metadata
Assignees
Labels
e1-hoursEffort: < 8 hrsEffort: < 8 hrsfix.examplesAdds or changes exampleAdds or changes examplep2-mediumNecessary but not urgent concern. Resolve when possible.Necessary but not urgent concern. Resolve when possible.t.ui.generalRelates to general Flutter app UI topicsRelates to general Flutter app UI topicstest.generalRelates to unit, integration, perf testingRelates to unit, integration, perf testingtest.widgetRelates to widget testingRelates to widget testing
@eseidelGoogle commented on Thu May 25 2017
@sethladd asked me how difficult it was to test landscape layouts in tests. I suspect it's straightforward to do, but I'm not aware of an example to give.
@Hixie commented on Thu May 25 2017
In practice all tests are landscape. :-)
@eseidelGoogle commented on Thu May 25 2017
It seems like we will want to explain to individuals in flutter.io/testing how to test landscape vs. portrait for their widgets (as well as layouts at different sizes). For our own widgets, coverage will tell us if we're testing the landscape vs. portrait configurations of course. e.g. https://coveralls.io/builds/11679479/source?filename=lib%2Fsrc%2Fmaterial%2Fdate_picker.dart#L101 (I'm not actually sure if that's telling me the portrait code is covered or not).
@Hixie commented on Thu May 25 2017
Indeed. Where's a good place to put this information? API docs? Where?
@eseidelGoogle commented on Thu May 25 2017
Presumably https://flutter.io/testing?
@zoechi commented on Wed Jun 27 2018
Related SO question https://stackoverflow.com/questions/50158364/in-flutter-widget-testing-how-to-make-media-orientation-to-portrait
@zoechi commented on Tue Dec 11 2018
Probably a better way (not tested, wasn't aware of that before) https://stackoverflow.com/questions/53706569/how-to-test-flutter-widgets-on-different-screen-sizes