Skip to content

Would like an example of testing for Landscape in a widget test #10307

Closed

Description

@eseidelGoogle

@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.

Activity

  1. added this to the milestone on May 25, 2017
  2. Hixie commented on May 25, 2017

    @Hixie
    Contributor

    In practice all tests are landscape. :-)

  3. eseidelGoogle commented on May 25, 2017

    @eseidelGoogle
    ContributorAuthor

    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).

  4. Hixie commented on May 25, 2017

    @Hixie
    Contributor

    Indeed. Where's a good place to put this information? API docs? Where?

  5. eseidelGoogle commented on May 25, 2017

    @eseidelGoogle
    ContributorAuthor
  6. self-assigned this
    on Jun 13, 2017
  7. removed
    d: api docsIssues with https://api.flutter.dev/
    on Jun 13, 2017
  8. removed their assignment
    on Jun 13, 2017
  9. zoechi commented on Dec 11, 2018

    @zoechi
    Contributor
  10. zoechi commented on Dec 11, 2018

    @zoechi
    Contributor

    Issue moved to flutter/website #2005 via ZenHub

  11. eggenstein commented on Mar 27, 2019

    @eggenstein

    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 landscape
    
  12. github-actions commented on Aug 15, 2021

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  13. locked as resolved and limited conversation to collaborators on Aug 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions