@@ -51,21 +51,18 @@ FlutterProjectType? stringToProjectType(String value) {
5151}
5252
5353 /// Verifies the expected yaml keys are present in the file.
54- bool _validateMetadataMap (Object ? yamlRoot, Map <String , Type > validations, Logger logger) {
55- if (yamlRoot != null && yamlRoot is ! YamlMap ) {
56- return false ;
57- }
58- final YamlMap map = yamlRoot! as YamlMap ;
54+ bool _validateMetadataMap (YamlMap map, Map <String , Type > validations, Logger logger) {
5955 bool isValid = true ;
6056 for (final MapEntry <String , Object > entry in validations.entries) {
6157 if (! map.keys.contains (entry.key)) {
6258 isValid = false ;
6359 logger.printTrace ('The key `${entry .key }` was not found' );
6460 break ;
6561 }
66- if (map[entry.key] != null && (map[entry.key] as Object ).runtimeType != entry.value) {
62+ final Object ? metadataValue = map[entry.key];
63+ if (metadataValue.runtimeType != entry.value) {
6764 isValid = false ;
68- logger.printTrace ('The value of key `${entry .key }` in .metadata was expected to be ${entry .value } but was ${( map [ entry . key ] as Object ) .runtimeType }' );
65+ logger.printTrace ('The value of key `${entry .key }` in .metadata was expected to be ${entry .value } but was ${metadataValue .runtimeType }' );
6966 break ;
7067 }
7168 }
@@ -89,28 +86,26 @@ class FlutterProjectMetadata {
8986 } on YamlException {
9087 // Handled in _validate below.
9188 }
92- if (yamlRoot == null || yamlRoot is ! YamlMap ) {
89+ if (yamlRoot is ! YamlMap ) {
9390 _logger.printTrace ('.metadata file at ${_metadataFile .path } was empty or malformed.' );
9491 return ;
9592 }
96- final YamlMap map = yamlRoot;
9793 if (_validateMetadataMap (yamlRoot, < String , Type > {'version' : YamlMap }, _logger)) {
98- final Object ? versionYaml = map ['version' ];
99- if (_validateMetadataMap (versionYaml , < String , Type > {
94+ final Object ? versionYamlMap = yamlRoot ['version' ];
95+ if (versionYamlMap is YamlMap && _validateMetadataMap (versionYamlMap , < String , Type > {
10096 'revision' : String ,
10197 'channel' : String ,
10298 }, _logger)) {
103- final YamlMap versionYamlMap = versionYaml! as YamlMap ;
10499 _versionRevision = versionYamlMap['revision' ] as String ? ;
105100 _versionChannel = versionYamlMap['channel' ] as String ? ;
106101 }
107102 }
108103 if (_validateMetadataMap (yamlRoot, < String , Type > {'project_type' : String }, _logger)) {
109- _projectType = stringToProjectType (map ['project_type' ] as String );
104+ _projectType = stringToProjectType (yamlRoot ['project_type' ] as String );
110105 }
111- final Object ? migrationYaml = map ['migration' ];
112- if (migrationYaml != null && migrationYaml is YamlMap ) {
113- migrateConfig.parseYaml (map[ 'migration' ] as YamlMap , _logger);
106+ final Object ? migrationYaml = yamlRoot ['migration' ];
107+ if (migrationYaml is YamlMap ) {
108+ migrateConfig.parseYaml (migrationYaml , _logger);
114109 }
115110 }
116111
@@ -289,13 +284,12 @@ migration:
289284 final Object ? platformsYaml = map['platforms' ];
290285 if (_validateMetadataMap (map, < String , Type > {'platforms' : YamlList }, logger)) {
291286 if (platformsYaml is YamlList && platformsYaml.isNotEmpty) {
292- for (final Object ? platform in platformsYaml) {
293- if (_validateMetadataMap (platform , < String , Type > {
287+ for (final YamlMap platformYamlMap in platformsYaml. whereType < YamlMap >() ) {
288+ if (_validateMetadataMap (platformYamlMap , < String , Type > {
294289 'platform' : String ,
295290 'create_revision' : String ,
296291 'base_revision' : String ,
297292 }, logger)) {
298- final YamlMap platformYamlMap = platform! as YamlMap ;
299293 final SupportedPlatform platformString = SupportedPlatform .values.firstWhere (
300294 (SupportedPlatform val) => val.toString () == 'SupportedPlatform.${platformYamlMap ['platform' ] as String }'
301295 );
0 commit comments