createRenderObject method Null safety
- BuildContext context
override
Creates an instance of the RenderObject class that this RenderObjectWidget represents, using the configuration described by this RenderObjectWidget.
This method should not do anything with the children of the render object. That should instead be handled by the method that overrides RenderObjectElement.mount in the object rendered by this object's createElement method. See, for example, SingleChildRenderObjectElement.mount.
Implementation
@override
RenderObject createRenderObject(BuildContext context) {
final AndroidViewController viewController = controller as AndroidViewController;
// Compose using the Android view hierarchy.
// This is useful when embedding a SurfaceView into a Flutter app.
// SurfaceViews cannot be composed using GL textures.
if (viewController is ExpensiveAndroidViewController) {
final PlatformViewRenderBox renderBox =
super.createRenderObject(context) as PlatformViewRenderBox;
viewController.pointTransformer =
(Offset position) => renderBox.globalToLocal(position);
return renderBox;
}
// Use GL texture based composition.
// App should use GL texture unless they require to embed a SurfaceView.
final RenderAndroidView renderBox = RenderAndroidView(
viewController: viewController,
gestureRecognizers: gestureRecognizers,
hitTestBehavior: hitTestBehavior,
);
viewController.pointTransformer =
(Offset position) => renderBox.globalToLocal(position);
return renderBox;
}