Flutter添加启动页flutter_native_splash

flutter_native_splash的使用

1.flutter_native_splash

官方链接见https://pub-web.flutter-io.cn/packages/flutter_native_splash

支持Android/iOS/Web

2.pubspec.yaml添加依赖

flutter_native_splash: ^2.4.0

flutter_native_splash:
color: "#42a5f5"
image: "images/splash.png"
# image_dark: "assets/images/splash_dark.png"
android: true
ios: true

3.生成启动画面

flutter pub run flutter_native_splash:create

ksnowlv@MacBook-Pro-3 base_demo % flutter pub run flutter_native_splash:create
Deprecated. Use `dart run` instead.
Building package executable... (9.4s)
Built flutter_native_splash:create.
[Android] Creating default splash images
[Android] Updating launch background(s) with splash image path...
[Android] - android/app/src/main/res/drawable/launch_background.xml
[Android] - android/app/src/main/res/drawable-v21/launch_background.xml
[Android] Updating styles...
[Android] - android/app/src/main/res/values-v31/styles.xml
[Android] - android/app/src/main/res/values-night-v31/styles.xml
[Android] - android/app/src/main/res/values/styles.xml
[Android] - android/app/src/main/res/values-night/styles.xml
[iOS] Creating images
[iOS] Updating ios/Runner/Info.plist for status bar hidden/visible
[Web] Creating images
[Web] Creating images
[Web] Creating background images
[Web] Creating CSS
[Web] Updating index.html

✅ Native splash complete.
Now go finish building something awesome! 💪 You rock! 🤘🤩
Like the package? Please give it a 👍 here: https://pub.dev/packages/flutter_native_splash

ksnowlv@MacBook-Pro-3 base_demo %

4.代码示例

  • main.dart

import 'package:flutter_native_splash/flutter_native_splash.dart';

void main() {
XLogger.getLogger().d("main init");
WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
runApp(const MyApp());

}

5.XCode中设置启动屏

在flutter工程中的iOS目录下,打开Runner.xcworkspace,设置启动屏,如图所示

Flutter添加启动页flutter_native_splash

6.效果

Flutter添加启动页flutter_native_splash


原文始发于微信公众号(ksnowlv):Flutter添加启动页flutter_native_splash

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/254443.html

(0)
Java朝阳的头像Java朝阳

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!