argument_ must_ be_ native
Details about the 'argument_must_be_native' diagnostic produced by the Dart analyzer.
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));
}
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.