Use ?. over explicit null check (dart-lang/watcher#85)
diff --git a/pkgs/watcher/lib/src/directory_watcher/linux.dart b/pkgs/watcher/lib/src/directory_watcher/linux.dart index 0a66a12..7348cb4 100644 --- a/pkgs/watcher/lib/src/directory_watcher/linux.dart +++ b/pkgs/watcher/lib/src/directory_watcher/linux.dart
@@ -262,7 +262,7 @@ StreamSubscription subscription; subscription = stream.listen(onData, onError: onError, onDone: () { _subscriptions.remove(subscription); - if (onDone != null) onDone(); + onDone?.call(); }, cancelOnError: cancelOnError); _subscriptions.add(subscription); }
diff --git a/pkgs/watcher/lib/src/directory_watcher/mac_os.dart b/pkgs/watcher/lib/src/directory_watcher/mac_os.dart index 0aa0566..4408ff1 100644 --- a/pkgs/watcher/lib/src/directory_watcher/mac_os.dart +++ b/pkgs/watcher/lib/src/directory_watcher/mac_os.dart
@@ -95,8 +95,8 @@ @override void close() { - if (_watchSubscription != null) _watchSubscription.cancel(); - if (_initialListSubscription != null) _initialListSubscription.cancel(); + _watchSubscription?.cancel(); + _initialListSubscription?.cancel(); _watchSubscription = null; _initialListSubscription = null; @@ -365,7 +365,7 @@ /// of its state. Future _listDir() { assert(!isReady); - if (_initialListSubscription != null) _initialListSubscription.cancel(); + _initialListSubscription?.cancel(); _files.clear(); var completer = Completer();
diff --git a/pkgs/watcher/lib/src/directory_watcher/polling.dart b/pkgs/watcher/lib/src/directory_watcher/polling.dart index 388f28a..902e8b8 100644 --- a/pkgs/watcher/lib/src/directory_watcher/polling.dart +++ b/pkgs/watcher/lib/src/directory_watcher/polling.dart
@@ -92,7 +92,7 @@ _events.close(); // If we're in the middle of listing the directory, stop. - if (_listSubscription != null) _listSubscription.cancel(); + _listSubscription?.cancel(); // Don't process any remaining files. _filesToProcess.clear();
diff --git a/pkgs/watcher/lib/src/directory_watcher/windows.dart b/pkgs/watcher/lib/src/directory_watcher/windows.dart index 9a7de5f..f5093c5 100644 --- a/pkgs/watcher/lib/src/directory_watcher/windows.dart +++ b/pkgs/watcher/lib/src/directory_watcher/windows.dart
@@ -32,9 +32,7 @@ void addEvent(FileSystemEvent event, void Function() callback) { events.add(event); - if (timer != null) { - timer.cancel(); - } + timer?.cancel(); timer = Timer(_BATCH_DELAY, callback); } @@ -102,9 +100,9 @@ @override void close() { - if (_watchSubscription != null) _watchSubscription.cancel(); - if (_parentWatchSubscription != null) _parentWatchSubscription.cancel(); - if (_initialListSubscription != null) _initialListSubscription.cancel(); + _watchSubscription?.cancel(); + _parentWatchSubscription?.cancel(); + _initialListSubscription?.cancel(); for (var sub in _listSubscriptions) { sub.cancel(); } @@ -401,7 +399,7 @@ /// of its state. Future<void> _listDir() { assert(!isReady); - if (_initialListSubscription != null) _initialListSubscription.cancel(); + _initialListSubscription?.cancel(); _files.clear(); var completer = Completer();
diff --git a/pkgs/watcher/lib/src/file_watcher/native.dart b/pkgs/watcher/lib/src/file_watcher/native.dart index 7f466af..0b42cb9 100644 --- a/pkgs/watcher/lib/src/file_watcher/native.dart +++ b/pkgs/watcher/lib/src/file_watcher/native.dart
@@ -83,7 +83,7 @@ @override void close() { - if (_subscription != null) _subscription.cancel(); + _subscription?.cancel(); _subscription = null; _eventsController.close(); }