From ce31d4ff7e0cf7f202e0d448e449db4be250b6d9 Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Wed, 24 Mar 2021 15:18:00 -0700 Subject: [PATCH] Migrate android_console to null safety (#78923) --- .../lib/src/android/android_console.dart | 17 +++++----- .../lib/src/base/project_migrator.dart | 2 -- .../flutter_tools/lib/src/base/utils.dart | 1 - .../flutter_tools/lib/src/ios/iproxy.dart | 15 ++++---- .../lib/src/ios/plist_parser.dart | 13 +++---- packages/flutter_tools/test/src/io.dart | 34 +++++++++---------- .../flutter_tools/test/src/test_wrapper.dart | 2 -- 7 files changed, 35 insertions(+), 49 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/android_console.dart b/packages/flutter_tools/lib/src/android/android_console.dart index 69d5e7cfea..252208ecdb 100644 --- a/packages/flutter_tools/lib/src/android/android_console.dart +++ b/packages/flutter_tools/lib/src/android/android_console.dart @@ -2,9 +2,8 @@ // 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:async/async.dart'; + import '../base/io.dart'; import '../convert.dart'; @@ -28,20 +27,20 @@ typedef AndroidConsoleSocketFactory = Future Function(String host, int p class AndroidConsole { AndroidConsole(this._socket); - Socket _socket; - StreamQueue _queue; + Socket? _socket; + StreamQueue? _queue; Future connect() async { assert(_socket != null); assert(_queue == null); - _queue = StreamQueue(_socket.asyncMap(ascii.decode)); + _queue = StreamQueue(_socket!.asyncMap(ascii.decode)); // Discard any initial connection text. await _readResponse(); } - Future getAvdName() async { + Future getAvdName() async { if (_queue == null) { return null; } @@ -55,17 +54,17 @@ class AndroidConsole { _queue = null; } - Future _readResponse() async { + Future _readResponse() async { if (_queue == null) { return null; } final StringBuffer output = StringBuffer(); while (true) { - if (!await _queue.hasNext) { + if (!await _queue!.hasNext) { destroy(); return null; } - final String text = await _queue.next; + final String text = await _queue!.next; final String trimmedText = text.trim(); if (trimmedText == 'OK') { break; diff --git a/packages/flutter_tools/lib/src/base/project_migrator.dart b/packages/flutter_tools/lib/src/base/project_migrator.dart index e81e3508db..1ba453f44e 100644 --- a/packages/flutter_tools/lib/src/base/project_migrator.dart +++ b/packages/flutter_tools/lib/src/base/project_migrator.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:meta/meta.dart'; import 'file_system.dart'; diff --git a/packages/flutter_tools/lib/src/base/utils.dart b/packages/flutter_tools/lib/src/base/utils.dart index 9179e14aba..518aa7a1c2 100644 --- a/packages/flutter_tools/lib/src/base/utils.dart +++ b/packages/flutter_tools/lib/src/base/utils.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - import 'dart:async'; import 'dart:math' as math; diff --git a/packages/flutter_tools/lib/src/ios/iproxy.dart b/packages/flutter_tools/lib/src/ios/iproxy.dart index 6ce94554ee..3a3facd2e9 100644 --- a/packages/flutter_tools/lib/src/ios/iproxy.dart +++ b/packages/flutter_tools/lib/src/ios/iproxy.dart @@ -2,9 +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:meta/meta.dart'; import 'package:process/process.dart'; import '../base/io.dart'; @@ -16,10 +13,10 @@ import '../base/process.dart'; /// See https://github.com/libimobiledevice/libusbmuxd. class IProxy { IProxy({ - @required String iproxyPath, - @required Logger logger, - @required ProcessManager processManager, - @required MapEntry dyLdLibEntry, + required String iproxyPath, + required Logger logger, + required ProcessManager processManager, + required MapEntry dyLdLibEntry, }) : _dyLdLibEntry = dyLdLibEntry, _processUtils = ProcessUtils(processManager: processManager, logger: logger), _iproxyPath = iproxyPath; @@ -29,8 +26,8 @@ class IProxy { /// This specifies the path to iproxy as 'iproxy` and the dyLdLibEntry as /// 'DYLD_LIBRARY_PATH: /path/to/libs'. factory IProxy.test({ - @required Logger logger, - @required ProcessManager processManager, + required Logger logger, + required ProcessManager processManager, }) { return IProxy( iproxyPath: 'iproxy', diff --git a/packages/flutter_tools/lib/src/ios/plist_parser.dart b/packages/flutter_tools/lib/src/ios/plist_parser.dart index 46efe26132..242c42ae12 100644 --- a/packages/flutter_tools/lib/src/ios/plist_parser.dart +++ b/packages/flutter_tools/lib/src/ios/plist_parser.dart @@ -2,9 +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:meta/meta.dart'; import 'package:process/process.dart'; import '../base/file_system.dart'; @@ -16,9 +13,9 @@ import '../convert.dart'; class PlistParser { PlistParser({ - @required FileSystem fileSystem, - @required Logger logger, - @required ProcessManager processManager, + required FileSystem fileSystem, + required Logger logger, + required ProcessManager processManager, }) : _fileSystem = fileSystem, _logger = logger, _processUtils = ProcessUtils(logger: logger, processManager: processManager); @@ -58,7 +55,7 @@ class PlistParser { args, throwOnError: true, ).stdout.trim(); - return castStringKeyedMap(json.decode(jsonContent)); + return castStringKeyedMap(json.decode(jsonContent)) ?? const {}; } on ProcessException catch (error) { _logger.printTrace('$error'); return const {}; @@ -74,7 +71,7 @@ class PlistParser { /// If [key] is not found in the property list, this will return null. /// /// The [plistFilePath] and [key] arguments must not be null. - String getValueFromFile(String plistFilePath, String key) { + String? getValueFromFile(String plistFilePath, String key) { assert(key != null); final Map parsed = parseFile(plistFilePath); return parsed[key] as String; diff --git a/packages/flutter_tools/test/src/io.dart b/packages/flutter_tools/test/src/io.dart index 2bfbd40b52..2a83448c2a 100644 --- a/packages/flutter_tools/test/src/io.dart +++ b/packages/flutter_tools/test/src/io.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 'dart:io' as io show IOOverrides, Directory, File, Link; import 'package:flutter_tools/src/base/file_system.dart'; @@ -19,17 +17,17 @@ import 'package:flutter_tools/src/base/file_system.dart'; /// The only safe delegate types are those that do not call out to `dart:io`, /// like the [MemoryFileSystem]. class FlutterIOOverrides extends io.IOOverrides { - FlutterIOOverrides({ FileSystem fileSystem }) + FlutterIOOverrides({ FileSystem? fileSystem }) : _fileSystemDelegate = fileSystem; - final FileSystem _fileSystemDelegate; + final FileSystem? _fileSystemDelegate; @override io.Directory createDirectory(String path) { if (_fileSystemDelegate == null) { return super.createDirectory(path); } - return _fileSystemDelegate.directory(path); + return _fileSystemDelegate!.directory(path); } @override @@ -37,7 +35,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.createFile(path); } - return _fileSystemDelegate.file(path); + return _fileSystemDelegate!.file(path); } @override @@ -45,7 +43,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.createLink(path); } - return _fileSystemDelegate.link(path); + return _fileSystemDelegate!.link(path); } @override @@ -53,7 +51,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.fsWatch(path, events, recursive); } - return _fileSystemDelegate.file(path).watch(events: events, recursive: recursive); + return _fileSystemDelegate!.file(path).watch(events: events, recursive: recursive); } @override @@ -61,7 +59,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.fsWatchIsSupported(); } - return _fileSystemDelegate.isWatchSupported; + return _fileSystemDelegate!.isWatchSupported; } @override @@ -69,7 +67,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.fseGetType(path, followLinks); } - return _fileSystemDelegate.type(path, followLinks: followLinks ?? true); + return _fileSystemDelegate!.type(path, followLinks: followLinks); } @override @@ -77,7 +75,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.fseGetTypeSync(path, followLinks); } - return _fileSystemDelegate.typeSync(path, followLinks: followLinks ?? true); + return _fileSystemDelegate!.typeSync(path, followLinks: followLinks); } @override @@ -85,7 +83,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.fseIdentical(path1, path2); } - return _fileSystemDelegate.identical(path1, path2); + return _fileSystemDelegate!.identical(path1, path2); } @override @@ -93,7 +91,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.fseIdenticalSync(path1, path2); } - return _fileSystemDelegate.identicalSync(path1, path2); + return _fileSystemDelegate!.identicalSync(path1, path2); } @override @@ -101,7 +99,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.getCurrentDirectory(); } - return _fileSystemDelegate.currentDirectory; + return _fileSystemDelegate!.currentDirectory; } @override @@ -109,7 +107,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.getSystemTempDirectory(); } - return _fileSystemDelegate.systemTempDirectory; + return _fileSystemDelegate!.systemTempDirectory; } @override @@ -117,7 +115,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.setCurrentDirectory(path); } - _fileSystemDelegate.currentDirectory = path; + _fileSystemDelegate!.currentDirectory = path; } @override @@ -125,7 +123,7 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.stat(path); } - return _fileSystemDelegate.stat(path); + return _fileSystemDelegate!.stat(path); } @override @@ -133,6 +131,6 @@ class FlutterIOOverrides extends io.IOOverrides { if (_fileSystemDelegate == null) { return super.statSync(path); } - return _fileSystemDelegate.statSync(path); + return _fileSystemDelegate!.statSync(path); } } diff --git a/packages/flutter_tools/test/src/test_wrapper.dart b/packages/flutter_tools/test/src/test_wrapper.dart index 4158114b50..cd6fd458da 100644 --- a/packages/flutter_tools/test/src/test_wrapper.dart +++ b/packages/flutter_tools/test/src/test_wrapper.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:test/test.dart' hide isInstanceOf; export 'package:test/test.dart' hide isInstanceOf;