颤振启动画面
Flutter Splash Screen
如何在 flutter 中显示启动画面?所以有一个启动图标的选项。我在各自的文件夹中添加了 ios 和 android 的图像。我的问题是它太快了。所以它直接打开MyApp()。我希望我的应用程序不显示任何内容并让飞溅控制,直到我弄清楚将用户带到哪个屏幕(在 MyApp 中我想进行初始化)
您可以在 initState
中使用 Future.delayed
构造函数。这将使您的 SplashScreen 在导航发生之前的指定时间内保持不变。
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => new _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState (){
super.initState();
// TODO initial state stuff
new Future.delayed(const Duration(seconds: 4));
}
@override
Widget build(BuildContext context) {
//build
}
}
aziza 答案的小更新
import 'dart:async';
import 'package:flutter/material.dart';
import 'src/login_screen.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
new Future.delayed(
const Duration(seconds: 3),
() => Navigator.push(
context,
MaterialPageRoute(builder: (context) => LoginScreen()),
));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.white,
body: Container(
child: new Column(children: <Widget>[
Divider(
height: 240.0,
color: Colors.white,
),
new Image.asset(
'assets/logo.png',
fit: BoxFit.cover,
repeat: ImageRepeat.noRepeat,
width: 170.0,
),
Divider(
height: 105.2,
color: Colors.white,
),
]),
),
);
}
}
希望这对其他人也有帮助:)
如何在 flutter 中显示启动画面?所以有一个启动图标的选项。我在各自的文件夹中添加了 ios 和 android 的图像。我的问题是它太快了。所以它直接打开MyApp()。我希望我的应用程序不显示任何内容并让飞溅控制,直到我弄清楚将用户带到哪个屏幕(在 MyApp 中我想进行初始化)
您可以在 initState
中使用 Future.delayed
构造函数。这将使您的 SplashScreen 在导航发生之前的指定时间内保持不变。
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => new _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> {
@override
void initState (){
super.initState();
// TODO initial state stuff
new Future.delayed(const Duration(seconds: 4));
}
@override
Widget build(BuildContext context) {
//build
}
}
aziza 答案的小更新
import 'dart:async';
import 'package:flutter/material.dart';
import 'src/login_screen.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
void initState() {
super.initState();
new Future.delayed(
const Duration(seconds: 3),
() => Navigator.push(
context,
MaterialPageRoute(builder: (context) => LoginScreen()),
));
}
@override
Widget build(BuildContext context) {
return new Scaffold(
backgroundColor: Colors.white,
body: Container(
child: new Column(children: <Widget>[
Divider(
height: 240.0,
color: Colors.white,
),
new Image.asset(
'assets/logo.png',
fit: BoxFit.cover,
repeat: ImageRepeat.noRepeat,
width: 170.0,
),
Divider(
height: 105.2,
color: Colors.white,
),
]),
),
);
}
}
希望这对其他人也有帮助:)