在Flutter中经过一定时间后如何切换小部件?

时间:2019-12-26 07:00:59

标签: android ios flutter android-animation flutter-animation

我在使用这种tematic时遇到了问题,我想在一段时间后更改一个小部件。例如 我有一个animationFlutter屏幕(屏幕1),然后在动画结束后,我想将屏幕更改为我拥有的任何屏幕。 Login();

有什么提示吗?谢谢。

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,

    );
  }
}

3 个答案:

答案 0 :(得分:3)

尝试一下

<ion-item>
    <ion-label color="medium">Leave</ion-label>
    <ion-select [(ngModel)]="leavetype" name="leavetype">
        <ion-select-option *ngFor="let val of result" value="">
            {{val. leavetype}}
        </ion-select-option>
    </ion-select>
</ion-item> 

答案 1 :(得分:0)

您需要编写导航到另一个屏幕的代码(在Flutter的情况下为小部件)

Navigator.push(
    context,
    MaterialPageRoute(builder: (context) => Login()),
  );

您需要在当前屏幕中导入“登录名”。

答案 2 :(得分:0)

AnimatedFlutterLogo包裹MaterialApp,并在Timer的回调函数中使用Navigator导航到相应的页面

示例:

import 'package:flutter/material.dart';
import 'dart:async';

void main() => runApp(MaterialApp(home: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;
      });
    Navigator.push(                      //<-- Navigate to loginPage on Timeout
    context,
    MaterialPageRoute(builder: (context) => LoginPage()),
  );
    });
  }

  @override
  void dispose() {
    super.dispose();
    _timer.cancel();
  }

  @override
  Widget build(BuildContext context) {
    return new FlutterLogo(
      size: 200.0,
      textColor: Colors.white,
      style: _logoStyle,

    );
  }
}

class LoginPage extends StatelessWidget{
  @override 
  Widget build(BuildContext context){
    return Container(alignment: Alignment.center,child: Text("LOG IN PAGE"));
  }
}