APP
项目中闪屏页(或启动页)的作用是为了解决在程序显示第一帧之前,不要出现白屏的现象,尤其是在纯RN
和Flutter
的项目里面,资源加载完成到显示的速度会比Native
要逊色一些。这里主要总结纯Flutter
项目可选择的闪屏页实现方案,大部分为 pub.dev 上比较受欢迎的几种。前言Native
处理闪屏页不管是Android
还是iOS
官方都有很成熟的解决方案。API
不完善,issue
没人解决。这里提到这个插件主要想让同样在选闪屏页方案小伙伴就别再趟坑了,绕路节省时间。package
可以自动生Android
和iOS
端闪屏页的代码。并且可以自定义image
和背景color
。dev_dependencies:
flutter_native_splash: ^0.1.9
flutter pub get
pubspec.yaml
中flutter_native_splash:
image: images/splash.png // 对应生成iOS中LaunchImage图片,包含1x2x3x
color: "#ffffff" // 闪屏页背景色
flutter_native_splash:
android: false // 可以选择是否支持android或者iOS
android_disable_fullscreen: true // 禁用android全屏启动
fill: true // 如果图像可用在所有的屏幕上添加为true,目前只支持android
Native
flutter pub pub run flutter_native_splash:create
bogon:flutterdemo yin$ flutter pub pub run flutter_native_splash:create
[Android] Creating splash images
[Android] Updating launch_background.xml with splash image path
[Android] Updating colors.xml with color for splash screen background
[Android] Updating styles.xml with full screen mode setting
[iOS] Creating splash images
[iOS] Updating LaunchScreen.storyboard with width, height and color
bogon:flutterdemo yin$
iOS
端在Xcode
工程中选中LaunchScreen.storyboard
,关联UIImageView
和刚刚生成的图片,如果有需要调整UIImageView
的布局。Native
的闪屏页方案,只不过做成了工具提高了效率。最终run
起来也确实是我们想要的效果。icon
来自 iconfont 不做任何商业用途~~package
让闪屏页具有Flare
动画的功能。flutter pub get
dependencies:
flare_splash_screen: ^3.0.1
pubspec.yaml
中添加制作好的.flr
,我这里使用demo
自带的,公司项目中使用肯定是找设计师要。assets:
- intro.flr
import 'package:flare_splash_screen/flare_splash_screen.dart';
SplashScreen.navigate
方式class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: SplashScreen.navigate(
name: 'intro.flr',
next: (context) => BottomNavigationWidget(),
until: () => Future.delayed(Duration(seconds: 5)),
startAnimation: '1',
),
);
}
}
SplashScreen.callback
方式class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Builder(
builder: (context) => SplashScreen.callback(
name: 'intro.flr',
onSuccess: (_) {
Navigator.of(context).pushReplacement(PageRouteBuilder(
pageBuilder: (_, __, ___) =>
BottomNavigationWidget()));
},
loopAnimation: '1',
until: () => Future.delayed(Duration(seconds: 1)),
endAnimation: '1',
onError: (error, stacktrace) {
print(error);
},
),
),
);
}
}
package
的API
写的很灵活也很详细,选择你需要的属性做对应的调试即可,这里不做过多解释,直接看文档就好。Native
的闪屏页方案结合使用才是爆炸效果,至于如何做到闪屏页和这个Flare
动画完美过渡就要交给设计师们发光发热了。这里就展示一个粗糙的效果:Native
的支持Native
开发者闪屏页推荐选择方案为Native
处理。Native
开发者可以选择flutter_native_splash
方案。flare_splash_screen
。近期精彩内容推荐: