1

According to the answers here, I tried this in my test:

      import 'dart:ui' as ui;

      testWidgets('test', (tester) async{
          // setup the physical size
          tester.binding.window.physicalSizeTestValue = const Size(1366.0, 673.0);
          tester.binding.window.devicePixelRatioTestValue = 1.0;
    
          // reset the edited settings after the test ends
          addTearDown(tester.binding.window.clearPhysicalSizeTestValue);
          addTearDown(tester.binding.window.clearDevicePixelRatioTestValue);
    
          //////////// For debugging
          var physicalSize = ui. window.physicalSize; // debugger shows Size(2400.0, 1800.0)
          var pixelRatio = ui.window.devicePixelRatio; // debugger shows 3.0
          ///////////

          await tester.runAsync(() async {
            ... // code that depends on the screen size (window.size and window.devicePixelRatio)
          });

          ...
        });

Why is the physicalSize and pixelRatio not changing?

HII
  • 3,420
  • 1
  • 14
  • 35

0 Answers0