IPlatformgit
移除一下代碼github
Activity getMainActivity();
boolean startActivity(Context context,String url,int requestCode);
Map getSettings();
複製代碼
新增長json
void registerPlugins(PluginRegistry registry) 方法
void openContainer(Context context,String url,Map<String,Object> urlParams,int requestCode,Map<String,Object> exts);
void closeContainer(IContainerRecord record, Map<String,Object> result, Map<String,Object> exts);
IFlutterEngineProvider engineProvider();
int whenEngineStart();
複製代碼
這個Api變化主要是在Application初始化的時候的修改bash
以上是Flutter_boost github上面的說明,具體能夠查看ide
接入的方式主要是在V0.0.420版本上面作的修改,V0.0.420的接入方式能夠參考我以前的文章函數
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
FlutterBoostPlugin.init(new IPlatform() {
@Override
public Application getApplication() {
return MyApplication.this;
}
/**
* get the main activity, this activity should always at the bottom of task stack.
*/
@Override
public Activity getMainActivity() {
return MainActivity.sRef.get();
}
@Override
public boolean isDebug() {
return false;
}
/**
* start a new activity from flutter page, you may need a activity router.
*/
@Override
public boolean startActivity(Context context, String url, int requestCode) {
return PageRouter.openPageByUrl(context,url,requestCode);
}
@Override
public Map getSettings() {
return null;
}
});
}
}
複製代碼
能夠繼承FlutterApplication,直接使用,不繼承FlutterApplication 的話須要在使用Flutter的Activity中onCreate加入 FlutterMain.startInitialization(this); 以下所示測試
@CallSuper
public void onCreate() {
FlutterMain.startInitialization(this);
super.onCreate();
}
複製代碼
其實對應的FlutterApplication是很簡單的,主要仍是在onCreate中優化
public class FlutterApplication extends Application {
private Activity mCurrentActivity = null;
public FlutterApplication() {
}
@CallSuper
public void onCreate() {
super.onCreate();
FlutterMain.startInitialization(this);
}
public Activity getCurrentActivity() {
return this.mCurrentActivity;
}
public void setCurrentActivity(Activity mCurrentActivity) {
this.mCurrentActivity = mCurrentActivity;
}
}
複製代碼
public class MyApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
FlutterBoost.init(new Platform() {
@Override
public Application getApplication() {
return MyApplication.this;
}
@Override
public boolean isDebug() {
return true;
}
@Override
public void openContainer(Context context, String url, Map<String, Object> urlParams, int requestCode, Map<String, Object> exts) {
PageRouter.openPageByUrl(context,url,urlParams,requestCode);
}
@Override
public IFlutterEngineProvider engineProvider() {
return new BoostEngineProvider(){
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"),"/");
}
};
}
@Override
public int whenEngineStart() {
return IMMEDIATELY;
}
});
}
}
複製代碼
移除和新增代碼,前面講了,這裏主要講一下whenEngineStart()函數,其返回值有兩個ui
int IMMEDIATELY = 0; //當即啓動引擎
int ANY_ACTIVITY_CREATED = 1; //當有任何Activity建立時,啓動引擎
複製代碼
官方demo給的默認值是ANY_ACTIVITY_CREATED 建立Activity 都會啓動,主要是控制引擎的初始化時機this
engineProvider()返回一個Flutter引擎提供者,BoostEngineProvider,主要看其內部的createEngine()方法
@Override
public BoostFlutterEngine createEngine(Context context) {
return new BoostFlutterEngine(context, new DartExecutor.DartEntrypoint(
context.getResources().getAssets(),
FlutterMain.findAppBundlePath(context),
"main"),"/");
}
複製代碼
這裏大體講一下其中的main字符,這個主要是在BoostFlutterEngine內部建立引擎的時候,設置對應的Flutter 執行的main函數也就是Flutter代碼的執行的入口,斜槓主要是初始化路由用的
修改版本信息v0.1.52,最新版
移除
FlutterBoost.handleOnStartPage();
複製代碼
打開頁面不帶參數
FlutterBoost.singleton.openPage("second", {}, animated: true);
<!--修改爲-->
FlutterBoost.singleton.open("second")
複製代碼
打開頁面帶參數
FlutterBoost.singleton.openPage("sample://nativePage", {
"query": {"aaa": "bbb"}
}),
<!--修改爲-->
FlutterBoost.singleton.open("sample://nativePage", urlParams:{
"query": {"aaa": "bbb"}
}),
複製代碼
關閉頁面
FlutterBoost.singleton.closePageForContext(context);
<!--修改爲-->
BoostContainerSettings settings = BoostContainer.of(context).settings;
FlutterBoost.singleton.close(settings.uniqueId,result: {"result":"data from second"});
複製代碼
寫好flutter插件相關的以後,再iOS端接入就比較簡單了
再命令行執行
pod install
複製代碼
就會升級完flutter_boost的插件,主要再API層面的改動和Android差很少,就是open/close兩個方法,具體以下
升級前
- (void)openPage:(NSString *)name params:(NSString *)json animated:(BOOL)animated completion:(void (^)(BOOL))completion
- (void)closePage:(NSString *)uid
animated:(BOOL)animated
params:(NSDictionary *)params
completion:(void (^)(BOOL finished))completion;
升級後
#pragma mark - Boost 1.5
- (void)open:(NSString *)name
urlParams:(NSDictionary *)params
exts:(NSDictionary *)exts
completion:(void (^)(BOOL))completion
- (void)close:(NSString *)uid
result:(NSDictionary *)result
exts:(NSDictionary *)exts
completion:(void (^)(BOOL finished))completion;
複製代碼
//繼承BoostFlutterActivity修改
BoostFlutterActivity#createRenderingProgressCover()方法能夠避免
複製代碼
2.一樣的低端機器,再native界面回退到Flutter頁面會存在白屏閃一下的現象,應該是在恢復Flutter相關的繪製時候致使的,期待後續的優化