non_ native_ function_ type_ argument_ to_ pointer
Can't invoke 'asFunction' because the function signature '{0}' for the pointer isn't a valid C function signature.
Description
#
The analyzer produces this diagnostic when the method asFunction is
invoked on a pointer to a native function, but the signature of the native
function isn't a valid C function signature.
For more information about FFI, see C interop using dart:ffi.
Example
#
The following code produces this diagnostic because function signature
associated with the pointer p (FNative) isn't a valid C function
signature:
import 'dart:ffi';
typedef FNative = int Function(int);
typedef F = int Function(int);
class C {
void f(Pointer<NativeFunction<FNative>> p) {
p.asFunction<F>();
}
}
Common fixes
#Make the NativeFunction signature a valid C signature:
import 'dart:ffi';
typedef FNative = Int8 Function(Int8);
typedef F = int Function(int);
class C {
void f(Pointer<NativeFunction<FNative>> p) {
p.asFunction<F>();
}
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-4. View source or report an issue.