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

本文详细解析了Flutter与Android应用启动页(闪屏页)的创建流程,包括FlutterView、FlutterTextureView和FlutterSplashView的使用。通过代码展示如何显示和管理闪屏页,并介绍了利用原生Surface优化启动页的方案,如使用SVGAPlayer播放动画,通过子线程处理以减少延迟,并讨论了通过Flutter端通知移除闪屏页的可能性。
摘要由CSDN通过智能技术生成

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值