@@ -222,7 +222,8 @@ class Writer {
222222 for (final b in lookUpBindings) {
223223 s.write (b.toBindingString (this ).string);
224224 }
225- if (symbolAddressWriter.shouldGenerate) {
225+ if (symbolAddressWriter.shouldGenerate &&
226+ symbolAddressWriter.hasNonNativeAddress) {
226227 s.write (symbolAddressWriter.writeObject (this ));
227228 }
228229
@@ -233,13 +234,12 @@ class Writer {
233234 for (final b in ffiNativeBindings) {
234235 s.write (b.toBindingString (this ).string);
235236 }
236-
237- if (symbolAddressWriter.shouldGenerate) {
238- s.write (symbolAddressWriter.writeObject (this ));
239- }
240237 }
241238
242239 if (symbolAddressWriter.shouldGenerate) {
240+ if (! symbolAddressWriter.hasNonNativeAddress) {
241+ s.write (symbolAddressWriter.writeObject (this ));
242+ }
243243 s.write (symbolAddressWriter.writeClass (this ));
244244 }
245245
@@ -451,7 +451,7 @@ class SymbolAddressWriter {
451451 /// Used to check if we need to generate `_SymbolAddress` class.
452452 bool get shouldGenerate => _addresses.isNotEmpty;
453453
454- bool get hasNonNativeAddress => _addresses. any ((e) => ! e. native ) ;
454+ bool hasNonNativeAddress = false ;
455455
456456 SymbolAddressWriter (this .context);
457457
@@ -460,6 +460,7 @@ class SymbolAddressWriter {
460460 required String name,
461461 required String ptrName,
462462 }) {
463+ hasNonNativeAddress = true ;
463464 _addresses.add (_SymbolAddressUnit (type, name, ptrName, false ));
464465 }
465466
0 commit comments