我正在使用opencv和flutter来构建应用程序。ffi包是用来实现桥接的,我从教程代码中得到了错误。我找不到任何解决办法。你能帮帮我吗?当Utf8.fromtf8和Utf8.toUtf8 时,我出现错误
import 'dart:ffi' as ffi;
import 'dart:io';
import 'package:ffi/ffi.dart';
// C function signatures
typedef _version_func = ffi.Pointer<Utf8> Function();
typedef _process_image_func = ffi.Void Function(ffi.Pointer<Utf8>, ffi.Pointer<Utf8>);
// Dart function signatures
typedef _VersionFunc = ffi.Pointer<Utf8> Function();
typedef _ProcessImageFunc = void Function(ffi.Pointer<Utf8>, ffi.Pointer<Utf8>);
// Getting a library that holds needed symbols
ffi.DynamicLibrary _lib = Platform.isAndroid
? ffi.DynamicLibrary.open('libnative_opencv.so')
: ffi.DynamicLibrary.process();
// Looking for the functions
final _VersionFunc _version = _lib
.lookup<ffi.NativeFunction<_version_func>>('version')
.asFunction();
final _ProcessImageFunc _processImage = _lib
.lookup<ffi.NativeFunction<_process_image_func>>('process_image')
.asFunction();
String opencvVersion() {
return Utf8.fromUtf8(_version());
}
void processImage(ProcessImageArguments args) {
_processImage(Utf8.toUtf8(args.inputPath), Utf8.toUtf8(args.outputPath));
}
错误
Error: Method not found: 'Utf8.fromUtf8'.
本教程中的FFi包可能已经过时了。Dart FFI1.1.1
具有Pointer<Utf8>
类型的方法toString()
、toDartString()
和toNativeUtf8()
。
在这里结账。
它应该是这样的:
String opencvVersion() {
return _version().toDartString();
}
void processImage(ProcessImageArguments args) {
_processImage(args.inputPath.toNativeUtf8(), args.outputPath.toNativeUtf8());
}