Trying to create a platform view of unregistered type

875 Views Asked by At

I'm developing a Flutter Plugin that uses AndroidView to display native Android views

But I get the following Exception:

Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: type

I can't figure out why it happens. Can someone explain the origin of this exception?

I thought you have to register the view-type in PluginName.java like this:

@Override
  public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
    binding.getPlatformViewRegistry()
           .registerViewFactory("type", new ViewFactory());
  }

And in main.dart of the example app simple use that view type:

AndroidView(
          viewType: "type",
          layoutDirection: TextDirection.ltr,
          creationParams: creationParams,
          creationParamsCodec: const StandardMessageCodec(),
        )
0

There are 0 best solutions below