Home > front end >  How to register multiple native iOS views in flutter?
How to register multiple native iOS views in flutter?

Time:12-01

I have two native views in flutter for iOS CealQrViewNativeViewFactory and CealScanViewNativeViewFactory. When I use them individually while commenting out the other one then it works but if I try to register both of them I get error saying

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Duplicate plugin key: <ceal-views>' 

Below is my code in AppDelegate's didFinishLaunchingWithOptions

GeneratedPluginRegistrant.register(with: self)
        
        weak var registrar = self.registrar(forPlugin: "ceal-views")
        let cealQrViewfactory = CealQrViewNativeViewFactory(messenger: registrar!.messenger())
        self.registrar(forPlugin: "<ceal-views>")!.register(
            cealQrViewfactory,
            withId: "cealQrView")
        
        let cealScanViewFactory = CealScanViewNativeViewFactory(messenger: registrar!.messenger())
        self.registrar(forPlugin: "<ceal-views>")!.register(
            cealScanViewFactory,
            withId: "cealScanQrView")

I have separate swift file for CealScanViewNativeViewFactory and CealQrViewNativeViewFactory where I have written native swift code

CodePudding user response:

Try this:

        weak var registrar = self.registrar(forPlugin: "ceal-views")
        let cealQrViewfactory = CealQrViewNativeViewFactory(messenger: registrar!.messenger())
        let viewRegistrar = self.registrar(forPlugin: "<ceal-views>")!
        viewRegistrar.register(
            cealQrViewfactory,
            withId: "cealQrView")
        
        let cealScanViewFactory = CealScanViewNativeViewFactory(messenger: registrar!.messenger())
        viewRegistrar.register(
            cealScanViewFactory,
            withId: "cealScanQrView")
  • Related