美文网首页
Flutter FlutterEngineGroup 基本使用

Flutter FlutterEngineGroup 基本使用

作者: 菜鸟何时起飞 | 来源:发表于2021-03-20 19:34 被阅读0次

创建引擎

        FlutterEngineGroup engineGroup = new FlutterEngineGroup(this);

        /*topMain 是跳转Flutter 执行的方法*/
        DartExecutor.DartEntrypoint dartEntrypoint = new DartExecutor.DartEntrypoint(
                FlutterInjector.instance().flutterLoader().findAppBundlePath(), "topMain"
        );

        FlutterEngine topEngine = engineGroup.createAndRunEngine(this, dartEntrypoint);
        FlutterEngineCache.getInstance().put("topMain", topEngine);
        /*创建不同的入口 使用不同的dartEntrypoint engineid 只能用来区分 引擎 引擎的入口交给 */
        DartExecutor.DartEntrypoint bottomEntrypoint = new DartExecutor.DartEntrypoint(
                FlutterInjector.instance().flutterLoader().findAppBundlePath(), "bottomMain"
        );
//        FlutterEngine bottomEngine = engineGroup.createAndRunEngine(this, bottomEntrypoint)
         /*动态移除*/
//        FlutterEngineCache.getInstance().remove(i.toString())

使用

 val intent =  FlutterActivity.CachedEngineIntentBuilder(FlutterActivityImpl::class.java, "topMain")
                    .build(this)
startActivity(intent)

dart

void main() {
  Stream.value(WidgetsFlutterBinding.ensureInitialized())
      .asyncMap((event) => SharedPreferenceUtil().initSpf())
      .listen((event) {
    runApp(getMainApp(window.defaultRouteName));
  });
}

@pragma('vm:entry-point')
void topMain() {
  Stream.value(WidgetsFlutterBinding.ensureInitialized())
      .asyncMap((event) => SharedPreferenceUtil().initSpf())
      .listen((event) {
    runApp(MaterialApp(
      home: Text("这是topMain"),
    ));
  });
  
}
@pragma('vm:entry-point')
void bottomMain() {
  Stream.value(WidgetsFlutterBinding.ensureInitialized())
      .asyncMap((event) => SharedPreferenceUtil().initSpf())
      .listen((event) {
    runApp(MaterialApp(
      home: Text("这是bottomMain"),
    ));
  });

}

相关文章

网友评论

      本文标题:Flutter FlutterEngineGroup 基本使用

      本文链接:https://www.haomeiwen.com/subject/manwcltx.html