Abdullah Umer
Abdullah Umer

Reputation: 4624

Pass data to Flutter View Controller

I have added flutter to a native iOS code. I have UIButton and on pressing this button, I am presenting a FlutterViewController. I have been following this.

Here's my code for presenting the FlutterViewController:

@objc
@IBAction func openProfile() {
    print("open profile")
    
    lazy var flutterEngine = FlutterEngine(name: "patient_profile_engine")
    
    flutterEngine.run(withEntrypoint: "", libraryURI: "");
    
    let profileVC =
            FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)
    present(profileVC, animated: true, completion: nil)
}

This code is working fine and the flutter view is opening and since I haven't specified and entry point yet so it using the main.dart.

The problem is that I need to pass some information to the Flutter dart code. e.g. a dictionary ["patient_id": "123456"] during the initialization.

I will have to do the same in Android native Java code as well.

Is there any easy way?

Upvotes: 0

Views: 1111

Answers (1)

Nico Spencer
Nico Spencer

Reputation: 1181

You will probably want to write a platform channel to communicate between the native code and the flutter engine.

An alternative, for this purpose, would be to use runWithEntrypoint:initialRoute: method to start the engine, encode the data into the initial route, and parse it on the flutter side.

Upvotes: 1

Related Questions