setSurfaceSize method
- Size? size
Artificially changes the surface size to size
on the Widget binding,
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));
See also TestFlutterView.physicalSize, which has a similar effect.
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();
});
}