|
|
|
@ -17,7 +17,7 @@ class AppTimer extends StatefulWidget {
|
|
|
|
final BoxDecoration? decoration;
|
|
|
|
final BoxDecoration? decoration;
|
|
|
|
final bool enabled;
|
|
|
|
final bool enabled;
|
|
|
|
final String? label;
|
|
|
|
final String? label;
|
|
|
|
final double ?width;
|
|
|
|
final double? width;
|
|
|
|
|
|
|
|
|
|
|
|
final Function(bool)? timerProgress;
|
|
|
|
final Function(bool)? timerProgress;
|
|
|
|
|
|
|
|
|
|
|
|
@ -98,8 +98,12 @@ class _AppTimerState extends State<AppTimer> {
|
|
|
|
_endAt = widget.timer?.endAt;
|
|
|
|
_endAt = widget.timer?.endAt;
|
|
|
|
_running = _startAt != null && _endAt == null;
|
|
|
|
_running = _startAt != null && _endAt == null;
|
|
|
|
_delay = widget.timer?.durationInSecond ?? 0;
|
|
|
|
_delay = widget.timer?.durationInSecond ?? 0;
|
|
|
|
final difference = _startAt == null ? 0 : (_endAt ?? DateTime.now()).difference(_startAt!).inSeconds;
|
|
|
|
int difference = _startAt == null ? 0 : (_endAt ?? DateTime.now()).difference(_startAt!).inSeconds;
|
|
|
|
|
|
|
|
if (difference != 0 && _delay != 0) {
|
|
|
|
|
|
|
|
difference = difference + _delay;
|
|
|
|
|
|
|
|
}
|
|
|
|
_period.value = Duration(seconds: _running ? difference : (difference != 0 ? difference : _delay)).toString().split(".").first;
|
|
|
|
_period.value = Duration(seconds: _running ? difference : (difference != 0 ? difference : _delay)).toString().split(".").first;
|
|
|
|
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
super.initState();
|
|
|
|
if (_running) {
|
|
|
|
if (_running) {
|
|
|
|
_startTimer();
|
|
|
|
_startTimer();
|
|
|
|
@ -115,7 +119,7 @@ class _AppTimerState extends State<AppTimer> {
|
|
|
|
@override
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
return Container(
|
|
|
|
width: widget.width??100 * AppStyle.getScaleFactor(context),
|
|
|
|
width: widget.width ?? 100 * AppStyle.getScaleFactor(context),
|
|
|
|
height: 56.toScreenHeight,
|
|
|
|
height: 56.toScreenHeight,
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 16.toScreenWidth),
|
|
|
|
decoration: widget.decoration ??
|
|
|
|
decoration: widget.decoration ??
|
|
|
|
|