code_assets
2.2.0, released 14 days ago by dart.dev
Provides the hook protocol specification for bundling native code with Dart packages.
What it does
This package provides the API for code assets to be used with package:hooks. It is used in build and link hooks to inform the Dart and Flutter SDKs about code assets that need to be bundled with an application.
AI-written summary of version 2.2.0, based on the package's README and metadata. Report an inaccuracy
Use it when
- You need to bundle native code (C, C++, Objective-C, Rust, Go) with your Dart or Flutter package.
- You are writing a build or link hook for native asset compilation.
Skip it when
- You are building a pure Dart application without native C/C++ or other compiled binary dependencies.
- You do not use package:hooks for native asset building.
Strengths
- Standardized protocol for native code bundling in Dart and Flutter.
- Supports custom operating systems, architectures, and sanitizers.
Weaknesses
- Breaking changes can occur with custom target representations in maps and sets (e.g., v2.0.0 update).
- Requires understanding native build hooks and toolchains.
Setup
- Kind
- Pure Dart
- Effort
- Medium
- Code generation
- Yes (build_runner)
- Direct dependencies
- 3
Requires setting up build and link hooks in the hook/ directory of your package.
import 'package:code_assets/code_assets.dart';
import 'package:hooks/hooks.dart';
void main(List<String> args) async {
await build(args, (input, output) async {
if (input.config.buildCodeAssets) {
output.assets.code.add(
CodeAsset(
package: input.packageName,
name: 'src/third_party/unix.dart',
linkMode: LookupInProcess(),
),
);
}
});
}Alternatives
Packages that do the same job and could replace code_assets.
- flutter_gen_runner
Generates strongly-typed Dart classes for Flutter assets, fonts, and colors to avoid string-based APIs.
87Compare - flutter_gen
A code generator for your assets, fonts, and colors to eliminate string-based APIs.
87Compare - swiftgen
A tool for generating bindings that allow interop between Dart and Swift code.
78Compare - protobuf
Provides runtime support for Dart protocol buffer messages generated by protoc_plugin.
84Compare
Works with
Packages commonly used together with code_assets: ones it builds on, ones built on it, and its own family.
- hookscode_assets depends on itDart API for the JSON-based protocol for package build and link hooks.
- loggingcode_assets depends on itProvides configurable logging with levels and stream listeners for Dart apps.
- built_valueSame familyImmutable value types with builders, enum classes and JSON serialization for Dart.
- asyncSame familyUtility classes and helpers that extend Dart's async library.
- testSame familyA full featured library for writing and running Dart tests across platforms.
- typed_dataSame familyUtility functions and classes for easier work with dart:typed_data lists.
- http_parserSame familyA platform-independent package for parsing and serializing HTTP formats.
- fake_asyncSame familyFake asynchronous events like timers and microtasks for deterministic testing.