Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test Flutter widgets on different screen sizes?

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 had a look through the widget_tester source code but can't find anything.

like image 381
Jordan Davies Avatar asked Dec 10 '18 13:12

Jordan Davies


People also ask

How do you test apps on flutter?

You need two pieces of software to complete this lab: the Flutter SDK, and an editor. You can run this codelab using any of the following devices: A physical device (Android or iOS) connected to your computer and set to developer mode.


1 Answers

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 original size after the test end     addTearDown(tester.binding.window.clearPhysicalSizeTestValue);      // TODO: do something   }); } 
like image 76
Rémi Rousselet Avatar answered Sep 27 '22 23:09

Rémi Rousselet