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.
This commit is contained in:
@@ -37,7 +37,7 @@ Future<int> run(
|
||||
if (muteCommandLogging) {
|
||||
// Remove the verbose option; for help and doctor, users don't need to see
|
||||
// verbose logs.
|
||||
args = List<String>.from(args);
|
||||
args = List<String>.of(args);
|
||||
args.removeWhere((String option) => option == '-v' || option == '--verbose');
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import 'android_studio.dart';
|
||||
|
||||
/// The environment variables needed to run Gradle.
|
||||
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) {
|
||||
// Use java bundled with Android Studio.
|
||||
environment['JAVA_HOME'] = javaPath;
|
||||
|
||||
@@ -28,7 +28,7 @@ class Fingerprinter {
|
||||
Iterable<String> depfilePaths = const <String>[],
|
||||
FingerprintPathFilter pathFilter,
|
||||
}) : _paths = paths.toList(),
|
||||
_properties = Map<String, String>.from(properties),
|
||||
_properties = Map<String, String>.of(properties),
|
||||
_depfilePaths = depfilePaths.toList(),
|
||||
_pathFilter = pathFilter,
|
||||
assert(fingerprintPath != null),
|
||||
|
||||
@@ -273,7 +273,7 @@ class AnsiTerminal implements Terminal {
|
||||
List<String> charactersToDisplay = acceptedCharacters;
|
||||
if (defaultChoiceIndex != null) {
|
||||
assert(defaultChoiceIndex >= 0 && defaultChoiceIndex < acceptedCharacters.length);
|
||||
charactersToDisplay = List<String>.from(charactersToDisplay);
|
||||
charactersToDisplay = List<String>.of(charactersToDisplay);
|
||||
charactersToDisplay[defaultChoiceIndex] = bolden(charactersToDisplay[defaultChoiceIndex]);
|
||||
acceptedCharacters.add('\n');
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class ItemListNotifier<T> {
|
||||
}
|
||||
|
||||
ItemListNotifier.from(List<T> items) {
|
||||
_items = Set<T>.from(items);
|
||||
_items = Set<T>.of(items);
|
||||
}
|
||||
|
||||
Set<T> _items;
|
||||
@@ -93,7 +93,7 @@ class ItemListNotifier<T> {
|
||||
List<T> get items => _items.toList();
|
||||
|
||||
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> removedItems = _items.difference(updatedSet);
|
||||
|
||||
@@ -54,7 +54,7 @@ class AnalyzeOnce extends AnalyzeBase {
|
||||
(workingDirectory ?? fileSystem.currentDirectory).path;
|
||||
|
||||
// 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)));
|
||||
if (directories.isNotEmpty) {
|
||||
for (final String directory in directories) {
|
||||
|
||||
@@ -1290,7 +1290,7 @@ class PubDependencyTree {
|
||||
dependencies = const <String>[];
|
||||
}
|
||||
_versions[package] = version;
|
||||
_dependencyTree[package] = Set<String>.from(dependencies);
|
||||
_dependencyTree[package] = Set<String>.of(dependencies);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -139,7 +139,7 @@ abstract class DesktopDevice extends Device {
|
||||
bool succeeded = true;
|
||||
// Walk a copy of _runningProcesses, since the exit handler removes from the
|
||||
// set.
|
||||
for (final Process process in Set<Process>.from(_runningProcesses)) {
|
||||
for (final Process process in Set<Process>.of(_runningProcesses)) {
|
||||
succeeded &= process.kill();
|
||||
}
|
||||
return succeeded;
|
||||
|
||||
@@ -293,7 +293,7 @@ class _DevFSHttpWriter {
|
||||
Future<void> write(Map<Uri, DevFSContent> entries) async {
|
||||
_client.maxConnectionsPerHost = kMaxInFlight;
|
||||
_completer = Completer<void>();
|
||||
_outstanding = Map<Uri, DevFSContent>.from(entries);
|
||||
_outstanding = Map<Uri, DevFSContent>.of(entries);
|
||||
_scheduleWrites();
|
||||
await _completer.future;
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ Future<void> _buildAssets(
|
||||
);
|
||||
|
||||
final Map<String, DevFSContent> assetEntries =
|
||||
Map<String, DevFSContent>.from(assets.entries);
|
||||
Map<String, DevFSContent>.of(assets.entries);
|
||||
await writeBundle(globals.fs.directory(assetDir), assetEntries);
|
||||
|
||||
final String appName = fuchsiaProject.project.manifest.appName;
|
||||
|
||||
@@ -809,7 +809,7 @@ class _FuchsiaPortForwarder extends DevicePortForwarder {
|
||||
@override
|
||||
Future<void> dispose() async {
|
||||
final List<ForwardedPort> forwardedPortsCopy =
|
||||
List<ForwardedPort>.from(forwardedPorts);
|
||||
List<ForwardedPort>.of(forwardedPorts);
|
||||
for (final ForwardedPort port in forwardedPortsCopy) {
|
||||
await unforward(port);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class IOSDeploy {
|
||||
// Python script that uses package 'six'. LLDB.framework relies on the
|
||||
// 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.
|
||||
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.addEntries(<MapEntry<String, String>>[_cache.dyLdLibEntry]);
|
||||
return environment;
|
||||
|
||||
@@ -342,7 +342,7 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
// it a lot of wiggle room (locally on Flutter Gallery, this takes ~1s).
|
||||
// When there is a timeout, we retry once. See issue #35988.
|
||||
final List<String> showBuildSettingsCommand = (List<String>
|
||||
.from(buildCommands)
|
||||
.of(buildCommands)
|
||||
..add('-showBuildSettings'))
|
||||
// Undocumented behavior: xcodebuild craps out if -showBuildSettings
|
||||
// is used together with -allowProvisioningUpdates or
|
||||
|
||||
@@ -897,7 +897,7 @@ class _IOSSimulatorDevicePortForwarder extends DevicePortForwarder {
|
||||
|
||||
@override
|
||||
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) {
|
||||
await unforward(port);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,7 @@ class FlutterProject {
|
||||
example.android.applicationId,
|
||||
await example.ios.productBundleIdentifier,
|
||||
];
|
||||
return Set<String>.from(candidates
|
||||
return Set<String>.of(candidates
|
||||
.map<String>(_organizationNameFromPackageName)
|
||||
.where((String name) => name != null));
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ Future<void> downloadStartupTrace(VMService observatory, { bool awaitFirstFrame
|
||||
|
||||
int extractInstantEventTimestamp(String eventName) {
|
||||
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(
|
||||
(Map<String, dynamic> event) => event['name'] == eventName, orElse: () => null,
|
||||
);
|
||||
|
||||
@@ -362,7 +362,7 @@ void main() {
|
||||
},
|
||||
'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>{
|
||||
'buildMode': BuildMode.release.toString(),
|
||||
};
|
||||
@@ -380,7 +380,7 @@ void main() {
|
||||
'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>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'b.dart': '6f144e08b58cd0925328610fad7ac07d',
|
||||
@@ -399,7 +399,7 @@ void main() {
|
||||
'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>{
|
||||
'a.dart': '8a21a15fad560b799f6731d436c1b698',
|
||||
'c.dart': '6f144e08b58cd0925328610fad7ac07d',
|
||||
|
||||
@@ -387,7 +387,7 @@ void main() {
|
||||
final VisualStudioFixture fixture = setUpVisualStudio();
|
||||
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;
|
||||
setMockCompatibleVisualStudioInstallation(
|
||||
null,
|
||||
@@ -448,7 +448,7 @@ void main() {
|
||||
fixture.processManager,
|
||||
);
|
||||
|
||||
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse)
|
||||
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
|
||||
..['isComplete'] = false;
|
||||
setMockAnyVisualStudioInstallation(
|
||||
response,
|
||||
@@ -476,7 +476,7 @@ void main() {
|
||||
fixture.processManager,
|
||||
);
|
||||
|
||||
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse)
|
||||
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
|
||||
..['isLaunchable'] = false;
|
||||
setMockAnyVisualStudioInstallation(
|
||||
response,
|
||||
@@ -503,7 +503,7 @@ void main() {
|
||||
fixture.processManager,
|
||||
);
|
||||
|
||||
final Map<String, dynamic> response = Map<String, dynamic>.from(_defaultResponse)
|
||||
final Map<String, dynamic> response = Map<String, dynamic>.of(_defaultResponse)
|
||||
..['isRebootRequired'] = true;
|
||||
setMockAnyVisualStudioInstallation(
|
||||
response,
|
||||
@@ -565,7 +565,7 @@ void main() {
|
||||
final VisualStudioFixture fixture = setUpVisualStudio();
|
||||
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;
|
||||
setMockCompatibleVisualStudioInstallation(
|
||||
response,
|
||||
@@ -585,7 +585,7 @@ void main() {
|
||||
final VisualStudioFixture fixture = setUpVisualStudio();
|
||||
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;
|
||||
setMockCompatibleVisualStudioInstallation(
|
||||
response,
|
||||
|
||||
@@ -585,7 +585,7 @@ class BasicMock {
|
||||
final List<String> messages = <String>[];
|
||||
|
||||
void expectMessages(List<String> expectedMessages) {
|
||||
final List<String> actualMessages = List<String>.from(messages);
|
||||
final List<String> actualMessages = List<String>.of(messages);
|
||||
messages.clear();
|
||||
expect(actualMessages, unorderedEquals(expectedMessages));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user