dart-native-interop-ffi
Interoperating with C using dart:ffi
Contents
- Core Concepts
- Memory Management & Finalization
- Cross-Platform Type Mapping
- Workflow: Generating Bindings with ffigen
- Workflow: Loading and Calling Native Functions
- Examples
Core Concepts
Use the dart:ffi library to call native C APIs and manage native memory in Dart applications running on the Dart Native platform.
Related Skills: Refer to dart-concurrency-isolates when executing heavy FFI workloads to avoid blocking the main thread.
Memory Management & Finalization
Manage native memory explicitly to prevent leaks.
- DO manually allocate and free memory using
callocormallocfrompackage:ffiwhen passing dynamically sized data to C. - DO use
FinalizableandNativeFinalizerto ensure native resources are automatically cleaned up when the Dart object is garbage collected.
More from dart-lang/skills
dart-add-unit-test
Write and organize unit tests for functions, methods, and classes using `package:test`. Use when creating new logic or fixing bugs to ensure code remains correct and regression-free.
2.0Kdart-fix-runtime-errors
Uses get_runtime_errors and lsp to fetch an active stack trace, locate the failing line, apply a fix, and verify resolution via hot_reload.
2.0Kdart-run-static-analysis
Execute `dart analyze` to identify warnings and errors, and use `dart fix --apply` to automatically resolve mechanical lint issues. Use during development to ensure code quality and before committing changes.
2.0Kdart-use-pattern-matching
Use switch expressions and pattern matching where appropriate
2.0Kdart-resolve-package-conflicts
Workflow for fixing package version conflicts. Use this when `pub get` fails due to incompatible package versions.
2.0Kdart-collect-coverage
Collect coverage using the coverage packge and create an LCOV report
2.0K