Flutter FlutterEngineGroup 基本使用

创建引擎

        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"),
    ));
  });

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容