diff --git a/lib/src/code_generator/objc_built_in_functions.dart b/lib/src/code_generator/objc_built_in_functions.dart index b092e738..b772861e 100644 --- a/lib/src/code_generator/objc_built_in_functions.dart +++ b/lib/src/code_generator/objc_built_in_functions.dart @@ -326,7 +326,7 @@ class $name implements ${w.ffiLibraryPrefix}.Finalizable { String toString() { final data = dataUsingEncoding_( 0x94000100 /* NSUTF16LittleEndianStringEncoding */); - return data.bytes.cast<${w.ffiPkgLibraryPrefix}.Utf16>().toDartString( + return data!.bytes.cast<${w.ffiPkgLibraryPrefix}.Utf16>().toDartString( length: length); } '''); diff --git a/lib/src/code_generator/objc_interface.dart b/lib/src/code_generator/objc_interface.dart index 416753ab..2611078f 100644 --- a/lib/src/code_generator/objc_interface.dart +++ b/lib/src/code_generator/objc_interface.dart @@ -369,6 +369,9 @@ class $name extends ${superType?.name ?? '_ObjCWrapper'} { String _getConvertedType(Type type, Writer w, String enclosingClass) { if (type is ObjCInstanceType) return enclosingClass; + if (type is ObjCNullable && type.child is ObjCInstanceType) { + return '$enclosingClass?'; + } return type.getDartType(w); } diff --git a/lib/src/code_generator/objc_nullable.dart b/lib/src/code_generator/objc_nullable.dart index 4bdacb35..4cb6a81f 100644 --- a/lib/src/code_generator/objc_nullable.dart +++ b/lib/src/code_generator/objc_nullable.dart @@ -11,12 +11,15 @@ class ObjCNullable extends Type { Type child; ObjCNullable(this.child) { - assert(child is ObjCInterface || - child is ObjCBlock || - child is ObjCObjectPointer || - child is ObjCInstanceType); + assert(isSupported(child)); } + static bool isSupported(Type type) => + type is ObjCInterface || + type is ObjCBlock || + type is ObjCObjectPointer || + type is ObjCInstanceType; + @override void addDependencies(Set dependencies) { child.addDependencies(dependencies); diff --git a/lib/src/header_parser/type_extractor/extractor.dart b/lib/src/header_parser/type_extractor/extractor.dart index ae1208d7..311c1e8b 100644 --- a/lib/src/header_parser/type_extractor/extractor.dart +++ b/lib/src/header_parser/type_extractor/extractor.dart @@ -141,7 +141,9 @@ Type getCodeGenType( ); final isNullable = clang.clang_Type_getNullability(cxtype) == clang_types.CXTypeNullabilityKind.CXTypeNullability_Nullable; - return isNullable ? ObjCNullable(innerType) : innerType; + return isNullable && ObjCNullable.isSupported(innerType) + ? ObjCNullable(innerType) + : innerType; default: var typeSpellKey = clang.clang_getTypeSpelling(cxtype).toStringAndDispose();