Migrate flutter_tools file_system to null safety (#78896)
diff --git a/packages/flutter_tools/lib/src/base/file_system.dart b/packages/flutter_tools/lib/src/base/file_system.dart index 38b8871..6cf75ad 100644 --- a/packages/flutter_tools/lib/src/base/file_system.dart +++ b/packages/flutter_tools/lib/src/base/file_system.dart
@@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart = 2.8 - import 'package:file/file.dart'; import 'package:file/local.dart' as local_fs; import 'package:meta/meta.dart'; @@ -31,8 +29,8 @@ /// Various convenience file system methods. class FileSystemUtils { FileSystemUtils({ - @required FileSystem fileSystem, - @required Platform platform, + required FileSystem fileSystem, + required Platform platform, }) : _fileSystem = fileSystem, _platform = platform; @@ -86,8 +84,8 @@ /// /// Returns false, if [entity] exists, but [referenceFile] does not. bool isOlderThanReference({ - @required FileSystemEntity entity, - @required File referenceFile, + required FileSystemEntity entity, + required File referenceFile, }) { if (!entity.existsSync()) { return true; @@ -97,8 +95,8 @@ } /// Return the absolute path of the user's home directory. - String get homeDirPath { - String path = _platform.isWindows + String? get homeDirPath { + String? path = _platform.isWindows ? _platform.environment['USERPROFILE'] : _platform.environment['HOME']; if (path != null) { @@ -123,8 +121,8 @@ void copyDirectory( Directory srcDir, Directory destDir, { - bool Function(File srcFile, File destFile) shouldCopyFile, - void Function(File srcFile, File destFile) onFileCopied, + bool Function(File srcFile, File destFile)? shouldCopyFile, + void Function(File srcFile, File destFile)? onFileCopied, }) { if (!srcDir.existsSync()) { throw Exception('Source directory "${srcDir.path}" does not exist, nothing to copy'); @@ -167,13 +165,13 @@ @visibleForTesting LocalFileSystem.test({ - @required Signals signals, + required Signals signals, List<ProcessSignal> fatalSignals = Signals.defaultExitSignals, }) : this(signals, fatalSignals, null); - Directory _systemTemp; + Directory? _systemTemp; final Map<ProcessSignal, Object> _signalTokens = <ProcessSignal, Object>{}; - final ShutdownHooks _shutdownHooks; + final ShutdownHooks? _shutdownHooks; Future<void> dispose() async { _tryToDeleteTemp(); @@ -189,7 +187,7 @@ void _tryToDeleteTemp() { try { if (_systemTemp?.existsSync() ?? false) { - _systemTemp.deleteSync(recursive: true); + _systemTemp?.deleteSync(recursive: true); } } on FileSystemException { // ignore. @@ -225,6 +223,6 @@ _tryToDeleteTemp, ); } - return _systemTemp; + return _systemTemp!; } }