代码之家  ›  专栏  ›  技术社区  ›  Abdullah Umer

将数据传递给颤振视图控制器

  •  0
  • Abdullah Umer  · 技术社区  · 4 年前

    我在原生iOS代码中添加了flatter。我有一个UIButton,按下这个按钮,我展示了一个FlatterViewController。我一直在关注 this .

    以下是我展示FlightViewController的代码:

    @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)
    }
    

    这段代码运行良好,颤振视图正在打开,因为我还没有指定和入口点,所以它使用了main。飞奔

    问题是我需要向颤振镖代码传递一些信息。e、 g.字典 ["patient_id": "123456"] 初始化期间。

    我也必须在Android原生Java代码中这样做。

    有什么简单的方法吗?

    1 回复  |  直到 4 年前
        1
  •  1
  •   Nico Spencer    4 年前

    你可能会想写一个 platform channel 在本机代码和颤振引擎之间通信。

    为此,另一种选择是使用 runWithEntrypoint:initialRoute: 方法启动引擎,将数据编码到初始路径,并在颤振侧对其进行解析。