@@ -25,7 +25,7 @@ class MyHomePage extends StatefulWidget {
25
25
final String ? title;
26
26
27
27
@override
28
- _MyHomePageState createState () => _MyHomePageState ();
28
+ State < MyHomePage > createState () => _MyHomePageState ();
29
29
}
30
30
31
31
class _MyHomePageState extends State <MyHomePage > {
@@ -39,117 +39,135 @@ class _MyHomePageState extends State<MyHomePage> {
39
39
title: Text (widget.title! ),
40
40
),
41
41
body: Center (
42
- child: CircularCountDownTimer (
43
- // Countdown duration in Seconds.
44
- duration: _duration,
42
+ child: CircularCountDownTimer (
43
+ // Countdown duration in Seconds.
44
+ duration: _duration,
45
45
46
- // Countdown initial elapsed Duration in Seconds.
47
- initialDuration: 0 ,
46
+ // Countdown initial elapsed Duration in Seconds.
47
+ initialDuration: 0 ,
48
48
49
- // Controls (i.e Start, Pause, Resume, Restart) the Countdown Timer.
50
- controller: _controller,
49
+ // Controls (i.e Start, Pause, Resume, Restart) the Countdown Timer.
50
+ controller: _controller,
51
51
52
- // Width of the Countdown Widget.
53
- width: MediaQuery .of (context).size.width / 2 ,
52
+ // Width of the Countdown Widget.
53
+ width: MediaQuery .of (context).size.width / 2 ,
54
54
55
- // Height of the Countdown Widget.
56
- height: MediaQuery .of (context).size.height / 2 ,
55
+ // Height of the Countdown Widget.
56
+ height: MediaQuery .of (context).size.height / 2 ,
57
57
58
- // Ring Color for Countdown Widget.
59
- ringColor: Colors .grey[300 ]! ,
58
+ // Ring Color for Countdown Widget.
59
+ ringColor: Colors .grey[300 ]! ,
60
60
61
- // Ring Gradient for Countdown Widget.
62
- ringGradient: null ,
61
+ // Ring Gradient for Countdown Widget.
62
+ ringGradient: null ,
63
63
64
- // Filling Color for Countdown Widget.
65
- fillColor: Colors .purpleAccent[100 ]! ,
64
+ // Filling Color for Countdown Widget.
65
+ fillColor: Colors .purpleAccent[100 ]! ,
66
66
67
- // Filling Gradient for Countdown Widget.
68
- fillGradient: null ,
67
+ // Filling Gradient for Countdown Widget.
68
+ fillGradient: null ,
69
69
70
- // Background Color for Countdown Widget.
71
- backgroundColor: Colors .purple[500 ],
70
+ // Background Color for Countdown Widget.
71
+ backgroundColor: Colors .purple[500 ],
72
72
73
- // Background Gradient for Countdown Widget.
74
- backgroundGradient: null ,
73
+ // Background Gradient for Countdown Widget.
74
+ backgroundGradient: null ,
75
75
76
- // Border Thickness of the Countdown Ring.
77
- strokeWidth: 20.0 ,
76
+ // Border Thickness of the Countdown Ring.
77
+ strokeWidth: 20.0 ,
78
78
79
- // Begin and end contours with a flat edge and no extension.
80
- strokeCap: StrokeCap .round,
79
+ // Begin and end contours with a flat edge and no extension.
80
+ strokeCap: StrokeCap .round,
81
81
82
- // Text Style for Countdown Text.
83
- textStyle: const TextStyle (
84
- fontSize: 33.0 ,
85
- color: Colors .white,
86
- fontWeight: FontWeight .bold,
87
- ),
82
+ // Text Style for Countdown Text.
83
+ textStyle: const TextStyle (
84
+ fontSize: 33.0 ,
85
+ color: Colors .white,
86
+ fontWeight: FontWeight .bold,
87
+ ),
88
88
89
- // Format for the Countdown Text.
90
- textFormat: CountdownTextFormat .S ,
89
+ // Format for the Countdown Text.
90
+ textFormat: CountdownTextFormat .S ,
91
91
92
- // Handles Countdown Timer (true for Reverse Countdown (max to 0), false for Forward Countdown (0 to max)).
93
- isReverse: false ,
92
+ // Handles Countdown Timer (true for Reverse Countdown (max to 0), false for Forward Countdown (0 to max)).
93
+ isReverse: false ,
94
94
95
- // Handles Animation Direction (true for Reverse Animation, false for Forward Animation).
96
- isReverseAnimation: false ,
95
+ // Handles Animation Direction (true for Reverse Animation, false for Forward Animation).
96
+ isReverseAnimation: false ,
97
97
98
- // Handles visibility of the Countdown Text.
99
- isTimerTextShown: true ,
98
+ // Handles visibility of the Countdown Text.
99
+ isTimerTextShown: true ,
100
100
101
- // Handles the timer start.
102
- autoStart: false ,
101
+ // Handles the timer start.
102
+ autoStart: false ,
103
103
104
- // This Callback will execute when the Countdown Starts.
105
- onStart: () {
106
- // Here, do whatever you want
107
- debugPrint ('Countdown Started' );
108
- },
104
+ // This Callback will execute when the Countdown Starts.
105
+ onStart: () {
106
+ // Here, do whatever you want
107
+ debugPrint ('Countdown Started' );
108
+ },
109
109
110
- // This Callback will execute when the Countdown Ends.
111
- onComplete: () {
112
- // Here, do whatever you want
113
- debugPrint ('Countdown Ended' );
114
- },
115
- )),
110
+ // This Callback will execute when the Countdown Ends.
111
+ onComplete: () {
112
+ // Here, do whatever you want
113
+ debugPrint ('Countdown Ended' );
114
+ },
115
+
116
+ // This Callback will execute when the Countdown Changes.
117
+ onChange: (String timeStamp) {
118
+ // Here, do whatever you want
119
+ debugPrint ('Countdown Changed $timeStamp ' );
120
+ },
121
+ ),
122
+ ),
116
123
floatingActionButton: Row (
117
124
mainAxisAlignment: MainAxisAlignment .center,
118
125
children: [
119
126
const SizedBox (
120
127
width: 30 ,
121
128
),
122
- _button (title: "Start" , onPressed: () => _controller.start ()),
129
+ _button (
130
+ title: "Start" ,
131
+ onPressed: () => _controller.start (),
132
+ ),
123
133
const SizedBox (
124
134
width: 10 ,
125
135
),
126
- _button (title: "Pause" , onPressed: () => _controller.pause ()),
136
+ _button (
137
+ title: "Pause" ,
138
+ onPressed: () => _controller.pause (),
139
+ ),
127
140
const SizedBox (
128
141
width: 10 ,
129
142
),
130
- _button (title: "Resume" , onPressed: () => _controller.resume ()),
143
+ _button (
144
+ title: "Resume" ,
145
+ onPressed: () => _controller.resume (),
146
+ ),
131
147
const SizedBox (
132
148
width: 10 ,
133
149
),
134
150
_button (
135
- title: "Restart" ,
136
- onPressed: () => _controller.restart (duration: _duration))
151
+ title: "Restart" ,
152
+ onPressed: () => _controller.restart (duration: _duration),
153
+ ),
137
154
],
138
155
),
139
156
);
140
157
}
141
158
142
159
Widget _button ({required String title, VoidCallback ? onPressed}) {
143
160
return Expanded (
144
- child: ElevatedButton (
145
- child: Text (
146
- title,
147
- style: const TextStyle (color: Colors .white),
148
- ),
149
- style: ButtonStyle (
150
- backgroundColor: MaterialStateProperty .all (Colors .purple),
161
+ child: ElevatedButton (
162
+ style: ButtonStyle (
163
+ backgroundColor: MaterialStateProperty .all (Colors .purple),
164
+ ),
165
+ onPressed: onPressed,
166
+ child: Text (
167
+ title,
168
+ style: const TextStyle (color: Colors .white),
169
+ ),
151
170
),
152
- onPressed: onPressed,
153
- ));
171
+ );
154
172
}
155
173
}
0 commit comments