我在使用此tematic时遇到问题,我想在一段时间后更改窗口小部件。例如我有一个animationFlutter屏幕(屏幕1),然后在动画结束后,我想将屏幕更改为我拥有的任何屏幕。 Login();
任何提示?谢谢。
import 'package:flutter/material.dart';
import 'dart:async';
void main() => runApp(AnimatedFlutterLogo());
class AnimatedFlutterLogo extends StatefulWidget {
@override
State<StatefulWidget> createState() => new _AnimatedFlutterLogoState();
}
class _AnimatedFlutterLogoState extends State<AnimatedFlutterLogo> {
Timer _timer;
FlutterLogoStyle _logoStyle = FlutterLogoStyle.markOnly;
_AnimatedFlutterLogoState() {
_timer = new Timer(const Duration(milliseconds: 800), () {
setState(() {
_logoStyle = FlutterLogoStyle.horizontal;
});
});
}
@override
void dispose() {
super.dispose();
_timer.cancel();
}
@override
Widget build(BuildContext context) {
return new FlutterLogo(
size: 200.0,
textColor: Colors.white,
style: _logoStyle,
);
}
}
您需要编写导航到另一个屏幕的代码(在Flutter的情况下为小部件)
Navigator.push(
context,
MaterialPageRoute(builder: (context) => Login()),
);
您需要在当前屏幕中导入登录名。
setState()
内编写如下所示的代码。
setState(() {
Navigator.push(context,
MaterialPageRoute(builder: (context) => Login()));
});
尝试一下,
_Act_NotificationScreenState() {
_timer = new Timer(const Duration(milliseconds: 800), () {
setState(() {
_logoStyle = FlutterLogoStyle.horizontal;
});
_timer = new Timer(const Duration(seconds: 1), () {
Navigator.push(context, MaterialPageRoute(builder: (context) => Act_Login()));
});
});
}