ffi_ native_ unexpected_ number_ of_ parameters_ with_ receiver
Unexpected number of Native annotation parameters. Expected {0} but has {1}. Native instance method annotation must have receiver as first argument.
Description
#
The analyzer produces this diagnostic when the type argument used on the
@Native
annotation of a native method doesn't include a type for the
receiver of the method.
Example
#
The following code produces this diagnostic because the type argument on
the
@Native
annotation (Void Function(Double)
) doesn't include a type
for the receiver of the method:
import 'dart:ffi';
class C {
@Native<Void Function(Double)>()
external void f(double x);
}
Common fixes
#Add an initial parameter whose type is the same as the class in which the native method is being declared:
import 'dart:ffi';
class C {
@Native<Void Function(C, Double)>()
external void f(double x);
}
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.