From 1101d85fc42404247ea0aeec32f22e3af9966d04 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Mon, 9 Nov 2020 13:52:19 -0800 Subject: [PATCH 1/2] Use late final for _timer fields 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. Append `-dev` to the version since this can't be published until it is rolled and validated internally. --- CHANGELOG.md | 3 ++- lib/cli_logging.dart | 17 ++++++----------- pubspec.yaml | 2 +- 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 546b78e..01be2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ -## 0.3.0-nullsafety +## 0.3.0-nullsafety.0-dev + - 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 @@ class AnsiProgress extends Progress { 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 @@ class VerboseLogger implements Logger { @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; diff --git a/pubspec.yaml b/pubspec.yaml index fbf3018..d5f002a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: cli_util -version: 0.3.0-nullsafety.0 +version: 0.3.0-nullsafety.0-dev description: A library to help in building Dart command-line apps. homepage: https://github.com/dart-lang/cli_util From 1663fc5e11f71b3c0ecfa9a9712175ba69bb1481 Mon Sep 17 00:00:00 2001 From: Nate Bosch Date: Mon, 9 Nov 2020 15:03:17 -0800 Subject: [PATCH 2/2] Don't add -dev Optimistically we'll publish right after validation. --- CHANGELOG.md | 2 +- pubspec.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01be2f3..4b6d8ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.3.0-nullsafety.0-dev +## 0.3.0-nullsafety.0 - Updated to support 2.12.0 and null safety. diff --git a/pubspec.yaml b/pubspec.yaml index d5f002a..fbf3018 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: cli_util -version: 0.3.0-nullsafety.0-dev +version: 0.3.0-nullsafety.0 description: A library to help in building Dart command-line apps. homepage: https://github.com/dart-lang/cli_util