Skip to content
This repository was archived by the owner on Nov 1, 2024. It is now read-only.

Commit 2fbb4eb

Browse files
authored
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.
1 parent 50cc840 commit 2fbb4eb

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
## 0.3.0-nullsafety
1+
## 0.3.0-nullsafety.0
2+
23
- Updated to support 2.12.0 and null safety.
34

45
## 0.2.1

lib/cli_logging.dart

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,13 @@ class AnsiProgress extends Progress {
201201
final Ansi ansi;
202202

203203
int _index = 0;
204-
late Timer _timer;
204+
late final _timer = Timer.periodic(Duration(milliseconds: 80), (t) {
205+
_index++;
206+
_updateDisplay();
207+
});
205208

206209
AnsiProgress(this.ansi, String message) : super(message) {
207210
io.stdout.write('${message}... '.padRight(40));
208-
209-
_timer = Timer.periodic(Duration(milliseconds: 80), (t) {
210-
_index++;
211-
_updateDisplay();
212-
});
213-
214211
_updateDisplay();
215212
}
216213

@@ -258,12 +255,10 @@ class VerboseLogger implements Logger {
258255
@override
259256
Ansi ansi;
260257
bool logTime;
261-
late Stopwatch _timer;
258+
final _timer = Stopwatch()..start();
262259

263260
VerboseLogger({Ansi? ansi, this.logTime = false})
264-
: ansi = ansi ?? Ansi(Ansi.terminalSupportsAnsi) {
265-
_timer = Stopwatch()..start();
266-
}
261+
: ansi = ansi ?? Ansi(Ansi.terminalSupportsAnsi);
267262

268263
@override
269264
bool get isVerbose => true;

0 commit comments

Comments
 (0)