How to test Flutter widgets on different screen sizes?

后端 未结 5 2007
长情又很酷
长情又很酷 2020-11-29 09:09

I have a Flutter widget which shows extra data depending on the screen size. Does anyone know a way of testing this widget on multiple different screen sizes?

I\'ve

5条回答
  •  眼角桃花
    2020-11-29 09:56

    You can specify custom surface size by using WidgetTester

    The following code will run a test with a screen size of 42x42

    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
      });
    }
    

提交回复
热议问题