setSurfaceSize method
- Size? size
Artificially changes the logical size of WidgetTester.view to the specified size, then flushes microtasks.
Set to null to use the default surface size.
To avoid affecting other tests by leaking state, a test that
uses this method should always reset the surface size to the default.
For example, using addTearDown
:
await binding.setSurfaceSize(someSize);
addTearDown(() => binding.setSurfaceSize(null));
This method only affects the size of the WidgetTester.view. It does not affect the size of any other views. Instead of this method, consider setting TestFlutterView.physicalSize, which works for any view, including WidgetTester.view.
Implementation
// TODO(pdblasi-google): Deprecate this. https://github.com/flutter/flutter/issues/123881
Future<void> setSurfaceSize(Size? size) {
return TestAsyncUtils.guard<void>(() async {
assert(inTest);
if (_surfaceSize == size) {
return;
}
_surfaceSize = size;
handleMetricsChanged();
});
}