本文介绍了在flutter应用程序中添加初始屏幕的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个基于Flutter的应用程序,并研究了添加初始屏幕的几种方法。但是我不确定哪个是最好的。
I am developing a flutter based app and studied there are couple of ways to add splash screen. But I am not sure which one is the best to achieve.
推荐答案
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:mingup/screen/login_screen.dart';
// This is the Splash Screen
class SplashScreen extends StatefulWidget {
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen> with SingleTickerProviderStateMixin{
AnimationController _animationController;
Animation<double> _animation;
@override
void initState() {
// TODO: implement initState
super.initState();
_animationController = new AnimationController(
vsync: this,
duration: new Duration(milliseconds: 500)
);
_animation = new CurvedAnimation(
parent: _animationController,
curve: Curves.easeOut,
);
_animation.addListener(()=> this.setState((){}));
_animationController.forward();
Timer(Duration(seconds: 10), (){
Navigator.push(context, MaterialPageRoute(builder: (context) => LoginScreen()));
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
Container(
child: Image.asset(
'images/splashscreenbg.png',
fit: BoxFit.cover,
)
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Expanded(
flex: 2,
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
FlutterLogo(
size: _animation.value * 100.0,
),
Padding(padding: EdgeInsets.only(top: 10.0)),
Text("MingUp", style: TextStyle(color: Colors.white, fontSize: 24.0, fontWeight: FontWeight.bold),)
],
),
),
),
]
)
],
),
);
}
}
这篇关于在flutter应用程序中添加初始屏幕的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!