void main() {
// This code enables the Splash Screen to be active unless manually removed
var widgetsBinding = WidgetsFlutterBinding.ensureInitialized();
FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);
runApp(const MyApp());
}
在Material应用程序定义中,在构建方法中设置一个计时器,在删除启动画面之前等待2秒
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
// This will keep you SplashScreen up for exactly 2 seconds
Timer(Duration(seconds: 2), () {FlutterNativeSplash.remove(); });
return MaterialApp(
title: 'Coffee Rewards',
home: const MyHomePage(),
);
}
}
5条答案
按热度按时间4nkexdtk1#
Flutter原生启动画面不可能显示精确的时间,因为启动画面是在Flutter框架加载时显示的。根据设备的处理速度,这可能需要或多或少的时间。可以想象,在旧设备上,即使您没有添加额外的延迟,它也可能持续超过两秒。
kmb7vmvb2#
你可以在main方法中试试这个代码:
7nbnzgx93#
我没有使用flutter启动画面,而是尝试在scaffold中添加图像
//从init调用此函数
闪屏后要导航到的屏幕
vmjh9lq94#
在你的主镖中载入所有东西后,你可以设置一个启动画面的计时器
u1ehiz5o5#
您可以保留启动画面,以便在您将其删除之前一直显示它。
启动应用程序之前,请保留启动画面
在Material应用程序定义中,在构建方法中设置一个计时器,在删除启动画面之前等待2秒