flutter - 如何在 Flutter 中重置倒计时
解决方案
你需要通过function
首先你需要改变你restartTimer
的
void restartTimer() {
setState(() {
_controller.reset();
_controller.forward();
});
}
然后将使用的小部件更改Countdown
为此
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(scaffoldBackgroundColor: darkBlue),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: Countdown(
restartTimer:restartTimer, // send the function
animation: StepTween(
begin: 1 * 60,
end: 0,
).animate(_controller),
),
),
),
);
}
之后,您需要receive
该功能
class Countdown extends AnimatedWidget {
Countdown({Key key, this.animation,this.restartTimer}) : super(key: key, listenable: animation);
Animation<int> animation;
final Function restartTimer;
....
然后在里面Countdown
改成OnTap
这个
onTap: () {
this.restartTimer();
},
推荐阅读
- ruby - 更新到 macOS Catalina [使用 Fishshell] 后,Fastlane 不起作用
- javascript - AmCharts 地图上的动画线
- java - 如何使用继承项解析 Json 泛型数组
- php - 在 PHP 中运行标志集时 MySQL 表未更新
- maven - AEM 6.5 WKND 存储库构建问题
- api - 如何在 Json ld 上下文中重命名 @id - API 平台 [已解决]
- sql-server - 从 txt 批量插入。具有主键和时间戳值的文件
- swift - 当调用此集合视图的 ReloadData 时,附加到 UICollectionView 中的单元格的弹出框移动
- reactjs - 如何在不使用 Owl Carousel 2 组件的情况下实现 Owl Carousel 的反应?
- coldfusion - 强制停止cfc组件中函数的执行