must_ return_ void
The return type of the function passed to 'NativeCallable.listener' must be 'void' rather than '{0}'.
Description
#
The analyzer produces this diagnostic when you pass a function
that doesn't return
void
to the
NativeCallable.listener
constructor.
NativeCallable.listener
creates a native callable that can be invoked
from any thread. The native code that invokes the callable sends a message
back to the isolate that created the callable, and doesn't wait for a
response. So it isn't possible to return a result from the callable.
For more information about FFI, see C interop using dart:ffi.
Example
#
The following code produces this diagnostic because the function
f
returns
int
rather than
void
.
import 'dart:ffi';
int f(int i) => i * 2;
void g() {
NativeCallable<Int32 Function(Int32)>.listener(f);
}
Common fixes
#Change the return type of the function to void
.
import 'dart:ffi';
void f(int i) => print(i * 2);
void g() {
NativeCallable<Void Function(Int32)>.listener(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.