@@ -1237,39 +1237,42 @@ bool hasPlugins(FlutterProject project) {
1237
1237
///
1238
1238
/// For more details, https://flutter.dev/go/federated-plugins.
1239
1239
// TODO(stuartmorgan): Expand implementation to apply to all implementations,
1240
- // not just Dart-only, per the federated plugin spec.
1240
+ // not just Dart-only, per the federated plugin spec.
1241
+ // TODO(gustl22): The flag [throwOnPluginPubspecError] is currently only used
1242
+ // for testing dart plugins as the logic is not working correctly.
1241
1243
List <PluginInterfaceResolution > resolvePlatformImplementation (
1242
1244
List <Plugin > plugins, {
1243
1245
bool throwOnPluginPubspecError = true ,
1244
1246
}) {
1245
- final List <String > platforms = < String > [
1247
+ const Iterable <String > platformKeys = < String > [
1246
1248
AndroidPlugin .kConfigKey,
1247
1249
IOSPlugin .kConfigKey,
1248
1250
LinuxPlugin .kConfigKey,
1249
1251
MacOSPlugin .kConfigKey,
1250
1252
WindowsPlugin .kConfigKey,
1251
1253
];
1252
- final Map <String , List <PluginInterfaceResolution >> possibleResolutions
1253
- = < String , List <PluginInterfaceResolution >> {};
1254
+ final Map <String , List <PluginInterfaceResolution >> possibleResolutions =
1255
+ < String , List <PluginInterfaceResolution >> {};
1254
1256
final Map <String , String > defaultImplementations = < String , String > {};
1255
1257
// Generates a key for the maps above.
1256
1258
String getResolutionKey ({required String platform, required String packageName}) {
1257
1259
return '$packageName :$platform ' ;
1258
1260
}
1259
1261
1260
1262
bool hasPubspecError = false ;
1261
- for (final Plugin plugin in plugins ) {
1262
- for (final String platform in platforms ) {
1263
- if (plugin.platforms[platform ] == null &&
1264
- plugin.defaultPackagePlatforms[platform ] == null ) {
1263
+ for (final String platformKey in platformKeys ) {
1264
+ for (final Plugin plugin in plugins ) {
1265
+ if (plugin.platforms[platformKey ] == null &&
1266
+ plugin.defaultPackagePlatforms[platformKey ] == null ) {
1265
1267
// The plugin doesn't implement this platform.
1266
1268
continue ;
1267
1269
}
1268
1270
String ? implementsPackage = plugin.implementsPackage;
1269
1271
if (implementsPackage == null || implementsPackage.isEmpty) {
1270
- final String ? defaultImplementation = plugin.defaultPackagePlatforms[platform];
1272
+ final String ? defaultImplementation =
1273
+ plugin.defaultPackagePlatforms[platformKey];
1271
1274
final bool hasInlineDartImplementation =
1272
- plugin.pluginDartClassPlatforms[platform ] != null ;
1275
+ plugin.pluginDartClassPlatforms[platformKey ] != null ;
1273
1276
if (defaultImplementation == null && ! hasInlineDartImplementation) {
1274
1277
if (throwOnPluginPubspecError) {
1275
1278
globals.printError (
@@ -1279,27 +1282,27 @@ List<PluginInterfaceResolution> resolvePlatformImplementation(
1279
1282
'flutter:\n '
1280
1283
' plugin:\n '
1281
1284
' platforms:\n '
1282
- ' $platform :\n '
1285
+ ' $platformKey :\n '
1283
1286
' $kDartPluginClass : <plugin-class>\n '
1284
1287
'\n '
1285
1288
'To set a default implementation, use:\n '
1286
1289
'flutter:\n '
1287
1290
' plugin:\n '
1288
1291
' platforms:\n '
1289
- ' $platform :\n '
1292
+ ' $platformKey :\n '
1290
1293
' $kDefaultPackage : <plugin-implementation>\n '
1291
1294
'\n '
1292
1295
'To implement an interface, use:\n '
1293
1296
'flutter:\n '
1294
1297
' plugin:\n '
1295
1298
' implements: <plugin-interface>'
1296
- '\n '
1299
+ '\n ' ,
1297
1300
);
1298
1301
}
1299
1302
hasPubspecError = true ;
1300
1303
continue ;
1301
1304
}
1302
- final String defaultImplementationKey = getResolutionKey (platform: platform , packageName: plugin.name);
1305
+ final String defaultImplementationKey = getResolutionKey (platform: platformKey , packageName: plugin.name);
1303
1306
if (defaultImplementation != null ) {
1304
1307
defaultImplementations[defaultImplementationKey] = defaultImplementation;
1305
1308
continue ;
@@ -1313,7 +1316,7 @@ List<PluginInterfaceResolution> resolvePlatformImplementation(
1313
1316
// - the plugin requires at least Flutter 2.11 (when this opt-in logic
1314
1317
// was added), so that existing plugins continue to work.
1315
1318
// See https://github.com/flutter/flutter/issues/87862 for details.
1316
- final bool isDesktop = platform == 'linux' || platform == 'macos' || platform == 'windows' ;
1319
+ final bool isDesktop = platformKey == 'linux' || platformKey == 'macos' || platformKey == 'windows' ;
1317
1320
final semver.VersionConstraint ? flutterConstraint = plugin.flutterConstraint;
1318
1321
final semver.Version ? minFlutterVersion = flutterConstraint != null &&
1319
1322
flutterConstraint is semver.VersionRange ? flutterConstraint.min : null ;
@@ -1330,25 +1333,23 @@ List<PluginInterfaceResolution> resolvePlatformImplementation(
1330
1333
}
1331
1334
}
1332
1335
// If there's no Dart implementation, there's nothing to register.
1333
- if (plugin.pluginDartClassPlatforms[platform ] == null ||
1334
- plugin.pluginDartClassPlatforms[platform ] == 'none' ) {
1336
+ if (plugin.pluginDartClassPlatforms[platformKey ] == null ||
1337
+ plugin.pluginDartClassPlatforms[platformKey ] == 'none' ) {
1335
1338
continue ;
1336
1339
}
1337
1340
1338
1341
// If it hasn't been skipped, it's a candidate for auto-registration, so
1339
1342
// add it as a possible resolution.
1340
- final String resolutionKey = getResolutionKey (platform: platform, packageName: implementsPackage);
1341
- if (! possibleResolutions.containsKey (resolutionKey)) {
1342
- possibleResolutions[resolutionKey] = < PluginInterfaceResolution > [];
1343
- }
1343
+ final String resolutionKey = getResolutionKey (platform: platformKey, packageName: implementsPackage);
1344
+ possibleResolutions.putIfAbsent (resolutionKey, () => < PluginInterfaceResolution > []);
1344
1345
possibleResolutions[resolutionKey]! .add (PluginInterfaceResolution (
1345
1346
plugin: plugin,
1346
- platform: platform ,
1347
+ platform: platformKey ,
1347
1348
));
1348
1349
}
1349
1350
}
1350
1351
if (hasPubspecError && throwOnPluginPubspecError) {
1351
- throwToolExit ('Please resolve the errors' );
1352
+ throwToolExit ('Please resolve the pubspec errors' );
1352
1353
}
1353
1354
1354
1355
// Now resolve all the possible resolutions to a single option for each
@@ -1401,7 +1402,7 @@ List<PluginInterfaceResolution> resolvePlatformImplementation(
1401
1402
}
1402
1403
}
1403
1404
if (hasResolutionError) {
1404
- throwToolExit ('Please resolve the errors' );
1405
+ throwToolExit ('Please resolve the plugin implementation selection errors' );
1405
1406
}
1406
1407
return finalResolution;
1407
1408
}
0 commit comments