ffi 0.1.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 97

Build Status

Utilities for working with Foreign Function Interface (FFI) code, incl. converting between Dart strings and C strings encoded with utf8 and utf16.

For additional details about Dart FFI (dart:ffi), see https://dart.dev/guides/libraries/c-interop.

Changelog #

0.1.3 #

Stable release incorporating all the previous dev release changes.

Bump SDK constraint to >= 2.6.0.

0.1.3-dev.4 #

Bump SDK constraint to >= 2.6.0-dev.8.2 which contains the new API of dart:ffi.

0.1.3-dev.3 #

Replace use of deprecated asExternalTypedData with asTypedList.

0.1.3-dev.2 #

Incorporate struct API changes, drop type argument of structs.

0.1.3-dev.1 #

  • Adds top-level allocate<T>() and free() methods which can be used as a replacement for the deprecated Pointer.allocate<T>() and Pointer.free() members in dart:ffi.

0.1.1+2 #

  • Expand readme

0.1.1+1 #

  • Fix documentation link

0.1.1 #

  • Add basic Utf16 support

0.1.0 #

  • Initial release supporting Utf8


import 'dart:ffi';

import 'package:ffi/ffi.dart';

main() {
  // Allocate and free some native memory with malloc and free.
  final pointer = allocate<Uint8>();
  pointer.value = 3;

  // Use the Utf8 helper to encode null-terminated Utf8 strings in native memory.
  final String myString = "πŸ˜ŽπŸ‘ΏπŸ’¬";
  final Pointer<Utf8> charPointer = Utf8.toUtf8(myString);
  print("First byte is: ${charPointer.cast<Uint8>().value}");

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  ffi: ^0.1.3

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:ffi/ffi.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Feb 27, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.5


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
Dev dependencies
pedantic ^1.0.0
test ^1.6.8