须要实现native跳转到flutter 指定的路由页面。git
iOS 工程中发现 FlutterViewController setInitialRouter 无效,在个人需求里面是: 在iOS现有工程集成flutter项目,而后能够跳转到任意的 业务页面。swift
在iOS 之中实例化页面有两种方式,以下:app
swift 代码:less
@objc func handleButtonAction() { let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)! flutterViewController.setInitialRoute("test1") self.navigationController?.pushViewController(flutterViewController, animated: true) }
这种方式显示效果最好,app 已启动,就会直接加载数据,是我所须要的一种,渲染效果几乎和native 一致,毫无违和感,交互很是流畅。ide
可是若是我想以前跳转到指定页面如:“test1” 路由页面,却发现不起做用;测试
swift pushRouter:ui
@objc func handleButtonAction() { let flutterEngine = (UIApplication.shared.delegate as? AppDelegate)?.flutterEngine let flutterViewController = FlutterViewController(engine: flutterEngine, nibName: nil, bundle: nil)! flutterViewController.pushRoute("test1") self.navigationController?.pushViewController(flutterViewController, animated: true) }
上面代码虽然有效,可是效果不是很好,并且有明显的push 状态。因此不是咱们想要的spa
@objc func handleButtonAction2(){ let flutterViewController = FlutterViewController() flutterViewController.setInitialRoute("test1") self.navigationController?.pushViewController(flutterViewController, animated: true) }
有效,可是每次渲染都有一闪的效果,在交互上比native差一点。debug
class MyApp extends StatelessWidget { // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter rokid', debugShowCheckedModeBanner: false,// 显示和隐藏 theme: ThemeData( // This is the theme of your application. // // Try running your application with "flutter run". You'll see the // application has a blue toolbar. Then, without quitting the app, try // changing the primarySwatch below to Colors.green and then invoke // "hot reload" (press "r" in the console where you ran "flutter run", // or press Run > Flutter Hot Reload in a Flutter IDE). Notice that the // counter didn't reset back to zero; the application is not restarted. primarySwatch: Colors.blue, ), home: PlaygroundPage(title: '若琪实验室'), routes: <String ,WidgetBuilder>{ "test": (_) => new PlaygroundPage(title: "我是内部路由测试test00",), "test1": (_) => new PlaygroundPage(title: "我是内部路由测试test01",) }, ); } }
https://www.gitmemory.com/issue/flutter/flutter/29554/492593645rest