@@ -38,8 +38,6 @@ class _CountDownPageState extends State<CountDownPage> {
38
38
double strokeWidth = ScreenUtil ().setHeight (12 );
39
39
// 进度条进度
40
40
double progressValue = 0 ;
41
- // 倒计时是否结束
42
- bool success = false ;
43
41
// 当前时间
44
42
int ? hour;
45
43
int ? minutes;
@@ -56,8 +54,10 @@ class _CountDownPageState extends State<CountDownPage> {
56
54
bool enable = false ;
57
55
// 是否开启声音
58
56
bool enableAudio = true ;
57
+
58
+ final num _threshold = 5 ;
59
59
void handleStartClick () {
60
- if (pickerTime.inSeconds < 10 ) return ;
60
+ if (pickerTime.inSeconds <= _threshold - 1 ) return ;
61
61
setState (() => show = true );
62
62
const timeout = Duration (seconds: 1 );
63
63
progressValue = 0 ;
@@ -82,7 +82,6 @@ class _CountDownPageState extends State<CountDownPage> {
82
82
startSecond++ ;
83
83
int diffSecond = totalSecond - startSecond;
84
84
timerId = timer;
85
- success = false ;
86
85
if (enableAudio) {
87
86
_myPlayer! .startPlayer (
88
87
fromDataBuffer:
@@ -109,16 +108,8 @@ class _CountDownPageState extends State<CountDownPage> {
109
108
// 倒计时完成
110
109
if (diffSecond == 0 ) {
111
110
timer.cancel ();
112
- await Future .delayed (const Duration (milliseconds: 300 ));
113
- setState (() {
114
- show = false ;
115
- hour = null ;
116
- minutes = null ;
117
- second = null ;
118
- pickerTime = const Duration (seconds: 0 );
119
- progressValue = 0 ;
120
- });
121
- success = true ;
111
+ await Future .delayed (const Duration (milliseconds: 800 ));
112
+ countdownEnd ();
122
113
if (await Vibration .hasCustomVibrationsSupport () != null ) {
123
114
Vibration .vibrate (duration: 2500 , amplitude: 128 );
124
115
}
@@ -127,18 +118,31 @@ class _CountDownPageState extends State<CountDownPage> {
127
118
});
128
119
}
129
120
121
+ void countdownEnd () {
122
+ setState (() {
123
+ show = false ;
124
+ hour = null ;
125
+ minutes = null ;
126
+ second = null ;
127
+ pickerTime = const Duration (seconds: 0 );
128
+ progressValue = 0 ;
129
+ });
130
+ }
131
+
130
132
Future <bool > handleOnWillPop () async {
131
133
// 判断是否结束
132
- if (success) {
133
- return true ;
134
- }
135
- // 判断是否退出
136
- if (await showConfirmDialog (context,
137
- message: S .of (context).cancelCountDownMessage) !=
138
- null ) {
134
+ if (progressValue == 0 ) {
139
135
return true ;
136
+ } else {
137
+ // 判断是否退出
138
+ if (await showConfirmDialog (context,
139
+ message: S .of (context).cancelCountDownMessage, showTips: false ) !=
140
+ null ) {
141
+ timerId? .cancel ();
142
+ countdownEnd ();
143
+ }
144
+ return false ;
140
145
}
141
- return false ;
142
146
}
143
147
144
148
TextStyle textStyle = TextStyle (
@@ -285,8 +289,6 @@ class _CountDownPageState extends State<CountDownPage> {
285
289
backgroundColor: isNightMode
286
290
? Colors .grey.shade800
287
291
: Colors .grey.shade300,
288
- circularStrokeCap:
289
- CircularStrokeCap .round,
290
292
linearGradient:
291
293
LinearGradient (colors: colors),
292
294
percent: progressValue,
@@ -415,7 +417,7 @@ class _CountDownPageState extends State<CountDownPage> {
415
417
S .of (context).startTiming,
416
418
textAlign: TextAlign .center,
417
419
style: TextStyle (
418
- color: pickerTime.inSeconds >= 10
420
+ color: pickerTime.inSeconds >= _threshold
419
421
? context
420
422
.read <CurrentTheme >()
421
423
.isNightMode
0 commit comments