gpt4 book ai didi

timer - 如何在特定时间内显示小部件?

转载 作者:IT王子 更新时间:2023-10-29 07:11:50 25 4
gpt4 key购买 nike

我在主屏幕上使用一个图标来向用户显示某个进程正在进行中。我希望此图标在特定时间(比如 100 秒)内可见。用户可能会导航到各种屏幕,但当他返回主屏幕时,他应该能够看到该图标,并且该图标应在 100 秒后消失。我该怎么做?

最佳答案

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: 100), () {
setState(() {
_logoStyle = FlutterLogoStyle.horizontal;
});
});
}

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

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

请参阅此链接 How to run code after some delay in Flutter?

或者,您可以使用以下代码来实现延迟状态更新:

Future.delayed(const Duration(milliseconds: 100), () {
setState(() {
// Here you can write your code to update the state to show/hide the icon
});
});

关于timer - 如何在特定时间内显示小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55846149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com