简体   繁体   English

如何在 flutter 中使用 flutter_native_splash package 更改启动画面的时间?

[英]How to change time for splash screen using flutter_native_splash package in flutter?

I want to Change the Splash Screen time by using flutter_native_splash package.我想通过使用 flutter_native_splash package 来更改启动画面时间。

So how i can change the splash screen time?那么我怎样才能改变闪屏时间呢?

You should not use splash_screen to delay the user intentionally.您不应故意使用 splash_screen 来延迟用户。 Instead you should use splash_screen to load all necessary data background and close splash as soon as the app data is loaded from the internet.相反,您应该使用 splash_screen 加载所有必要的数据背景,并在从 Internet 加载应用程序数据后立即关闭启动画面。

If you also read through the package you will see in the FAQ the following:如果您还阅读了 package,您将在常见问题解答中看到以下内容:

Can I change the duration of the splash screen?我可以更改启动画面的持续时间吗?

The native splash screen is displayed while the native app loads the Flutter framework.当本机应用程序加载 Flutter 框架时,会显示本机启动画面。 Because the resources in your app cannot load while the native splash screen is displayed, the native splash screen must be as fast as possible.由于在显示原生闪屏时无法加载应用中的资源,因此原生闪屏必须尽可能快。 Note that delaying the user experience is a poor design decision.请注意,延迟用户体验是一个糟糕的设计决策。

So, you should only use splash screen to load contents from the internet to your app.因此,您应该只使用闪屏将内容从互联网加载到您的应用程序。

@Kamrul is right you should not add intentional delay in your app. @Kamrul 是对的,您不应该在您的应用程序中故意添加延迟。 But if it is client's requirement as I used to have one in one of my project just change your "main function" located in main.dart as following.但是,如果这是客户的要求,因为我曾经在我的项目之一中有一个,只需更改位于 main.dart 中的“主要功能”,如下所示。

void main() async {
    await Future.delayed(Duration(seconds: 3));
    runApp(MyApp());
}

Here are the changed I've made in the default main function.这是我在默认主 function 中所做的更改。

  1. I've made it asynchronous by adding async right after the parentheses.我通过在括号后添加异步使其异步。
  2. In second line I've told the main function to wait until the future is resolved by adding custom delay of 3 seconds.在第二行中,我告诉主要 function 等到未来通过添加 3 秒的自定义延迟来解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何删除或更改flutter_native_splash? - How to remove or change flutter_native_splash? 如何使用 Flutter_native_splash 在初始屏幕底部添加文本 - How to add text at bottom in splash screen using Flutter_native_splash android 设备 flutter 中的闪屏不是全屏。 尝试了一切。 使用 flutter_native_splash - Splash Screen not full screen in android device flutter. Tried everyting. Using flutter_native_splash 用户登录时使用flutter_native_splash时如何跳过启动画面 - How to skip the splash screen when use flutter_native_splash while user is logged In flutter_native_splash package:图像在 Android 上没有按比例缩小 - flutter_native_splash package: image does not scale down on Android 如何从应用程序中删除flutter_native_splash? - How to remove flutter_native_splash from app? 如何在 pub package“flutter_native_splash”中调整图像大小? - How can I resize image in pub package "flutter_native_splash"? 更改 flutter 原生闪屏 package 中的图像大小 - Change size of image in flutter native splash screen package 找不到 package“flutter_native_splash”。 你忘记添加依赖项了吗? - Could not find package "flutter_native_splash". Did you forget to add a dependency? 你可以在 flutter_native_splash 中调整图像的大小吗? - Can you resize an image in a flutter_native_splash?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM