Skip to content

Commit 6407c26

Browse files
Migrated Package to Flutter version 3.3.5. Fixed Warnings/Problems
1 parent 32eaa7b commit 6407c26

File tree

5 files changed

+84
-79
lines changed

5 files changed

+84
-79
lines changed

analysis_options.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include: package:flutter_lints/flutter.yaml
2+
3+
# Additional information about this file can be found at
4+
# https://dart.dev/guides/language/analysis-options

lib/circular_countdown_timer.dart

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1+
// ignore_for_file: constant_identifier_names
2+
13
library circular_countdown_timer;
24

35
import 'package:flutter/material.dart';
46
import 'custom_timer_painter.dart';
57

68
/// Create a Circular Countdown Timer.
79
class CircularCountDownTimer extends StatefulWidget {
8-
/// Key for Countdown Timer.
9-
final Key? key;
10-
1110
/// Filling Color for Countdown Widget.
1211
final Color fillColor;
1312

@@ -74,7 +73,7 @@ class CircularCountDownTimer extends StatefulWidget {
7473
/// Handles the timer start.
7574
final bool autoStart;
7675

77-
CircularCountDownTimer({
76+
const CircularCountDownTimer({
7877
required this.width,
7978
required this.height,
8079
required this.duration,
@@ -93,18 +92,15 @@ class CircularCountDownTimer extends StatefulWidget {
9392
this.strokeWidth = 5.0,
9493
this.strokeCap = StrokeCap.butt,
9594
this.textStyle,
96-
this.key,
95+
super.key,
9796
this.isTimerTextShown = true,
9897
this.autoStart = true,
9998
this.textFormat,
10099
this.controller,
101-
}) : assert(initialDuration <= duration),
102-
super(key: key);
100+
}) : assert(initialDuration <= duration);
103101

104102
@override
105-
CircularCountDownTimerState createState() => CircularCountDownTimerState(
106-
countDownController: controller ?? CountDownController(),
107-
);
103+
CircularCountDownTimerState createState() => CircularCountDownTimerState();
108104
}
109105

110106
class CircularCountDownTimerState extends State<CircularCountDownTimer>
@@ -113,8 +109,6 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
113109
Animation<double>? _countDownAnimation;
114110
CountDownController? countDownController;
115111

116-
CircularCountDownTimerState({this.countDownController});
117-
118112
String get time {
119113
String timeStamp = "";
120114
if (widget.isReverse &&
@@ -185,7 +179,7 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
185179
}
186180
// For ss format
187181
else if (widget.textFormat == CountdownTextFormat.SS) {
188-
return '${(duration.inSeconds).toString().padLeft(2, '0')}';
182+
return (duration.inSeconds).toString().padLeft(2, '0');
189183
}
190184
// For s format
191185
else if (widget.textFormat == CountdownTextFormat.S) {
@@ -216,6 +210,7 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
216210

217211
@override
218212
void initState() {
213+
countDownController = widget.controller ?? CountDownController();
219214
super.initState();
220215
_controller = AnimationController(
221216
vsync: this,
@@ -253,7 +248,7 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
253248

254249
@override
255250
Widget build(BuildContext context) {
256-
return Container(
251+
return SizedBox(
257252
width: widget.width,
258253
height: widget.height,
259254
child: AnimatedBuilder(
@@ -286,7 +281,7 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
286281
child: Text(
287282
time,
288283
style: widget.textStyle ??
289-
TextStyle(
284+
const TextStyle(
290285
fontSize: 16.0,
291286
color: Colors.black,
292287
),
@@ -311,71 +306,84 @@ class CircularCountDownTimerState extends State<CircularCountDownTimer>
311306

312307
/// Controls (i.e Start, Pause, Resume, Restart) the Countdown Timer.
313308
class CountDownController {
314-
late CircularCountDownTimerState _state;
315-
late bool _isReverse;
309+
CircularCountDownTimerState? _state;
310+
bool? _isReverse;
316311
bool isStarted = false, isPaused = false, isResumed = false;
317312
int? _initialDuration, _duration;
318313

319314
/// This Method Starts the Countdown Timer
320315
void start() {
321-
if (_isReverse) {
322-
_state._controller?.reverse(
323-
from:
324-
_initialDuration == 0 ? 1 : 1 - (_initialDuration! / _duration!));
325-
} else {
326-
_state._controller?.forward(
327-
from: _initialDuration == 0 ? 0 : (_initialDuration! / _duration!));
316+
if (_isReverse != null && _state != null && _state?._controller != null) {
317+
if (_isReverse!) {
318+
_state?._controller?.reverse(
319+
from: _initialDuration == 0
320+
? 1
321+
: 1 - (_initialDuration! / _duration!));
322+
} else {
323+
_state?._controller?.forward(
324+
from: _initialDuration == 0 ? 0 : (_initialDuration! / _duration!));
325+
}
326+
isStarted = true;
328327
}
329-
330-
isStarted = true;
331328
}
332329

333330
/// This Method Pauses the Countdown Timer
334331
void pause() {
335-
_state._controller?.stop(canceled: false);
336-
isPaused = true;
332+
if (_state != null && _state?._controller != null) {
333+
_state?._controller?.stop(canceled: false);
334+
isPaused = true;
335+
}
337336
}
338337

339338
/// This Method Resumes the Countdown Timer
340339
void resume() {
341-
if (_isReverse) {
342-
_state._controller?.reverse(from: _state._controller!.value);
343-
} else {
344-
_state._controller?.forward(from: _state._controller!.value);
340+
if (_isReverse != null && _state != null && _state?._controller != null) {
341+
if (_isReverse!) {
342+
_state?._controller?.reverse(from: _state!._controller!.value);
343+
} else {
344+
_state?._controller?.forward(from: _state!._controller!.value);
345+
}
346+
isResumed = true;
345347
}
346-
isResumed = true;
347348
}
348349

349350
/// This Method Restarts the Countdown Timer,
350351
/// Here optional int parameter **duration** is the updated duration for countdown timer
351352
352353
void restart({int? duration}) {
353-
_state._controller!.duration =
354-
Duration(seconds: duration ?? _state._controller!.duration!.inSeconds);
355-
if (_isReverse) {
356-
_state._controller?.reverse(from: 1);
357-
} else {
358-
_state._controller?.forward(from: 0);
354+
if (_isReverse != null && _state != null && _state?._controller != null) {
355+
_state?._controller!.duration = Duration(
356+
seconds: duration ?? _state!._controller!.duration!.inSeconds);
357+
if (_isReverse!) {
358+
_state?._controller?.reverse(from: 1);
359+
} else {
360+
_state?._controller?.forward(from: 0);
361+
}
362+
isStarted = true;
363+
isPaused = false;
364+
isResumed = false;
359365
}
360-
isStarted = true;
361-
isPaused = false;
362-
isResumed = false;
363366
}
364367

365368
/// This Method resets the Countdown Timer
366369
void reset() {
367-
_state._controller?.reset();
368-
isStarted = _state.widget.autoStart;
369-
isPaused = false;
370-
isResumed = false;
370+
if (_state != null && _state?._controller != null) {
371+
_state?._controller?.reset();
372+
isStarted = _state?.widget.autoStart ?? false;
373+
isPaused = false;
374+
isResumed = false;
375+
}
371376
}
372377

373378
/// This Method returns the **Current Time** of Countdown Timer i.e
374379
/// Time Used in terms of **Forward Countdown** and Time Left in terms of **Reverse Countdown**
375380
376-
String getTime() {
377-
return _state
378-
._getTime(_state._controller!.duration! * _state._controller!.value);
381+
String? getTime() {
382+
if (_state != null && _state?._controller != null) {
383+
return _state?._getTime(
384+
_state!._controller!.duration! * _state!._controller!.value);
385+
}
386+
return "";
379387
}
380388
}
381389

lib/custom_timer_painter.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class CustomTimerPainter extends CustomPainter {
3434
if (ringGradient != null) {
3535
final rect = Rect.fromCircle(
3636
center: size.center(Offset.zero), radius: size.width / 2);
37-
paint..shader = ringGradient!.createShader(rect);
37+
paint.shader = ringGradient!.createShader(rect);
3838
} else {
39-
paint..shader = null;
39+
paint.shader = null;
4040
}
4141

4242
canvas.drawCircle(size.center(Offset.zero), size.width / 2, paint);
@@ -52,9 +52,9 @@ class CustomTimerPainter extends CustomPainter {
5252
if (fillGradient != null) {
5353
final rect = Rect.fromCircle(
5454
center: size.center(Offset.zero), radius: size.width / 2);
55-
paint..shader = fillGradient!.createShader(rect);
55+
paint.shader = fillGradient!.createShader(rect);
5656
} else {
57-
paint..shader = null;
57+
paint.shader = null;
5858
paint.color = fillColor!;
5959
}
6060

@@ -66,7 +66,7 @@ class CustomTimerPainter extends CustomPainter {
6666
if (backgroundGradient != null) {
6767
final rect = Rect.fromCircle(
6868
center: size.center(Offset.zero), radius: size.width / 2.2);
69-
backgroundPaint..shader = backgroundGradient!.createShader(rect);
69+
backgroundPaint.shader = backgroundGradient!.createShader(rect);
7070
} else {
7171
backgroundPaint.color = backgroundColor!;
7272
}
@@ -76,9 +76,9 @@ class CustomTimerPainter extends CustomPainter {
7676
}
7777

7878
@override
79-
bool shouldRepaint(CustomTimerPainter old) {
80-
return animation!.value != old.animation!.value ||
81-
ringColor != old.ringColor ||
82-
fillColor != old.fillColor;
79+
bool shouldRepaint(CustomTimerPainter oldDelegate) {
80+
return animation!.value != oldDelegate.animation!.value ||
81+
ringColor != oldDelegate.ringColor ||
82+
fillColor != oldDelegate.fillColor;
8383
}
8484
}

pubspec.lock

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ packages:
77
name: async
88
url: "https://pub.dartlang.org"
99
source: hosted
10-
version: "2.8.2"
10+
version: "2.9.0"
1111
boolean_selector:
1212
dependency: transitive
1313
description:
@@ -21,21 +21,14 @@ packages:
2121
name: characters
2222
url: "https://pub.dartlang.org"
2323
source: hosted
24-
version: "1.2.0"
25-
charcode:
26-
dependency: transitive
27-
description:
28-
name: charcode
29-
url: "https://pub.dartlang.org"
30-
source: hosted
31-
version: "1.3.1"
24+
version: "1.2.1"
3225
clock:
3326
dependency: transitive
3427
description:
3528
name: clock
3629
url: "https://pub.dartlang.org"
3730
source: hosted
38-
version: "1.1.0"
31+
version: "1.1.1"
3932
collection:
4033
dependency: transitive
4134
description:
@@ -49,7 +42,7 @@ packages:
4942
name: fake_async
5043
url: "https://pub.dartlang.org"
5144
source: hosted
52-
version: "1.3.0"
45+
version: "1.3.1"
5346
flutter:
5447
dependency: "direct main"
5548
description: flutter
@@ -80,28 +73,28 @@ packages:
8073
name: matcher
8174
url: "https://pub.dartlang.org"
8275
source: hosted
83-
version: "0.12.11"
76+
version: "0.12.12"
8477
material_color_utilities:
8578
dependency: transitive
8679
description:
8780
name: material_color_utilities
8881
url: "https://pub.dartlang.org"
8982
source: hosted
90-
version: "0.1.4"
83+
version: "0.1.5"
9184
meta:
9285
dependency: transitive
9386
description:
9487
name: meta
9588
url: "https://pub.dartlang.org"
9689
source: hosted
97-
version: "1.7.0"
90+
version: "1.8.0"
9891
path:
9992
dependency: transitive
10093
description:
10194
name: path
10295
url: "https://pub.dartlang.org"
10396
source: hosted
104-
version: "1.8.1"
97+
version: "1.8.2"
10598
sky_engine:
10699
dependency: transitive
107100
description: flutter
@@ -113,7 +106,7 @@ packages:
113106
name: source_span
114107
url: "https://pub.dartlang.org"
115108
source: hosted
116-
version: "1.8.2"
109+
version: "1.9.0"
117110
stack_trace:
118111
dependency: transitive
119112
description:
@@ -134,21 +127,21 @@ packages:
134127
name: string_scanner
135128
url: "https://pub.dartlang.org"
136129
source: hosted
137-
version: "1.1.0"
130+
version: "1.1.1"
138131
term_glyph:
139132
dependency: transitive
140133
description:
141134
name: term_glyph
142135
url: "https://pub.dartlang.org"
143136
source: hosted
144-
version: "1.2.0"
137+
version: "1.2.1"
145138
test_api:
146139
dependency: transitive
147140
description:
148141
name: test_api
149142
url: "https://pub.dartlang.org"
150143
source: hosted
151-
version: "0.4.9"
144+
version: "0.4.12"
152145
vector_math:
153146
dependency: transitive
154147
description:
@@ -157,5 +150,5 @@ packages:
157150
source: hosted
158151
version: "2.1.2"
159152
sdks:
160-
dart: ">=2.17.3 <3.0.0"
153+
dart: ">=2.18.2 <3.0.0"
161154
flutter: ">=1.17.0"

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version: 0.2.2
44
homepage: https://github.com/MuhammadUsamaSiddiqui/circular_countdown_timer
55

66
environment:
7-
sdk: ">=2.17.3 <3.0.0"
7+
sdk: '>=2.18.2 <3.0.0'
88
flutter: ">=1.17.0"
99

1010
dependencies:

0 commit comments

Comments
 (0)