createViewConfigurationFor method
- RenderView renderView
override
Returns a ViewConfiguration configured for the provided RenderView based on the current environment.
This is called during addRenderView and also in response to changes to the system metrics to update all renderViews added to the binding.
Bindings can override this method to change what size or device pixel
ratio the RenderView will use. For example, the testing framework uses
this to force the display into 800x600 when a test is run on the device
using flutter run
.
Implementation
@override
ViewConfiguration createViewConfigurationFor(RenderView renderView) {
if (_insideAddRenderView
&& renderView.hasConfiguration
&& renderView.configuration is TestViewConfiguration
&& renderView == this.renderView) {
// If a test has reached out to the now deprecated renderView property to set a custom TestViewConfiguration
// we are not replacing it. This is to maintain backwards compatibility with how things worked prior to the
// deprecation of that property.
// TODO(goderbauer): Remove this "if" when the deprecated renderView property is removed.
return renderView.configuration;
}
final FlutterView view = renderView.flutterView;
if (_surfaceSize != null && view == platformDispatcher.implicitView) {
final BoxConstraints constraints = BoxConstraints.tight(_surfaceSize!);
return ViewConfiguration(
logicalConstraints: constraints,
physicalConstraints: constraints * view.devicePixelRatio,
devicePixelRatio: view.devicePixelRatio,
);
}
return super.createViewConfigurationFor(renderView);
}