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));
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。