创建引擎
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"),
));
});
}