Flutter hold splash screen for 3 Seconds. How to implement splash screen in Flutter?

前端 未结 9 2001
后悔当初
后悔当初 2021-02-16 00:16

How to show splash screen in flutter for 3 seconds and then go next my login screen.

I have tried.countdowntimer but import is unresolved

import \'pack         


        
9条回答
  •  粉色の甜心
    2021-02-16 00:43

    You can execute code with a delay using Future.delayed

    new Future.delayed(const Duration(seconds: 3), () {
      Navigator.pushNamed(context, '/login');
    });
    

    update

    const delay = 3;
    widget.countdown = delay;
    
    StreamSubscription sub;
    sub = new Stream.periodic(const Duration(seconds: 1), (count) {
      setState(() => widget.countdown--);  
      if(widget.countdown <= 0) {
        sub.cancel();
        Navigator.pushNamed(context, '/login');
      }
    });     
    

提交回复
热议问题