记录Flutter启动页3秒跳转

复制下面代码就可运行

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State {
  //设置3秒
  int _countdown = 3;
  late Timer _countdownTimer;

//手动点击跳转
  TapGestureRecognizer _recognizer = TapGestureRecognizer();

  @override
  void initState() {
    super.initState();

    _startRecordTime();
    _recognizer.onTap = () {
      _stopTime();
      Globals.globalsProvider!.setMonth(Globals.users.month);
      Navigator.of(context).pop();
      Navigator.pushNamedAndRemoveUntil(context, '/Login', (route) => false);
    };
  }

  @override
  void dispose() {
    super.dispose();
    _stopTime();
  }

  void _stopTime() {
    if (_countdownTimer != null && _countdownTimer.isActive) {
      _countdownTimer.cancel();
    }
  }

  void _startRecordTime() {
    _countdownTimer = Timer.periodic(Duration(seconds: 1), (timer)

你可能感兴趣的:(flutter,flutter)