一尘不染

颤振保持闪屏3秒钟。如何在Flutter中实现启动屏幕?

flutter

如何在闪屏中显示闪屏3秒钟,然后进入我的登录屏幕。

我试过了.countdowntimer,但是导入无法解决

import 'package: countDown/countDown.dart';
CountDown cd  =  new CountDown(new Duration(seconds: 4));
CountDown is unresolved

Android Studio和Flutter


阅读 273

收藏
2020-08-13

共1个答案

一尘不染

您可以使用延迟执行代码 Future.delayed

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

更新

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');
  }
});
2020-08-13