leaf_call_must_not_take_handle
FFI leaf call can't take arguments of type 'Handle'.
Description
#The analyzer produces this diagnostic when the value of the isLeaf
argument in an invocation of either Pointer.asFunction
or
DynamicLibrary.lookupFunction
is true
and the function that would be
returned would have a parameter of type Handle
.
For more information about FFI, see C interop using dart:ffi.
Example
#The following code produces this diagnostic because the function p
has a
parameter of type Handle
, but the isLeaf
argument is true
:
import 'dart:ffi';
void f(Pointer<NativeFunction<Void Function(Handle)>> p) {
p.asFunction<void Function(Object)>(isLeaf: true);
}
Common fixes
#If the function has at least one parameter of type Handle
, then remove
the isLeaf
argument:
import 'dart:ffi';
void f(Pointer<NativeFunction<Void Function(Handle)>> p) {
p.asFunction<void Function(Object)>();
}
If none of the function's parameters are Handle
s, then correct the type
information:
import 'dart:ffi';
void f(Pointer<NativeFunction<Void Function(Int8)>> p) {
p.asFunction<void Function(int)>(isLeaf: true);
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。