argument_ must_ be_ native
Argument to 'Native.addressOf' must be annotated with @Native
Description
#
The analyzer produces this diagnostic when the argument passed to
Native.addressOf
isn't annotated with the
Native
annotation.
Examples
#
The following code produces this diagnostic because the argument to
addressOf
is a string, not a field, and strings can't be annotated:
import 'dart:ffi';
@Native<Void Function()>()
external void f();
void g() {
print(Native.addressOf('f'));
}
The following code produces this diagnostic because the function
f
is
being passed to
addressOf
but isn't annotated as being
Native
:
import 'dart:ffi';
external void f();
void g() {
print(Native.addressOf<NativeFunction<Void Function()>>(f));
}
Common fixes
#
If the argument isn't either a field or a function, then replace the
argument with a field or function that's annotated with
Native
:
import 'dart:ffi';
@Native<Void Function()>()
external void f();
void g() {
print(Native.addressOf<NativeFunction<Void Function()>>(f));
}
If the argument is either a field or a function, then annotate the field
of function with
Native
:
import 'dart:ffi';
@Native<Void Function()>()
external void f();
void g() {
print(Native.addressOf<NativeFunction<Void Function()>>(f));
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.