Unverified Commit 566c1d11 authored by James D. Lin's avatar James D. Lin Committed by GitHub

flutter_tools: Prefer using .of() over .from() when possible (#55250)

Prefer using `.of()` (which is statically type-checked) over
`.from()` (which is dynamically type-checked) when possible.
parent d2bd30e2
...@@ -37,7 +37,7 @@ Future<int> run( ...@@ -37,7 +37,7 @@ Future<int> run(
if (muteCommandLogging) { if (muteCommandLogging) {
// Remove the verbose option; for help and doctor, users don't need to see // Remove the verbose option; for help and doctor, users don't need to see
// verbose logs. // verbose logs.
args = List<String>.from(args); args = List<String>.of(args);
args.removeWhere((String option) => option == '-v' || option == '--verbose'); args.removeWhere((String option) => option == '-v' || option == '--verbose');
} }
......
...@@ -21,7 +21,7 @@ import 'android_studio.dart'; ...@@ -21,7 +21,7 @@ import 'android_studio.dart';
/// The environment variables needed to run Gradle. /// The environment variables needed to run Gradle.
Map<String, String> get gradleEnvironment { Map<String, String> get gradleEnvironment {
final Map<String, String> environment = Map<String, String>.from(globals.platform.environment); final Map<String, String> environment = Map<String, String>.of(globals.platform.environment);
if (javaPath != null) { if (javaPath != null) {
// Use java bundled with Android Studio. // Use java bundled with Android Studio.
environment['JAVA_HOME'] = javaPath; environment['JAVA_HOME'] = javaPath;
......
...@@ -28,7 +28,7 @@ class Fingerprinter { ...@@ -28,7 +28,7 @@ class Fingerprinter {
Iterable<String> depfilePaths = const <String>[], Iterable<String> depfilePaths = const <String>[],
FingerprintPathFilter pathFilter, FingerprintPathFilter pathFilter,
}) : _paths = paths.toList(), }) : _paths = paths.toList(),
_properties = Map<String, String>.from(properties), _properties = Map<String, String>.of(properties),
_depfilePaths = depfilePaths.toList(), _depfilePaths = depfilePaths.toList(),
_pathFilter = pathFilter, _pathFilter = pathFilter,
assert(fingerprintPath != null), assert(fingerprintPath != null),
......
...@@ -273,7 +273,7 @@ class AnsiTerminal implements Terminal { ...@@ -273,7 +273,7 @@ class AnsiTerminal implements Terminal {
List<String> charactersToDisplay = acceptedCharacters; List<String> charactersToDisplay = acceptedCharacters;
if (defaultChoiceIndex != null) { if (defaultChoiceIndex != null) {
assert(defaultChoiceIndex >= 0 && defaultChoiceIndex < acceptedCharacters.length); assert(defaultChoiceIndex >= 0 && defaultChoiceIndex < acceptedCharacters.length);
charactersToDisplay = List<String>.from(charactersToDisplay); charactersToDisplay = List<String>.of(charactersToDisplay);
charactersToDisplay[defaultChoiceIndex] = bolden(charactersToDisplay[defaultChoiceIndex]); charactersToDisplay[defaultChoiceIndex] = bolden(charactersToDisplay[defaultChoiceIndex]);
acceptedCharacters.add('\n'); acceptedCharacters.add('\n');
} }
......
...@@ -79,7 +79,7 @@ class ItemListNotifier<T> { ...@@ -79,7 +79,7 @@ class ItemListNotifier<T> {
} }
ItemListNotifier.from(List<T> items) { ItemListNotifier.from(List<T> items) {
_items = Set<T>.from(items); _items = Set<T>.of(items);
} }
Set<T> _items; Set<T> _items;
...@@ -93,7 +93,7 @@ class ItemListNotifier<T> { ...@@ -93,7 +93,7 @@ class ItemListNotifier<T> {
List<T> get items => _items.toList(); List<T> get items => _items.toList();
void updateWithNewList(List<T> updatedList) { void updateWithNewList(List<T> updatedList) {
final Set<T> updatedSet = Set<T>.from(updatedList); final Set<T> updatedSet = Set<T>.of(updatedList);
final Set<T> addedItems = updatedSet.difference(_items); final Set<T> addedItems = updatedSet.difference(_items);
final Set<T> removedItems = _items.difference(updatedSet); final Set<T> removedItems = _items.difference(updatedSet);
......
...@@ -54,7 +54,7 @@ class AnalyzeOnce extends AnalyzeBase { ...@@ -54,7 +54,7 @@ class AnalyzeOnce extends AnalyzeBase {
(workingDirectory ?? fileSystem.currentDirectory).path; (workingDirectory ?? fileSystem.currentDirectory).path;
// find directories from argResults.rest // find directories from argResults.rest
final Set<String> directories = Set<String>.from(argResults.rest final Set<String> directories = Set<String>.of(argResults.rest
.map<String>((String path) => fileSystem.path.canonicalize(path))); .map<String>((String path) => fileSystem.path.canonicalize(path)));
if (directories.isNotEmpty) { if (directories.isNotEmpty) {
for (final String directory in directories) { for (final String directory in directories) {
......
...@@ -1290,7 +1290,7 @@ class PubDependencyTree { ...@@ -1290,7 +1290,7 @@ class PubDependencyTree {
dependencies = const <String>[]; dependencies = const <String>[];
} }
_versions[package] = version; _versions[package] = version;
_dependencyTree[package] = Set<String>.from(dependencies); _dependencyTree[package] = Set<String>.of(dependencies);
} }
} }
return null; return null;
......
...@@ -139,7 +139,7 @@ abstract class DesktopDevice extends Device { ...@@ -139,7 +139,7 @@ abstract class DesktopDevice extends Device {
bool succeeded = true; bool succeeded = true;
// Walk a copy of _runningProcesses, since the exit handler removes from the // Walk a copy of _runningProcesses, since the exit handler removes from the
// set. // set.
for (final Process process in Set<Process>.from(_runningProcesses)) { for (final Process process in Set<Process>.of(_runningProcesses)) {
succeeded &= process.kill(); succeeded &= process.kill();
} }
return succeeded; return succeeded;
......
...@@ -293,7 +293,7 @@ class _DevFSHttpWriter { ...@@ -293,7 +293,7 @@ class _DevFSHttpWriter {
Future<void> write(Map<Uri, DevFSContent> entries) async { Future<void> write(Map<Uri, DevFSContent> entries) async {
_client.maxConnectionsPerHost = kMaxInFlight; _client.maxConnectionsPerHost = kMaxInFlight;
_completer = Completer<void>(); _completer = Completer<void>();
_outstanding = Map<Uri, DevFSContent>.from(entries); _outstanding = Map<Uri, DevFSContent>.of(entries);
_scheduleWrites(); _scheduleWrites();
await _completer.future; await _completer.future;
} }
......
...@@ -131,7 +131,7 @@ Future<void> _buildAssets( ...@@ -131,7 +131,7 @@ Future<void> _buildAssets(
); );
final Map<String, DevFSContent> assetEntries = final Map<String, DevFSContent> assetEntries =
Map<String, DevFSContent>.from(assets.entries); Map<String, DevFSContent>.of(assets.entries);
await writeBundle(globals.fs.directory(assetDir), assetEntries); await writeBundle(globals.fs.directory(assetDir), assetEntries);
final String appName = fuchsiaProject.project.manifest.appName; final String appName = fuchsiaProject.project.manifest.appName;
......
...@@ -809,7 +809,7 @@ class _FuchsiaPortForwarder extends DevicePortForwarder { ...@@ -809,7 +809,7 @@ class _FuchsiaPortForwarder extends DevicePortForwarder {
@override @override
Future<void> dispose() async { Future<void> dispose() async {
final List<ForwardedPort> forwardedPortsCopy = final List<ForwardedPort> forwardedPortsCopy =
List<ForwardedPort>.from(forwardedPorts); List<ForwardedPort>.of(forwardedPorts);
for (final ForwardedPort port in forwardedPortsCopy) { for (final ForwardedPort port in forwardedPortsCopy) {
await unforward(port); await unforward(port);
} }
......
...@@ -47,7 +47,7 @@ class IOSDeploy { ...@@ -47,7 +47,7 @@ class IOSDeploy {
// Python script that uses package 'six'. LLDB.framework relies on the // Python script that uses package 'six'. LLDB.framework relies on the
// python at the front of the path, which may not include package 'six'. // python at the front of the path, which may not include package 'six'.
// Ensure that we pick up the system install of python, which includes it. // Ensure that we pick up the system install of python, which includes it.
final Map<String, String> environment = Map<String, String>.from(_platform.environment); final Map<String, String> environment = Map<String, String>.of(_platform.environment);
environment['PATH'] = '/usr/bin:${environment['PATH']}'; environment['PATH'] = '/usr/bin:${environment['PATH']}';
environment.addEntries(<MapEntry<String, String>>[_cache.dyLdLibEntry]); environment.addEntries(<MapEntry<String, String>>[_cache.dyLdLibEntry]);
return environment; return environment;
......
...@@ -342,7 +342,7 @@ Future<XcodeBuildResult> buildXcodeProject({ ...@@ -342,7 +342,7 @@ Future<XcodeBuildResult> buildXcodeProject({
// it a lot of wiggle room (locally on Flutter Gallery, this takes ~1s). // it a lot of wiggle room (locally on Flutter Gallery, this takes ~1s).
// When there is a timeout, we retry once. See issue #35988. // When there is a timeout, we retry once. See issue #35988.
final List<String> showBuildSettingsCommand = (List<String> final List<String> showBuildSettingsCommand = (List<String>
.from(buildCommands) .of(buildCommands)
..add('-showBuildSettings')) ..add('-showBuildSettings'))
// Undocumented behavior: xcodebuild craps out if -showBuildSettings // Undocumented behavior: xcodebuild craps out if -showBuildSettings
// is used together with -allowProvisioningUpdates or // is used together with -allowProvisioningUpdates or
......
...@@ -897,7 +897,7 @@ class _IOSSimulatorDevicePortForwarder extends DevicePortForwarder { ...@@ -897,7 +897,7 @@ class _IOSSimulatorDevicePortForwarder extends DevicePortForwarder {
@override @override
Future<void> dispose() async { Future<void> dispose() async {
final List<ForwardedPort> portsCopy = List<ForwardedPort>.from(_ports); final List<ForwardedPort> portsCopy = List<ForwardedPort>.of(_ports);
for (final ForwardedPort port in portsCopy) { for (final ForwardedPort port in portsCopy) {
await unforward(port); await unforward(port);
} }
......
...@@ -108,7 +108,7 @@ class FlutterProject { ...@@ -108,7 +108,7 @@ class FlutterProject {
example.android.applicationId, example.android.applicationId,
await example.ios.productBundleIdentifier, await example.ios.productBundleIdentifier,
]; ];
return Set<String>.from(candidates return Set<String>.of(candidates
.map<String>(_organizationNameFromPackageName) .map<String>(_organizationNameFromPackageName)
.where((String name) => name != null)); .where((String name) => name != null));
} }
......
...@@ -102,7 +102,7 @@ Future<void> downloadStartupTrace(VMService observatory, { bool awaitFirstFrame ...@@ -102,7 +102,7 @@ Future<void> downloadStartupTrace(VMService observatory, { bool awaitFirstFrame
int extractInstantEventTimestamp(String eventName) { int extractInstantEventTimestamp(String eventName) {
final List<Map<String, dynamic>> events = final List<Map<String, dynamic>> events =
List<Map<String, dynamic>>.from((timeline['traceEvents'] as List<dynamic>).cast<Map<String, dynamic>>()); List<Map<String, dynamic>>.from(timeline['traceEvents'] as List<dynamic>);
final Map<String, dynamic> event = events.firstWhere( final Map<String, dynamic> event = events.firstWhere(
(Map<String, dynamic> event) => event['name'] == eventName, orElse: () => null, (Map<String, dynamic> event) => event['name'] == eventName, orElse: () => null,
); );
......
...@@ -362,7 +362,7 @@ void main() { ...@@ -362,7 +362,7 @@ void main() {
}, },
'files': <String, dynamic>{}, 'files': <String, dynamic>{},
}; };
final Map<String, dynamic> b = Map<String, dynamic>.from(a); final Map<String, dynamic> b = Map<String, dynamic>.of(a);
b['properties'] = <String, String>{ b['properties'] = <String, String>{
'buildMode': BuildMode.release.toString(), 'buildMode': BuildMode.release.toString(),
}; };
...@@ -380,7 +380,7 @@ void main() { ...@@ -380,7 +380,7 @@ void main() {
'b.dart': '6f144e08b58cd0925328610fad7ac07c', 'b.dart': '6f144e08b58cd0925328610fad7ac07c',
}, },
}; };
final Map<String, dynamic> b = Map<String, dynamic>.from(a); final Map<String, dynamic> b = Map<String, dynamic>.of(a);
b['files'] = <String, dynamic>{ b['files'] = <String, dynamic>{
'a.dart': '8a21a15fad560b799f6731d436c1b698', 'a.dart': '8a21a15fad560b799f6731d436c1b698',
'b.dart': '6f144e08b58cd0925328610fad7ac07d', 'b.dart': '6f144e08b58cd0925328610fad7ac07d',
...@@ -399,7 +399,7 @@ void main() { ...@@ -399,7 +399,7 @@ void main() {
'b.dart': '6f144e08b58cd0925328610fad7ac07c', 'b.dart': '6f144e08b58cd0925328610fad7ac07c',
}, },
}; };
final Map<String, dynamic> b = Map<String, dynamic>.from(a); final Map<String, dynamic> b = Map<String, dynamic>.of(a);
b['files'] = <String, dynamic>{ b['files'] = <String, dynamic>{
'a.dart': '8a21a15fad560b799f6731d436c1b698', 'a.dart': '8a21a15fad560b799f6731d436c1b698',
'c.dart': '6f144e08b58cd0925328610fad7ac07d', 'c.dart': '6f144e08b58cd0925328610fad7ac07d',
......
...@@ -387,7 +387,7 @@ void main() { ...@@ -387,7 +387,7 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isPrerelease'] = true; ..['isPrerelease'] = true;
setMockCompatibleVisualStudioInstallation( setMockCompatibleVisualStudioInstallation(
null, null,
...@@ -448,7 +448,7 @@ void main() { ...@@ -448,7 +448,7 @@ void main() {
fixture.processManager, fixture.processManager,
); );
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isComplete'] = false; ..['isComplete'] = false;
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
response, response,
...@@ -476,7 +476,7 @@ void main() { ...@@ -476,7 +476,7 @@ void main() {
fixture.processManager, fixture.processManager,
); );
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isLaunchable'] = false; ..['isLaunchable'] = false;
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
response, response,
...@@ -503,7 +503,7 @@ void main() { ...@@ -503,7 +503,7 @@ void main() {
fixture.processManager, fixture.processManager,
); );
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isRebootRequired'] = true; ..['isRebootRequired'] = true;
setMockAnyVisualStudioInstallation( setMockAnyVisualStudioInstallation(
response, response,
...@@ -565,7 +565,7 @@ void main() { ...@@ -565,7 +565,7 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isRebootRequired'] = true; ..['isRebootRequired'] = true;
setMockCompatibleVisualStudioInstallation( setMockCompatibleVisualStudioInstallation(
response, response,
...@@ -585,7 +585,7 @@ void main() { ...@@ -585,7 +585,7 @@ void main() {
final VisualStudioFixture fixture = setUpVisualStudio(); final VisualStudioFixture fixture = setUpVisualStudio();
final VisualStudio visualStudio = fixture.visualStudio; final VisualStudio visualStudio = fixture.visualStudio;
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse) final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
..['isRebootRequired'] = true; ..['isRebootRequired'] = true;
setMockCompatibleVisualStudioInstallation( setMockCompatibleVisualStudioInstallation(
response, response,
......
...@@ -585,7 +585,7 @@ class BasicMock { ...@@ -585,7 +585,7 @@ class BasicMock {
final List<String> messages = <String>[]; final List<String> messages = <String>[];
void expectMessages(List<String> expectedMessages) { void expectMessages(List<String> expectedMessages) {
final List<String> actualMessages = List<String>.from(messages); final List<String> actualMessages = List<String>.of(messages);
messages.clear(); messages.clear();
expect(actualMessages, unorderedEquals(expectedMessages)); expect(actualMessages, unorderedEquals(expectedMessages));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment