How to Switch Widgets after certain time in Flutter?
4,615
try this,
_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()));
});
});
}
Author by
Xavier VZ
I am from Ecuador, I am 20 years all, I like all kind of programming languages and right now I am a flutter addicted. I really love mobile development
Updated on December 16, 2022Comments
-
Xavier VZ over 1 year
I am facing problems with this tematic, I would like to change a widget after certain time. e.g I have this animatedFlutter Screen (screen 1) and then after the animation end I would like to change the screen to any screen that I have, for example. Login();
Any tips? Thanks.
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, ); } }
-
Xavier VZ over 4 yearsThis work fine, thanks. By the way is there a way to "clean" the screen 1? I mean, when the screen 2 appears I want that the previous buttom (buttom that apears in most of the cellphone (physic buttom)) goes to home screen and not screen 1 app
-
Xavier VZ over 4 yearsthe second screen appears faster than the logo animation, anyways it works.
-
Nardeepsinh Vaghela over 4 yearstry this, Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => Act_Login()));
-
Ayush Bherwani over 4 yearsThat's because you are changing the logo inside the Timeout callback function
-
Ayush Bherwani over 4 yearsYou can use
AnimationController
to achieve the desired animationo -
Xavier VZ over 4 yearsOh my god! It work excellent. Thanks for help flutter community :)
-
Xavier VZ over 4 yearsthanks for the explanation. I marked your answer as useful but system says " Votes cast by those with less than 15 reputation are recorded, but do not change the publicly displayed post score."