【发布时间】:2019-06-04 17:31:37
【问题描述】:
我正在尝试创建一个倒数计时器应用程序,在该应用程序中我可以按下一个按钮来增加更多时间,同时计时器正在主动倒计时,就像每个微波炉都有一个按钮,你可以按下一个按钮来增加一分钟的运行时间它运行时没有停止任何东西的时间。
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(
home: new MyApp(),
));
}
class Countdown extends AnimatedWidget {
Countdown({ Key key, this.animation }) : super(key: key, listenable: animation);
Animation<int> animation;
@override
build(BuildContext context){
return new Text(
animation.value.toString(),
style: new TextStyle(fontSize: 150.0),
);
}
}
class MyApp extends StatefulWidget {
State createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> with TickerProviderStateMixin {
AnimationController _controller;
static const int kStartValue = 4;
@override
void initState() {
super.initState();
_controller = new AnimationController(
vsync: this,
duration: new Duration(seconds: kStartValue),
);
}
@override
Widget build(BuildContext context) {
return new Scaffold(
floatingActionButton: new FloatingActionButton(
child: new Icon(Icons.play_arrow),
onPressed: () => _controller.forward(from: 0.0),
),
body: new Container(
child: new Center(
child: new Countdown(
animation: new StepTween(
begin: kStartValue,
end: 0,
).animate(_controller),
),
),
),
);
}
}
这个来自关于计时器的类似问题的示例对我来说很有意义,并且一直是我的出发点。我知道我需要更改持续时间并用具有适当持续时间的新动画替换动画,但我从来没有得到任何接近我正在寻找的正确行为的东西。
【问题讨论】:
标签: dart flutter flutter-animation