Skip to content
pubscout

embed

1.7.1, released 8 weeks ago by norelease.dev

Generates Dart code that embeds arbitrary file contents as literals.

$ flutter pub add embed
Source repository

What it does

The package reads non‑Dart files at build time and creates Dart constants (strings, binary, or structured records) containing their contents. It updates the generated code whenever the source files change.

AI-written summary of version 1.7.1, based on the package's README and metadata. Report an inaccuracy

Use it when

  • You need compile‑time access to configuration files, test fixtures, or other assets without runtime I/O.
  • You want type‑safe access to embedded structured data like YAML, JSON, or TOML.

Skip it when

  • You require dynamic loading of files at runtime.
  • The project targets platforms where build_runner is unavailable or undesirable.

Strengths

  • Eliminates runtime file I/O and async handling
  • Supports multiple formats (text, binary, YAML, JSON, TOML)
  • Works with Dart records for structured data

Weaknesses

  • Requires build_runner and code generation step
  • Only works for compile‑time known files
  • Limited to Dart‑only projects

Setup

Kind
Pure Dart
Effort
Medium
Code generation
Yes (build_runner)
Direct dependencies
10

Add embed_annotation, embed, and build_runner as dev dependencies; run build_runner to generate code.

import 'package:embed_annotation/embed_annotation.dart';
part 'example.g.dart';

@EmbedLiteral('assets/config.yaml')
const config = _$config;

Alternatives

Packages that do the same job and could replace embed.

Works with

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