共计 1906 个字符,预计需要花费 5 分钟才能阅读完成。
flutterView = new FlutterView(host.getActivity(), flutterSurfaceView);
} else {
FlutterTextureView flutterTextureView = new FlutterTextureView(host.getActivity());
// Allow our host to customize FlutterSurfaceView, if desired.
host.onFlutterTextureViewCreated(flutterTextureView);
// Create the FlutterView that owns the FlutterTextureView.
flutterView = new FlutterView(host.getActivity(), flutterTextureView);
}
// Add listener to be notified when Flutter renders its first frame.
flutterView.addOnFirstFrameRenderedListener(flutterUiDisplayListener);
/// 创建一个闪屏 view – FlutterSplashView
flutterSplashView = new FlutterSplashView(host.getContext());
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN_MR1) {
flutterSplashView.setId(View.generateViewId());
} else {
// TODO(mattcarroll): Find a better solution to this ID. This is a random, static ID.
// It might conflict with other Views, and it means that only a single FlutterSplashView
// can exist in a View hierarchy at one time.
flutterSplashView.setId(486947586);
}
/// 显示闪屏页
flutterSplashView.displayFlutterViewWithSplash(flutterView, host.provideSplashScreen());
Log.v(TAG,“Attaching FlutterEngine to FlutterView.”);
/// 所创建 surface 绑定到 engine 上
flutterView.attachToFlutterEngine(flutterEngine);
return flutterSplashView;
}
这里我们可以大致了解到,创建了一个 FlutterSurfaceView 它继承自 surfaceView(我们的 flutter 页面也是渲染在这个 surface 上的)。之后我们用它初始化一个 FlutterView,
FlutterView 继承自 FrameLayout
随后我们再创建一个 FlutterSplashView(继承 FrameLayout)并调用 displayFlutterViewWithSplash()方法。
public void displayFlutterViewWithSplash(
@NonNull FlutterView flutterView, @Nullable SplashScreen splashScreen) {
// If we were displaying a previous FlutterView, remove it.
if (this.flutterView != null) {
this.flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener);
removeView(this.flutterView);
}
// If we were displaying a previous splash screen View, remove it.
if (splashScreenView != null) {
removeView(splashScreenView);
}
// Display the new FlutterView.
this.flutterView = flutterView;
/// 添加 flutterView
addView(flutterView);
原文地址: Flutter&Android 启动页(闪屏页)的加载流程和优化方案