如何在 flutter 中显示启动屏幕 3 秒,然后转到下一个我的登录屏幕。
我已经尝试过.countdowntimer 但导入未解决
import 'package: countDown/countDown.dart';
CountDown cd = new CountDown(new Duration(seconds: 4));
CountDown is unresolved
Android Studio 和 Flutter
最佳答案
Simple solution which i use in every app.
在构建方法中使用 Timer
类
代码 fragment
class SplashScreen extends StatefulWidget {
@override
Splash createState() => Splash();
}
class Splash extends State<SplashScreen> {
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
Timer(
Duration(seconds: 3),
() =>
Navigator.of(context).pushReplacement(MaterialPageRoute(
builder: (BuildContext context) => LandingScreen())));
var assetsImage = new AssetImage(
'images/new_logo.png'); //<- Creates an object that fetches an image.
var image = new Image(
image: assetsImage,
height:300); //<- Creates a widget that displays an image.
return MaterialApp(
home: Scaffold(
/* appBar: AppBar(
title: Text("MyApp"),
backgroundColor:
Colors.blue, //<- background color to combine with the picture :-)
),*/
body: Container(
decoration: new BoxDecoration(color: Colors.white),
child: new Center(
child: image,
),
), //<- place where the image appears
),
);
}
}
https://stackoverflow.com/questions/50129761/