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

5,008次阅读
没有评论

共计 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 启动页(闪屏页)的加载流程和优化方案

    正文完
     0
    Yojack
    版权声明:本篇文章由 Yojack 于2024-10-29发表,共计1906字。
    转载说明:
    1 本网站名称:优杰开发笔记
    2 本站永久网址:https://yojack.cn
    3 本网站的文章部分内容可能来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
    4 本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
    5 本站所有内容均可转载及分享, 但请注明出处
    6 我们始终尊重原创作者的版权,所有文章在发布时,均尽可能注明出处与作者。
    7 站长邮箱:laylwenl@gmail.com
    评论(没有评论)