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