mirror of
https://github.com/flutter/packages.git
synced 2025-06-19 13:38:53 +08:00
[various] Enable avoid_dynamic_calls
(#6834)
* Enable the option * Fix camera * Fix webview * Remove unnecessary 'call's from camera tests * Fix maps * Fix sign-in * fix image_picker * Fix IAP * Fix shared_preferences * Fix url_launcher_android * Version bumps * Fix tool * Re-apply webview test fix * Re-bump versions * Fix one new tool issue
This commit is contained in:
@ -88,7 +88,8 @@ class GitVersionFinder {
|
||||
if (fileContent.trim().isEmpty) {
|
||||
return null;
|
||||
}
|
||||
final String? versionString = loadYaml(fileContent)['version'] as String?;
|
||||
final YamlMap fileYaml = loadYaml(fileContent) as YamlMap;
|
||||
final String? versionString = fileYaml['version'] as String?;
|
||||
return versionString == null ? null : Version.parse(versionString);
|
||||
}
|
||||
|
||||
|
@ -44,10 +44,12 @@ class PubVersionFinder {
|
||||
result: PubVersionFinderResult.fail,
|
||||
httpResponse: response);
|
||||
}
|
||||
final List<Version> versions =
|
||||
(json.decode(response.body)['versions'] as List<dynamic>)
|
||||
.map<Version>((final dynamic versionString) =>
|
||||
Version.parse(versionString as String))
|
||||
final Map<Object?, Object?> responseBody =
|
||||
json.decode(response.body) as Map<Object?, Object?>;
|
||||
final List<Version> versions = (responseBody['versions']! as List<Object?>)
|
||||
.cast<String>()
|
||||
.map<Version>(
|
||||
(final String versionString) => Version.parse(versionString))
|
||||
.toList();
|
||||
|
||||
return PubVersionFinderResponse(
|
||||
|
@ -244,24 +244,23 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
|
||||
###''';
|
||||
}
|
||||
|
||||
String _pubspecMapString(Map<String, dynamic> values) {
|
||||
String _pubspecMapString(Map<String, Object?> values) {
|
||||
final StringBuffer buffer = StringBuffer();
|
||||
|
||||
for (final MapEntry<String, dynamic> entry in values.entries) {
|
||||
for (final MapEntry<String, Object?> entry in values.entries) {
|
||||
buffer.writeln();
|
||||
if (entry.value is VersionConstraint) {
|
||||
String value = entry.value.toString();
|
||||
final Object? entryValue = entry.value;
|
||||
if (entryValue is VersionConstraint) {
|
||||
String value = entryValue.toString();
|
||||
// Range constraints require quoting.
|
||||
if (value.startsWith('>') || value.startsWith('<')) {
|
||||
value = "'$value'";
|
||||
}
|
||||
buffer.write(' ${entry.key}: $value');
|
||||
} else if (entry.value is SdkDependency) {
|
||||
final SdkDependency dep = entry.value as SdkDependency;
|
||||
buffer.write(' ${entry.key}: \n sdk: ${dep.sdk}');
|
||||
} else if (entry.value is PathDependency) {
|
||||
final PathDependency dep = entry.value as PathDependency;
|
||||
String depPath = dep.path;
|
||||
} else if (entryValue is SdkDependency) {
|
||||
buffer.write(' ${entry.key}: \n sdk: ${entryValue.sdk}');
|
||||
} else if (entryValue is PathDependency) {
|
||||
String depPath = entryValue.path;
|
||||
if (path.style == p.Style.windows) {
|
||||
// Posix-style path separators are preferred in pubspec.yaml (and
|
||||
// using a consistent format makes unit testing simpler), so convert.
|
||||
@ -278,7 +277,7 @@ dev_dependencies:${_pubspecMapString(pubspec.devDependencies)}
|
||||
buffer.write(' ${entry.key}: \n path: $depPath');
|
||||
} else {
|
||||
throw UnimplementedError(
|
||||
'Not available for type: ${entry.value.runtimeType}',
|
||||
'Not available for type: ${entryValue.runtimeType}',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -58,8 +58,9 @@ class DependabotCheckCommand extends PackageLoopingCommand {
|
||||
const String typeKey = 'package-ecosystem';
|
||||
const String dirKey = 'directory';
|
||||
_gradleDirs = entries
|
||||
.where((dynamic entry) => entry[typeKey] == 'gradle')
|
||||
.map((dynamic entry) => (entry as YamlMap)[dirKey] as String)
|
||||
.cast<YamlMap>()
|
||||
.where((YamlMap entry) => entry[typeKey] == 'gradle')
|
||||
.map((YamlMap entry) => entry[dirKey] as String)
|
||||
.toSet();
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ class FormatCommand extends PackageCommand {
|
||||
return <String>[];
|
||||
}
|
||||
|
||||
final String stdout = result.stdout.trim() as String;
|
||||
final String stdout = (result.stdout as String).trim();
|
||||
if (stdout.isEmpty) {
|
||||
return <String>[];
|
||||
}
|
||||
|
@ -244,8 +244,8 @@ class PubspecCheckCommand extends PackageLoopingCommand {
|
||||
required RepositoryPackage package,
|
||||
}) {
|
||||
if (_isImplementationPackage(package)) {
|
||||
final String? implements =
|
||||
pubspec.flutter!['plugin']!['implements'] as String?;
|
||||
final YamlMap pluginSection = pubspec.flutter!['plugin'] as YamlMap;
|
||||
final String? implements = pluginSection['implements'] as String?;
|
||||
final String expectedImplements = package.directory.parent.basename;
|
||||
if (implements == null) {
|
||||
return 'Missing "implements: $expectedImplements" in "plugin" section.';
|
||||
@ -265,19 +265,20 @@ class PubspecCheckCommand extends PackageLoopingCommand {
|
||||
Pubspec pubspec, {
|
||||
required RepositoryPackage package,
|
||||
}) {
|
||||
final dynamic platformsEntry = pubspec.flutter!['plugin']!['platforms'];
|
||||
if (platformsEntry == null) {
|
||||
final YamlMap pluginSection = pubspec.flutter!['plugin'] as YamlMap;
|
||||
final YamlMap? platforms = pluginSection['platforms'] as YamlMap?;
|
||||
if (platforms == null) {
|
||||
logWarning('Does not implement any platforms');
|
||||
return null;
|
||||
}
|
||||
final YamlMap platforms = platformsEntry as YamlMap;
|
||||
final String packageName = package.directory.basename;
|
||||
|
||||
// Validate that the default_package entries look correct (e.g., no typos).
|
||||
final Set<String> defaultPackages = <String>{};
|
||||
for (final MapEntry<dynamic, dynamic> platformEntry in platforms.entries) {
|
||||
for (final MapEntry<Object?, Object?> platformEntry in platforms.entries) {
|
||||
final YamlMap platformDetails = platformEntry.value! as YamlMap;
|
||||
final String? defaultPackage =
|
||||
platformEntry.value['default_package'] as String?;
|
||||
platformDetails['default_package'] as String?;
|
||||
if (defaultPackage != null) {
|
||||
defaultPackages.add(defaultPackage);
|
||||
if (!defaultPackage.startsWith('${packageName}_')) {
|
||||
|
@ -234,7 +234,8 @@ class ReadmeCheckCommand extends PackageLoopingCommand {
|
||||
}
|
||||
|
||||
// Validate that the supported OS lists match.
|
||||
final dynamic platformsEntry = pubspec.flutter!['plugin']!['platforms'];
|
||||
final YamlMap pluginSection = pubspec.flutter!['plugin'] as YamlMap;
|
||||
final dynamic platformsEntry = pluginSection['platforms'];
|
||||
if (platformsEntry == null) {
|
||||
logWarning('Plugin not support any platforms');
|
||||
return null;
|
||||
|
@ -22,12 +22,14 @@ void main() {
|
||||
gitDir = MockGitDir();
|
||||
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
||||
.thenAnswer((Invocation invocation) {
|
||||
gitDirCommands.add(invocation.positionalArguments[0] as List<String>?);
|
||||
final List<String> arguments =
|
||||
invocation.positionalArguments[0]! as List<String>;
|
||||
gitDirCommands.add(arguments);
|
||||
final MockProcessResult mockProcessResult = MockProcessResult();
|
||||
if (invocation.positionalArguments[0][0] == 'diff') {
|
||||
if (arguments[0] == 'diff') {
|
||||
when<String?>(mockProcessResult.stdout as String?)
|
||||
.thenReturn(gitDiffResponse);
|
||||
} else if (invocation.positionalArguments[0][0] == 'merge-base') {
|
||||
} else if (arguments[0] == 'merge-base') {
|
||||
when<String?>(mockProcessResult.stdout as String?)
|
||||
.thenReturn(mergeBaseResponse);
|
||||
}
|
||||
|
@ -110,8 +110,10 @@ void main() {
|
||||
final MockGitDir gitDir = MockGitDir();
|
||||
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
||||
.thenAnswer((Invocation invocation) {
|
||||
final List<String> arguments =
|
||||
invocation.positionalArguments[0]! as List<String>;
|
||||
final MockProcessResult mockProcessResult = MockProcessResult();
|
||||
if (invocation.positionalArguments[0][0] == 'diff') {
|
||||
if (arguments[0] == 'diff') {
|
||||
when<String?>(mockProcessResult.stdout as String?)
|
||||
.thenReturn(gitDiffResponse);
|
||||
}
|
||||
|
Reference in New Issue
Block a user