Flutter splash 屏幕

news2025/7/15 23:31:05

Flutter splash 屏幕

alt

原文 https://medium.com/@bedirhanssaglam/flutter-splash-screen-a8cafec52c8e

前言

启动画面通常被特别大的应用程序用来通知用户程序正在加载过程中。它们提供的反馈表明,一个漫长的过程正在进行中。有时,启动画面中的进度条会指示加载进度。当应用程序的主窗口出现时,启动画面就会消失。启动画面可以添加一段时间,然后重新替换。

正文

启动画面通常用于增强应用程序或网站的外观和感觉,因此它们通常在视觉上很吸引人。它们还可以具有动画、图形和声音。

alt

对于本文,我将从 flutter_national_splash 包获得帮助,我也在业务项目中使用该包。Flutter_national_splash 是 Flutter 最喜欢的软件包之一。它是最先进的闪屏解决方案之一。

让我们看看如何一步一步地做。

flutter_native_splash 包

首先,我们将库添加到 pubspec.yaml 文件。接下来,我们将用于启动画面的图像文件包含到项目中。

图像文件必须有.png extension 名。

pubspec.yaml

dependencies:
  flutter:
    sdk: flutter
  cupertino_icons: ^1.0.2

  flutter_native_splash: ^2.2.10+1
alt

flutter_navite_splash.yaml 配置

然后,创建一个名为 flutter_navite_splash.yaml 的文件,复制并粘贴下面的文本。 注意: 我在这里为您定制了一些设置。如果您想在自己的项目中使用该文件,只需更改“ image”部分:)

flutter_native_splash.yaml

flutter_native_splash:
  # This package generates native code to customize Flutter's default white native splash screen
  # with background color and splash image.
  # Customize the parameters below, and run the following command in the terminal:
  # flutter pub run flutter_native_splash:create
  # To restore Flutter's default white splash screen, run the following command in the terminal:
  # flutter pub run flutter_native_splash:remove

  # color or background_image is the only required parameter.  Use color to set the background
  # of your splash screen to a solid color.  Use background_image to set the background of your
  # splash screen to a png image.  This is useful for gradients. The image will be stretch to the
  # size of the app. Only one parameter can be used, color and background_image cannot both be set.
  color: "#ffffff"
  #background_image: "assets/background.png"

  # Optional parameters are listed below.  To enable a parameter, uncomment the line by removing
  # the leading # character.

  # The image parameter allows you to specify an image used in the splash screen.  It must be a
  # png file and should be sized for 4x pixel density.
  image: "assets/images/covid_splash.png"

  # The color_dark, background_image_dark, and image_dark are parameters that set the background
  # and image when the device is in dark mode. If they are not specified, the app will use the
  # parameters from above. If the image_dark parameter is specified, color_dark or
  # background_image_dark must be specified.  color_dark and background_image_dark cannot both be
  # set.
  #color_dark: "#042a49"
  #background_image_dark: "assets/dark-background.png"
  #image_dark: assets/splash-invert.png

  # The android, ios and web parameters can be used to disable generating a splash screen on a given
  # platform.
  android: true
  ios: true
  web: false

  # The position of the splash image can be set with android_gravity, ios_content_mode, and
  # web_image_mode parameters.  All default to center.
  #
  # android_gravity can be one of the following Android Gravity (see
  # https://developer.android.com/reference/android/view/Gravity): bottom, center,
  # center_horizontal, center_vertical, clip_horizontal, clip_vertical, end, fill, fill_horizontal,
  # fill_vertical, left, right, start, or top.
  android_gravity: fill
  #
  # ios_content_mode can be one of the following iOS UIView.ContentMode (see
  # https://developer.apple.com/documentation/uikit/uiview/contentmode): scaleToFill,
  # scaleAspectFit, scaleAspectFill, center, top, bottom, left, right, topLeft, topRight,
  # bottomLeft, or bottomRight.
  ios_content_mode: scaleToFill
  #
  # web_image_mode can be one of the following modes: center, contain, stretch, and cover.
  #web_image_mode: center

  # To hide the notification bar, use the fullscreen parameter.  Has no affect in web since web
  # has no notification bar.  Defaults to false.
  NOTE: Unlike Android, iOS will not automatically show the notification bar when the app loads.
  #       To show the notification bar, add the following code to your Flutter app:
  #       WidgetsFlutterBinding.ensureInitialized();
  #       SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
  #fullscreen: true

  # If you have changed the name(s) of your info.plist file(s), you can specify the filename(s)
  # with the info_plist_files parameter.  Remove only the # characters in the three lines below,
  # do not remove any spaces:
  #info_plist_files:
  #  - 'ios/Runner/Info-Debug.plist'
  #  - 'ios/Runner/Info-Release.plist'

然后在终端运行 Flutter clean 清理命令。

然后运行 flutter pub,运行 flutter pub run flutter_native_splash:create

在那之后,如果你在终端中看到以下内容,那么你已经做到了! :)

alt

main.dart 代码

现在是时候把最后一点。

main.dart

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await initialization(null);
  runApp(MyApp());
}

Future initialization(BuildContext? context) async {
  await Future.delayed(const Duration(milliseconds: 500));
}
}

我们在不运行 MyApp 的情况下调用启动画面。然后我们决定它会在屏幕上出现多长时间。现在,当我们关闭应用程序并从菜单中再次打开它时,我们定义的图像将出现。

结束语

如果本文对你有帮助,请转发让更多的朋友阅读。

也许这个操作只要你 3 秒钟,对我来说是一个激励,感谢。

祝你有一个美好的一天~


© 猫哥

  • 微信 ducafecat

  • https://wiki.ducafecat.tech

  • https://video.ducafecat.tech

本文由 mdnice 多平台发布

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/36517.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【MYSQL】在线恢复主从复制方案

一、恢复前提 因复杂情况,从库无法从binlog中恢复主从复制关系,需要从备份文件中恢复。恢复过程的几个关键点为: 1、从库现有数据的清理。本方案采用覆盖的方式,导出时添加add-drop参数即可。还有一个方案是手动删除数据文件&…

1990-2021年全国各省外商直接投资水平

1990-2021年全国各省外商直接投资水平 1、包括全国30省,不含西藏 2、指标包括: 行政区划代码、长江经济带、年份、地区、经度、纬度、GDP(亿元)、外商直接投资(美元)(万美元)、人民币对美元汇率(美元1)(元)、外商直接投资(万元)、外商直接投资水平 3、…

第三章:CompletableFuture

Future接口复习FutureTask 实现类Future 编码的优缺点优点缺点get() 方法导致阻塞isDone() 轮询总结CompletableFutureCompletableFuture 为什么会出现?CompletableFuture 架构图CompletionStageCompletableFuture 四个静态方法CompletableFuture 减少阻塞和轮询注意…

Elasticsearch 8.4.1 配置自签名证书和启用Https

一、背景 某次安全扫描过程中,发现环境存在【SSL证书不可信】和【SSL自签名证书】漏洞;漏洞描述: 此服务的X.509证书链未由认可的证书颁发机构签名。如果远程主机是生产中的公共主机,这将取消SSL的使用,因为任何人都可…

干货分享:超级浏览器使用感受

在亚马逊做工艺品时间挺长的了,来说说我这几年使用超级浏览的感受。 现在做跨境的就跟做国内的电商平台一样卷了,不仅产品要新奇独特、要包邮价格还要有优势,可以说以前跨境电商是卖方市场,现在已经妥妥变成买方市场了。但这是国际…

python基础之模块与列表

文章目录一、模块模块名也是一个标识符二、列表高级变量类型:在python中,所有非数字型变量都支持以下特点:列表的定义:列表函数使用:关键字、函数和方法科普:列表的迭代 遍历:一、模块 模块是p…

一文了解 Go 中的指针和结构体

一文了解 Go 中的指针和结构体前言指针指针的定义获取和修改指针所指向变量的值结构体结构体定义结构体的创建方式小结耐心和持久胜过激烈和狂热。 前言 前面的两篇文章对 Go 语言的基础语法和基本数据类型以及几个复合数据类型进行介绍,本文将对 Go 里面的指针和结…

机器学习-(手推)线性回归-最小二乘法(矩阵表达)、几何意义

一、最小二乘法(矩阵表达)误差平均分散每个样本 如下数学推到过程(手推!!!): 数据介绍: D{(x1,y1),(x2,y2),......(xn,yn), Xi(P维列向量&…

行列向量的维数和个数的关系【三秩相等作为桥梁】

前置知识 1.列向量组维数增加时,向量组的极大无关组增加(或不变)。 2. 三秩相等 向量组证明 直观证明 这两个列向量显然是相关的。 这两个列向量当a和b取k和2k的时候相关(k为任意常数),当不是k和2k的时…

【2-Docker安装部署ElasticSearch和Kibanan详细步骤】

一.知识回顾 【0.ElasticSearch专栏在这里哟,想要学习的可自行进入专栏学习】 【1-ElasticSearch的基本介绍与用途、ElasticSearch中一些基本的概念、倒排索引的基本概念】 二.Docker安装部署ElasticSearch 2.1 docker pull 从镜像仓库中拉拉取ElasticSearch的镜像…

【零基础入门SpringMVC】第三期——请求域添加数据与视图

一、域对象共享数据 SpringMVC 中有哪些域对象? Request请求域,代表一次请求,从浏览器开启到关闭Session请求域,代表一次会话,从服务器开启到关闭【一次getSession获得了cookie,这个会话没关闭,…

Romantics三大浪漫(编译原理+操作系统+计算机图形学)

Romantics三大浪漫 一、编译原理1.1 研究翻译的科学1.2 编译器和解释器1.3 编译的流程(JIT为例)1.4 词法分析器1.5 多有限状态机提取Token- 实现词法分析器lexer1.6 实现流的peek和putBack操作一、编译原理 本章目标: 提升编程能力 区别于面向研究人员、学者的编译原理教学&a…

CSS学习笔记(三)

her~~llo,我是你们的好朋友Lyle,是名梦想成为计算机大佬的男人! 博客是为了记录自我的学习历程,加强记忆方便复习,如有不足之处还望多多包涵!非常欢迎大家的批评指正。 目录 一、CSS 的三大特性 1.1 层叠…

mybatis复习05,mybatis的缓存机制(一级缓存和二级缓存及第三方缓存)

mybatis复习05,mybatis的缓存机制(一级缓存和二级缓存)MyBatis的缓存机制MyBatis的一级缓存MyBatis的二级缓存二级缓存的相关配置MyBatis缓存查询的顺序整合第三方缓存EHCacheEHCache配置文件说明:MyBatis的缓存机制 MyBatis作为持久化框架&…

社区故事|SmartX 用户社区技术发烧友独家专访

小伙伴们,SmartX 用户社区已经陪伴我们走过近两年的时光,这期间有一千多位小伙伴加入我们,共同讨论问题、分享经验。今天,SmartX 用户社区的一线记者小乐为我们带来了独家采访,揭秘社区中两位技术发烧友的幕后故事&…

葡萄糖-聚乙二醇-转铁蛋白|Transferrin-PEG-Glucose|转铁蛋白-PEG-葡萄糖

转铁蛋白又名运铁蛋白 transferrin,TRF,siderophilin)还可以提供PEG接枝修饰葡萄糖,葡萄糖-聚乙二醇-转铁蛋白,Transferrin-PEG-Glucose,转铁蛋白-PEG-葡萄糖 中文名称:葡萄糖-转铁蛋白 英文名称:Glucose…

Java学习——Servlet服务器请求响应程序

Servlet服务器程序 1. Servlet的概念 Servlet(Server Applet):运行在Web服务器端(Tomcat)的小程序。 Servlet的主要作用:接收客户端浏览器的请求,还可以为客户端浏览器做出响应。 学习Servl…

戴尔笔记本重装系统按f几进入

有不少使用戴尔笔记本电脑的用户对于u盘重装系统中的按f几进入u盘启动的操作不熟悉,导致自己无法独立完成戴尔笔记本重装系统的步骤怎么办?其实相关的方法不难,下面小编就教下大家戴尔笔记本重装系统按f几进入u盘启动项安装。 工具/原料&…

【培训】MMEdu离线版的使用:实现石头剪刀布图像分类的检测

一、MMEdu离线版的使用 1.双击XEdu v1.0.exe解压缩到某个盘,会是一个文件夹XEdu 2.进入XEdu,双击运行“点我初始化.bat”,等待至运行结束命令提示符窗口自动关闭 3.双击运行“jupyter编辑器.bat”,将会打开一个网页版jupyter&…

第五站:操作符(第二幕)

在前面的文章中我们详细讲解了操作符的一些内容, 今天我们来继续了解操作符剩余的内容 操作符第一幕的传送门在这:第五站:操作符(第一幕) 目录 七、关系操作符 八、逻辑操作符 1.基础知识 2.几道经典的题目 九、条…