woodemi / libusb.dart

Dart wrapper via dart:ffi for https://github.com/libusb/libusb
BSD 3-Clause "New" or "Revised" License
40 stars 23 forks source link

Update ffi package dependency #15

Closed shaxxx closed 3 years ago

shaxxx commented 3 years ago

Currently, using this package as dependency causes compile error

Launching lib/main.dart on macOS in debug mode...
lib/main.dart:1
../lib/src/quick_usb_desktop.dart:110:38: Error: Expected type 'Utf8' to be a valid and instantiated subtype of 'NativeType'.
 - 'Utf8' is from 'package:ffi/src/utf8.dart' ('../../../../.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/utf8.dart').

Offending line is

Pointer<ffi.Utf8> string = ffi.malloc(256);

Seems this is known issue https://github.com/flutter/flutter/issues/76705

To resolve it, ffi package dependency needs to be updated to latest version (currently 1.1.2)

Sunbreak commented 3 years ago

Since https://github.com/dart-lang/sdk/issues/44622, Utf8 is subclass of Opaque, which is designed to be uninstantiatable

/// [Opaque]'s subtypes represent opaque types in C.
///
/// [Opaque]'s subtypes are not constructible in the Dart code and serve purely
/// as markers in type signatures.
abstract class Opaque extends NativeType {}

Use Uint8 instead

Pointer<ffi.Utf8> pointer = ffi.malloc<Uint8>(256).cast();