diff --git a/packages/flutter_tools/lib/src/platform_plugins.dart b/packages/flutter_tools/lib/src/platform_plugins.dart index 8fb8c71ac75f..129273b10279 100644 --- a/packages/flutter_tools/lib/src/platform_plugins.dart +++ b/packages/flutter_tools/lib/src/platform_plugins.dart @@ -541,7 +541,12 @@ class WebPlugin extends PluginPlatform { }); factory WebPlugin.fromYaml(String name, YamlMap yaml) { - assert(validate(yaml)); + if (yaml['pluginClass'] is! String) { + throwToolExit('The plugin `$name` is missing the required field `pluginClass` in pubspec.yaml'); + } + if (yaml['fileName'] is! String) { + throwToolExit('The plugin `$name` is missing the required field `fileName` in pubspec.yaml'); + } return WebPlugin( name: name, pluginClass: yaml['pluginClass'] as String, @@ -549,13 +554,6 @@ class WebPlugin extends PluginPlatform { ); } - static bool validate(YamlMap yaml) { - if (yaml == null) { - return false; - } - return yaml['pluginClass'] is String && yaml['fileName'] is String; - } - static const String kConfigKey = 'web'; /// The name of the plugin. diff --git a/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart b/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart index 40ea7cea7031..0f8283855e42 100644 --- a/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart +++ b/packages/flutter_tools/test/general.shard/plugin_parsing_test.dart @@ -290,6 +290,29 @@ void main() { ]); }); + testWithoutContext('Web plugin tool exits if fileName field missing', () { + final FileSystem fileSystem = MemoryFileSystem.test(); + const String pluginYamlRaw = + 'platforms:\n' + ' web:\n' + ' pluginClass: WebSamplePlugin\n'; + + final YamlMap pluginYaml = loadYaml(pluginYamlRaw) as YamlMap; + expect( + () => Plugin.fromYaml( + _kTestPluginName, + _kTestPluginPath, + pluginYaml, + null, + const [], + fileSystem: fileSystem, + ), + throwsToolExit( + message: 'The plugin `$_kTestPluginName` is missing the required field `fileName` in pubspec.yaml', + ), + ); + }); + testWithoutContext('Windows assumes win32 when no variants are given', () { final FileSystem fileSystem = MemoryFileSystem.test(); const String pluginYamlRaw =