Skip to content
pubscout

code_assets

2.2.0, released 14 days ago by dart.dev

Provides the hook protocol specification for bundling native code with Dart packages.

$ flutter pub add code_assets
Source repository

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.

  • flutter_gen

    A code generator for your assets, fonts, and colors to eliminate string-based APIs.

  • swiftgen

    A tool for generating bindings that allow interop between Dart and Swift code.

  • protobuf

    Provides runtime support for Dart protocol buffer messages generated by protoc_plugin.

Works with

Packages commonly used together with code_assets: ones it builds on, ones built on it, and its own family.