mirror of
https://github.com/flutter/packages.git
synced 2025-06-19 22:03:33 +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) {
|
if (fileContent.trim().isEmpty) {
|
||||||
return null;
|
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);
|
return versionString == null ? null : Version.parse(versionString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,10 +44,12 @@ class PubVersionFinder {
|
|||||||
result: PubVersionFinderResult.fail,
|
result: PubVersionFinderResult.fail,
|
||||||
httpResponse: response);
|
httpResponse: response);
|
||||||
}
|
}
|
||||||
final List<Version> versions =
|
final Map<Object?, Object?> responseBody =
|
||||||
(json.decode(response.body)['versions'] as List<dynamic>)
|
json.decode(response.body) as Map<Object?, Object?>;
|
||||||
.map<Version>((final dynamic versionString) =>
|
final List<Version> versions = (responseBody['versions']! as List<Object?>)
|
||||||
Version.parse(versionString as String))
|
.cast<String>()
|
||||||
|
.map<Version>(
|
||||||
|
(final String versionString) => Version.parse(versionString))
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
return PubVersionFinderResponse(
|
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();
|
final StringBuffer buffer = StringBuffer();
|
||||||
|
|
||||||
for (final MapEntry<String, dynamic> entry in values.entries) {
|
for (final MapEntry<String, Object?> entry in values.entries) {
|
||||||
buffer.writeln();
|
buffer.writeln();
|
||||||
if (entry.value is VersionConstraint) {
|
final Object? entryValue = entry.value;
|
||||||
String value = entry.value.toString();
|
if (entryValue is VersionConstraint) {
|
||||||
|
String value = entryValue.toString();
|
||||||
// Range constraints require quoting.
|
// Range constraints require quoting.
|
||||||
if (value.startsWith('>') || value.startsWith('<')) {
|
if (value.startsWith('>') || value.startsWith('<')) {
|
||||||
value = "'$value'";
|
value = "'$value'";
|
||||||
}
|
}
|
||||||
buffer.write(' ${entry.key}: $value');
|
buffer.write(' ${entry.key}: $value');
|
||||||
} else if (entry.value is SdkDependency) {
|
} else if (entryValue is SdkDependency) {
|
||||||
final SdkDependency dep = entry.value as SdkDependency;
|
buffer.write(' ${entry.key}: \n sdk: ${entryValue.sdk}');
|
||||||
buffer.write(' ${entry.key}: \n sdk: ${dep.sdk}');
|
} else if (entryValue is PathDependency) {
|
||||||
} else if (entry.value is PathDependency) {
|
String depPath = entryValue.path;
|
||||||
final PathDependency dep = entry.value as PathDependency;
|
|
||||||
String depPath = dep.path;
|
|
||||||
if (path.style == p.Style.windows) {
|
if (path.style == p.Style.windows) {
|
||||||
// Posix-style path separators are preferred in pubspec.yaml (and
|
// Posix-style path separators are preferred in pubspec.yaml (and
|
||||||
// using a consistent format makes unit testing simpler), so convert.
|
// 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');
|
buffer.write(' ${entry.key}: \n path: $depPath');
|
||||||
} else {
|
} else {
|
||||||
throw UnimplementedError(
|
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 typeKey = 'package-ecosystem';
|
||||||
const String dirKey = 'directory';
|
const String dirKey = 'directory';
|
||||||
_gradleDirs = entries
|
_gradleDirs = entries
|
||||||
.where((dynamic entry) => entry[typeKey] == 'gradle')
|
.cast<YamlMap>()
|
||||||
.map((dynamic entry) => (entry as YamlMap)[dirKey] as String)
|
.where((YamlMap entry) => entry[typeKey] == 'gradle')
|
||||||
|
.map((YamlMap entry) => entry[dirKey] as String)
|
||||||
.toSet();
|
.toSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -304,7 +304,7 @@ class FormatCommand extends PackageCommand {
|
|||||||
return <String>[];
|
return <String>[];
|
||||||
}
|
}
|
||||||
|
|
||||||
final String stdout = result.stdout.trim() as String;
|
final String stdout = (result.stdout as String).trim();
|
||||||
if (stdout.isEmpty) {
|
if (stdout.isEmpty) {
|
||||||
return <String>[];
|
return <String>[];
|
||||||
}
|
}
|
||||||
|
@ -244,8 +244,8 @@ class PubspecCheckCommand extends PackageLoopingCommand {
|
|||||||
required RepositoryPackage package,
|
required RepositoryPackage package,
|
||||||
}) {
|
}) {
|
||||||
if (_isImplementationPackage(package)) {
|
if (_isImplementationPackage(package)) {
|
||||||
final String? implements =
|
final YamlMap pluginSection = pubspec.flutter!['plugin'] as YamlMap;
|
||||||
pubspec.flutter!['plugin']!['implements'] as String?;
|
final String? implements = pluginSection['implements'] as String?;
|
||||||
final String expectedImplements = package.directory.parent.basename;
|
final String expectedImplements = package.directory.parent.basename;
|
||||||
if (implements == null) {
|
if (implements == null) {
|
||||||
return 'Missing "implements: $expectedImplements" in "plugin" section.';
|
return 'Missing "implements: $expectedImplements" in "plugin" section.';
|
||||||
@ -265,19 +265,20 @@ class PubspecCheckCommand extends PackageLoopingCommand {
|
|||||||
Pubspec pubspec, {
|
Pubspec pubspec, {
|
||||||
required RepositoryPackage package,
|
required RepositoryPackage package,
|
||||||
}) {
|
}) {
|
||||||
final dynamic platformsEntry = pubspec.flutter!['plugin']!['platforms'];
|
final YamlMap pluginSection = pubspec.flutter!['plugin'] as YamlMap;
|
||||||
if (platformsEntry == null) {
|
final YamlMap? platforms = pluginSection['platforms'] as YamlMap?;
|
||||||
|
if (platforms == null) {
|
||||||
logWarning('Does not implement any platforms');
|
logWarning('Does not implement any platforms');
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final YamlMap platforms = platformsEntry as YamlMap;
|
|
||||||
final String packageName = package.directory.basename;
|
final String packageName = package.directory.basename;
|
||||||
|
|
||||||
// Validate that the default_package entries look correct (e.g., no typos).
|
// Validate that the default_package entries look correct (e.g., no typos).
|
||||||
final Set<String> defaultPackages = <String>{};
|
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 =
|
final String? defaultPackage =
|
||||||
platformEntry.value['default_package'] as String?;
|
platformDetails['default_package'] as String?;
|
||||||
if (defaultPackage != null) {
|
if (defaultPackage != null) {
|
||||||
defaultPackages.add(defaultPackage);
|
defaultPackages.add(defaultPackage);
|
||||||
if (!defaultPackage.startsWith('${packageName}_')) {
|
if (!defaultPackage.startsWith('${packageName}_')) {
|
||||||
|
@ -234,7 +234,8 @@ class ReadmeCheckCommand extends PackageLoopingCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Validate that the supported OS lists match.
|
// 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) {
|
if (platformsEntry == null) {
|
||||||
logWarning('Plugin not support any platforms');
|
logWarning('Plugin not support any platforms');
|
||||||
return null;
|
return null;
|
||||||
|
@ -22,12 +22,14 @@ void main() {
|
|||||||
gitDir = MockGitDir();
|
gitDir = MockGitDir();
|
||||||
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
||||||
.thenAnswer((Invocation invocation) {
|
.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();
|
final MockProcessResult mockProcessResult = MockProcessResult();
|
||||||
if (invocation.positionalArguments[0][0] == 'diff') {
|
if (arguments[0] == 'diff') {
|
||||||
when<String?>(mockProcessResult.stdout as String?)
|
when<String?>(mockProcessResult.stdout as String?)
|
||||||
.thenReturn(gitDiffResponse);
|
.thenReturn(gitDiffResponse);
|
||||||
} else if (invocation.positionalArguments[0][0] == 'merge-base') {
|
} else if (arguments[0] == 'merge-base') {
|
||||||
when<String?>(mockProcessResult.stdout as String?)
|
when<String?>(mockProcessResult.stdout as String?)
|
||||||
.thenReturn(mergeBaseResponse);
|
.thenReturn(mergeBaseResponse);
|
||||||
}
|
}
|
||||||
|
@ -110,8 +110,10 @@ void main() {
|
|||||||
final MockGitDir gitDir = MockGitDir();
|
final MockGitDir gitDir = MockGitDir();
|
||||||
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
when(gitDir.runCommand(any, throwOnError: anyNamed('throwOnError')))
|
||||||
.thenAnswer((Invocation invocation) {
|
.thenAnswer((Invocation invocation) {
|
||||||
|
final List<String> arguments =
|
||||||
|
invocation.positionalArguments[0]! as List<String>;
|
||||||
final MockProcessResult mockProcessResult = MockProcessResult();
|
final MockProcessResult mockProcessResult = MockProcessResult();
|
||||||
if (invocation.positionalArguments[0][0] == 'diff') {
|
if (arguments[0] == 'diff') {
|
||||||
when<String?>(mockProcessResult.stdout as String?)
|
when<String?>(mockProcessResult.stdout as String?)
|
||||||
.thenReturn(gitDiffResponse);
|
.thenReturn(gitDiffResponse);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user