本文介绍了如何在不同屏幕尺寸上测试Flutter小部件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Flutter小部件,它根据屏幕尺寸显示额外的数据.有谁知道在多种不同屏幕尺寸上测试此小部件的方法吗?
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?
我已经看过 widget_tester 源代码,但找不到任何内容.
I've had a look through the widget_tester source code but can't find anything.
推荐答案
您可以使用 WidgetTester
以下代码将运行屏幕尺寸为42x42的测试
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
});
}
这篇关于如何在不同屏幕尺寸上测试Flutter小部件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!