首页 前端知识 Flutter&Android 启动页(闪屏页)的加载流程和优化方案

Flutter&Android 启动页(闪屏页)的加载流程和优化方案

2024-10-29 11:10:19 前端知识 前端哥 1013 582 我要收藏

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);

转载请注明出处或者链接地址:https://www.qianduange.cn//article/19419.html
标签
flutter
评论
发布的文章

在C#中使用JSON

2024-11-04 10:11:05

JSON串

2024-11-04 10:11:57

JSON教程(非常详细)

2024-05-08 10:05:36

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!