Use late final for _timer fields (#53)
The field in `AnsiProgress`had been non-final so that it could be
initialized in the constructor, the initialization expression needs
access to `this`. With null safety this pattern can be expressed with a
`late final` field.
The field in `VerboseLogger` could have been `final` before the
migration.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 546b78e..4b6d8ce 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,5 @@
-## 0.3.0-nullsafety
+## 0.3.0-nullsafety.0
+
- Updated to support 2.12.0 and null safety.
## 0.2.1
diff --git a/lib/cli_logging.dart b/lib/cli_logging.dart
index 106d51e..ae03fa1 100644
--- a/lib/cli_logging.dart
+++ b/lib/cli_logging.dart
@@ -201,16 +201,13 @@
final Ansi ansi;
int _index = 0;
- late Timer _timer;
+ late final _timer = Timer.periodic(Duration(milliseconds: 80), (t) {
+ _index++;
+ _updateDisplay();
+ });
AnsiProgress(this.ansi, String message) : super(message) {
io.stdout.write('${message}... '.padRight(40));
-
- _timer = Timer.periodic(Duration(milliseconds: 80), (t) {
- _index++;
- _updateDisplay();
- });
-
_updateDisplay();
}
@@ -258,12 +255,10 @@
@override
Ansi ansi;
bool logTime;
- late Stopwatch _timer;
+ final _timer = Stopwatch()..start();
VerboseLogger({Ansi? ansi, this.logTime = false})
- : ansi = ansi ?? Ansi(Ansi.terminalSupportsAnsi) {
- _timer = Stopwatch()..start();
- }
+ : ansi = ansi ?? Ansi(Ansi.terminalSupportsAnsi);
@override
bool get isVerbose => true;