Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ffi package dependency #15

Closed
shaxxx opened this issue Aug 17, 2021 · 1 comment
Closed

Update ffi package dependency #15

shaxxx opened this issue Aug 17, 2021 · 1 comment

Comments

@shaxxx
Copy link

shaxxx commented Aug 17, 2021

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
flutter/flutter#76705

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

@Sunbreak
Copy link
Collaborator

Since dart-lang/sdk#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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants