Я новичок во флаттере.Сегодня я создал заставку и экран входа в систему.Затем я хочу анимировать свой логотип с заставки -> экран входа в систему.Но когда я запускаю код, анимация не работает, вот мой код:
Заставка
class SplashScreen extends StatelessWidget{
@override
Widget build(BuildContext context) {
// TODO: implement build
return new MaterialApp(
home: new SplashScreenPage(),
routes: <String, WidgetBuilder>{
'/LoginPage': (BuildContext context) => new LoginPage()
},
);
}
}
class SplashScreenPage extends StatefulWidget{
SplashScreenPage({Key key, this.title}) : super(key: key);
final String title;
@override
State<StatefulWidget> createState() {
return new SplashScreenState();
}
}
class SplashScreenState extends State<SplashScreenPage>{
startTime() async {
var _duration = new Duration(seconds: 2);
return new Timer(_duration, navigationPage);
}
void navigationPage() {
Navigator.of(context).pushNamed('/LoginPage');
}
@override
void initState() {
startTime();
super.initState();
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new SizedBox(
child: new Hero(
tag: 'hero-tag-llama',
child: new Image.asset(
'images/logo_futurisx.png',
fit: BoxFit.cover,
height: 150.0,
)
),
)
],
)
),
);
}
Экран входа в систему
class LoginState extends State<LoginPage>{
final userNameController = new TextEditingController();
final passwordController = new TextEditingController();
@override
Widget build(BuildContext context) {
var _imageBox = new SizedBox(
child: new Hero(
tag: 'hero-tag-llama',
child: new Image.asset(
'images/logo_futurisx.png',
fit: BoxFit.cover,
height: 100.0,
)
),
);
var _loginForm = new Container(
padding: new EdgeInsets.all(32.0),
child: new Column(
children: <Widget>[
new TextField(
maxLines: 1,
controller: userNameController,
decoration: new InputDecoration(
border: new UnderlineInputBorder(),
fillColor: Colors.green,
hintText: "Username"
),
),
new Container(
padding: new EdgeInsets.only(bottom: 20.0),
),
new TextField(
maxLines: 1,
controller: passwordController,
decoration: new InputDecoration(
border: new UnderlineInputBorder(),
fillColor: Colors.green,
hintText: "Password"
),
),
new Container(
padding: new EdgeInsets.only(bottom: 30.0),
),
new RaisedButton(
padding: new EdgeInsets.fromLTRB(30.0, 10.0, 30.0, 10.0),
child: new Text("Login", style: new TextStyle(color: Colors.white)),
elevation: 4.0,
color: Colors.teal,
onPressed: (){
login(userNameController.text, passwordController.text);
}
),
])
);
return new Scaffold(
key: _scaffoldKey,
body: new Center(
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
_imageBox,
_loginForm
],
)
)
);
}
Видео, которое я загрузил здесь:
https://vimeo.com/271938052
Когда я комментирую макет _loginForm на экране входа, анимация
children: <Widget>[
_imageBox,
//_loginForm
],
работает нормально.Может ли кто-нибудь помочь мне узнать, почему анимация не работает должным образом?
ОБНОВЛЕНИЕ -----------
После долгих поисков и исправлений я обнаружил, что таймер может бытьзаблокировать поток (или что-то подобное, ..) убрал таймер, позволил нажать кнопку, чтобы изменить страницу, анимация работает нормально.
Кто-нибудь сталкивался с этой проблемой?