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()));
  });
});
}
Share:
4,615
Xavier VZ
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, 2022

Comments

  • Xavier VZ
    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
    Xavier VZ over 4 years
    This 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
    Xavier VZ over 4 years
    the second screen appears faster than the logo animation, anyways it works.
  • Nardeepsinh Vaghela
    Nardeepsinh Vaghela over 4 years
    try this, Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => Act_Login()));
  • Ayush Bherwani
    Ayush Bherwani over 4 years
    That's because you are changing the logo inside the Timeout callback function
  • Ayush Bherwani
    Ayush Bherwani over 4 years
    You can use AnimationController to achieve the desired animationo
  • Xavier VZ
    Xavier VZ over 4 years
    Oh my god! It work excellent. Thanks for help flutter community :)
  • Xavier VZ
    Xavier VZ over 4 years
    thanks 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."