buildView method

  1. @override
Widget buildView(
  1. Map<String, dynamic> creationParams,
  2. Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
  3. PlatformViewCreatedCallback onPlatformViewCreated, {
  4. int? viewId,
})
override

This method builds the appropriate platform view where the street view can be rendered. The viewId is passed as a parameter from the framework on the onPlatformViewCreated callback.

Implementation

@override
Widget buildView(
    Map<String, dynamic> creationParams,
    Set<Factory<OneSequenceGestureRecognizer>>? gestureRecognizers,
    PlatformViewCreatedCallback onPlatformViewCreated,
    {int? viewId}) {
  // This is used in the platform side to register the view.
  final String viewType = 'my_street_view';
  if (defaultTargetPlatform == TargetPlatform.android) {
    return PlatformViewLink(
        viewType: viewType,
        surfaceFactory:
            (BuildContext context, PlatformViewController controller) {
          return AndroidViewSurface(
            controller: controller as AndroidViewController,
            gestureRecognizers: gestureRecognizers ??
                const <Factory<OneSequenceGestureRecognizer>>{},
            hitTestBehavior: PlatformViewHitTestBehavior.opaque,
          );
        },
        onCreatePlatformView: (PlatformViewCreationParams params) {
          return PlatformViewsService.initExpensiveAndroidView(
            id: params.id,
            viewType: viewType,
            layoutDirection: TextDirection.ltr,
            creationParams: creationParams,
            creationParamsCodec: const StandardMessageCodec(),
            onFocus: () {
              params.onFocusChanged(true);
            },
          )
            ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)
            ..addOnPlatformViewCreatedListener(onPlatformViewCreated)
            ..create();
        });
  } else if (defaultTargetPlatform == TargetPlatform.iOS) {
    return UiKitView(
        viewType: viewType,
        onPlatformViewCreated: onPlatformViewCreated,
        creationParams: creationParams,
        gestureRecognizers: gestureRecognizers,
        creationParamsCodec: const StandardMessageCodec());
  }
  return Text(
      '$defaultTargetPlatform is not yet supported by the maps plugin');
}