@@ -192,8 +192,14 @@ import FlutterMacOS
192192 });
193193 } else if (! hostDatatype.isBuiltin &&
194194 customEnumNames.contains (field.type.baseName)) {
195+ indent.writeln ('var ${field .name }: $fieldType ? = nil' );
195196 indent.writeln (
196- 'let ${field .name } = ${_castForceUnwrap (listValue , field .type , root )}' );
197+ 'let enumVal$index = ${_castForceUnwrap (listValue , const TypeDeclaration (baseName : 'Int' , isNullable : true ), root )}' );
198+ indent.write ('if let ${field .name }RawValue = enumVal$index ' );
199+ indent.addScoped ('{' , '}' , () {
200+ indent.writeln (
201+ '${field .name } = $fieldType (rawValue: ${field .name }RawValue)' );
202+ });
197203 } else {
198204 indent.writeln (
199205 'let ${field .name } = ${_castForceUnwrap (listValue , field .type , root )} ' );
@@ -677,22 +683,17 @@ String _camelCase(String text) {
677683}
678684
679685String _castForceUnwrap (String value, TypeDeclaration type, Root root) {
680- final String castUnwrap = type.isNullable ? '?' : '' ;
681686 if (isEnum (root, type)) {
682- final String nullableConditionPrefix =
683- type.isNullable ? 'nilOrValue(value: $value ) != nil ? ' : '' ;
684- final String nullableConditionSuffix = type.isNullable
685- ? ' : nilOrValue(value: $value ) as! ${type .baseName }?'
686- : '' ;
687-
687+ final String nullableConditionPrefix = type.isNullable ? '' : '' ;
688+ final String nullableConditionSuffix = type.isNullable ? '' : '!' ;
688689 return '$nullableConditionPrefix ${_swiftTypeForDartType (type )}(rawValue: $value as! Int)$nullableConditionSuffix ' ;
689690 } else if (type.baseName == 'Object' ) {
690691 // Special-cased to avoid warnings about using 'as' with Any.
691692 return value;
692693 } else if (type.isNullable) {
693- return 'nilOrValue(value: $value ) as! ${_swiftTypeForDartType (type )}$ castUnwrap ' ;
694+ return '( nilOrValue(value: $value ) as Any) as ! ${_swiftTypeForDartType (type )}? ' ;
694695 } else {
695- return '$value as! ${_swiftTypeForDartType (type )}$ castUnwrap ' ;
696+ return '$value as! ${_swiftTypeForDartType (type )}' ;
696697 }
697698}
698699
0 commit comments