Skip to content

Theme package contract

Package structure, authoring catalogs, build rules, and performance protocol for Akari themes.

Akari themes are standalone Dart/Flutter packages. Built-in themes live under themes/ (themes/default/, themes/fallback/, and themes/preset1/), while third-party or synthesized themes can live outside the repository.

Project structure

my_theme/
  pubspec.yaml                 # name: theme_<name>
  assets/
  lib/
    <name>.scene.json          # authoring scene layout and visibility conditions
    <name>.scene.g.dart        # generated by build_runner
    theme.dart                 # exports build<Name>Theme({Color? seed, SceneDocument? document})
    components/                # theme-owned Flutter widgets
  test/

Naming and dependency rules

RuleRequirement
Package & builder nameRead from pubspec.yaml (independent of folder name). theme_ocean must export buildOceanTheme from lib/theme.dart.
Required dependenciestheme_sdk and scene in dependencies; scene_codegen and build_runner: ^2.16.2 in dev_dependencies.
Component sharingMay depend on greeter_components, but must not import another concrete theme package.
Asset pathsMust use Flutter package paths (packages/theme_ocean/assets/wallpaper.jpg).
Return contractbuild<Name>Theme returns a ThemeDefinition bundling the SceneDocument, ThemeBundle, component factory, and optional authoring catalogs.

External theme repositories must point their SDK path dependencies at a local Akari checkout.

Primary scene & builder arguments

When a theme contains multiple *.scene.json files, you can declare which scene opens first in Theme Studio and CLI workflows in pubspec.yaml:

akari:
  scene: lib/composition.scene.json

The path must resolve inside lib/. Without akari.scene, scenes are listed in alphabetical order.

The exported builder accepts an optional SceneDocument? document parameter:

  • In production: document is omitted, and the builder uses the compiled <name>SceneDocument from *.scene.g.dart.
  • In Theme Studio: Studio passes the live edited SceneDocument (including themeProperties) so preset and token changes render identically in the canvas and in production.

Declaring editable component properties

Themes can expose typed inspector controls in Theme Studio via ThemeDefinition.componentCatalog. Each component entry lists ThemeTextProperty or ThemeChoiceProperty<Enum> declarations:

enum HeadingStyle { regular, large }

const headingStyle = ThemeChoiceProperty(
  name: 'variant',
  label: 'Text style',
  defaultValue: HeadingStyle.regular,
  choices: {HeadingStyle.regular: 'Regular', HeadingStyle.large: 'Large'},
);
const headingText = ThemeTextProperty(
  name: 'text',
  label: 'Text',
  defaultValue: 'Welcome',
);
const catalog = ThemeComponentCatalog(
  components: {
    'heading': ThemeComponentDefinition(
      label: 'Heading',
      properties: [headingText, headingStyle],
    ),
  },
);
  • Shared defaults & reading: Pass componentCatalog: catalog to ThemeDefinition, and read values inside your widgets with headingStyle.getValue(node.properties) and headingText.getValue(node.properties).
  • Stable persistence: Choice properties serialize enum .name strings into node.properties (independent of UI display labels). Include defaultValue in choices and keep enum member names stable.
  • Validation: Call catalog.validateDocument(document) in your theme builder before constructing tokens or widgets. Missing properties fall back to their declared defaults without mutating the JSON, while unsupported choice values throw a FormatException naming the node and property. Unlisted components and properties remain untouched.

Declaring theme-wide presets

Themes can expose global style choices (such as color palettes, control materials, or motion profiles) through ThemeDefinition.presetCatalog:

enum OceanPalette { deep, coral }

const oceanPalette = ThemeChoiceProperty(
  name: 'palette',
  label: 'Palette',
  defaultValue: OceanPalette.deep,
  choices: {OceanPalette.deep: 'Deep sea', OceanPalette.coral: 'Coral'},
);
const presets = ThemePresetCatalog(properties: [oceanPalette]);
  • Pass presetCatalog: presets to ThemeDefinition and call presets.validateDocument(document) in your theme builder.
  • Selected values are stored as strings in the scene’s root themeProperties map (oceanPalette.getValue(document.themeProperties)) and appear under Compose → Theme presets in Theme Studio.

Declaring layout slots

ThemeDefinition.layout optionally defines semantic component slots and switchable layout arrangements (presets) for a specific sceneId:

const layout = ThemeLayoutDefinition(
  sceneId: 'ocean',
  label: 'Ocean',
  slots: [
    ThemeLayoutSlot(
      label: 'Sign-in caption',
      defaultNode: SceneNode(
        id: 'caption',
        componentId: 'heading',
        rect: SceneRect(x: 0.1, y: 0.2, width: 0.4, height: 0.1),
        properties: {'text': 'Welcome'},
      ),
    ),
  ],
  presets: {
    'split': ThemeLayoutPreset(label: 'Split view'),
    'centered': ThemeLayoutPreset(
      label: 'Centered column',
      rects: {
        'caption': SceneRect(x: 0.3, y: 0.2, width: 0.4, height: 0.1),
      },
    ),
  },
);
  • Slot identity & templates: Each ThemeLayoutSlot reserves a unique defaultNode.id and componentId. Its defaultNode provides the complete insertion template (geometry, properties, motion, focus, and visibility) when toggling a component on in Studio’s Compose tab. Keep slot templates in Dart code so removing a node from JSON does not prevent re-inserting it later.
  • Required slots (isRequired: true): Studio prevents deleting required slots and offers a one-click Add required repair action if an imported scene is missing any (layout.findMissingRequiredSlots(document)).
  • Layout presets (presets): Each ThemeLayoutPreset supplies alternative SceneRect positions keyed by slot node ID (omitted IDs reuse the base slot rectangle). Switching layout presets in Studio updates slot geometry while preserving customized properties, optional slot omissions, and custom layers.
  • Validation: Call layout.validateDocument(document) in your theme builder. Scenes with a different id are unaffected.

Build and preview lifecycle

# Build the default theme for production (release mode)
akari build

# Build an external theme package
akari build --theme /path/to/my_theme --mode release

# Run automated UI walkthroughs in one window
akari preview --theme themes/default

# Inspect the execution plan without building
akari preview --theme /path/to/my_theme --dry-run

How the CLI builds and runs a theme:

  1. Resolves the selected theme’s dependencies and generates *.scene.g.dart.
  2. Creates a reusable Flutter host project under build/tool/hosts/<encoded-canonical-theme-path>/<real|demo|studio>/ that links shared greeter sources and imports the theme’s builder directly.
  3. Compiles theme code and assets into the Linux executable (runtime loading of uncompiled Dart code is not supported).
CommandMode & transportBehavior
buildRelease, production Rust backend + native splashPublishes symlinks at build/out/<theme>, build/out/backend, and build/out/akari-splash.
runDebug (default), private D-Bus + mock backend (--backend real for production transport)Supports hot reload (r), hot restart (R), and quit (q). Fullscreen by default; set AKARI_WINDOW_MODE=windowed for a window.
previewDebug, no backend or hot reloadRuns face-success and password-fallback (or --scenario) in one window and exits.
run splashStandalone windowPreviews the native loading screen until closed.

Caching and concurrency

  • Host projects preserve Flutter and CMake/Ninja build caches across runs.
  • Rust mock and production backends use separate target directories (crates/target/akari-mock/ and crates/target/akari-real/).
  • Commands targeting the same theme serialize on a per-theme lock; different themes can build concurrently.

Performance protocol

Themes own their performance entrypoints, interaction journeys, metrics, and pass/fail thresholds. A theme opts into verify-perf and trace-perf by declaring a perf block in pubspec.yaml:

perf:
  version: 1
  verify: [dart, run, perf/run.dart, verify]
  trace: [dart, run, perf/run.dart, trace]

Execution contract

akari verify-perf --theme /path/to/theme -- --custom-option value
akari trace-perf --theme /path/to/theme
  • Working directory & SDK: Commands run in the theme directory without a shell. Leading dart or flutter executables automatically resolve to the repository’s configured SDK.

  • Forwarded arguments: Everything after -- is passed verbatim to the theme runner.

  • Output directory: The CLI passes an existing absolute path via AKARI_PERF_OUTPUT_DIR.

  • Result manifest: Exit code 0 indicates success and requires a valid result.json inside AKARI_PERF_OUTPUT_DIR:

    {
      "version": 1,
      "artifacts": [
        {"name": "report", "path": "report.json"},
        {"name": "timeline", "path": "timeline.json"}
      ]
    }

    Artifact names must be unique and paths must resolve inside AKARI_PERF_OUTPUT_DIR. Validated paths are recorded in the CLI run report’s theme_artifacts map.

themes/default implements both verify and trace under themes/default/perf/, and themes/preset1 implements verify under themes/preset1/perf/. themes/fallback omits perf: and does not inherit another theme’s thresholds.