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
| Rule | Requirement |
|---|---|
| Package & builder name | Read from pubspec.yaml (independent of folder name). theme_ocean must export buildOceanTheme from lib/theme.dart. |
| Required dependencies | theme_sdk and scene in dependencies; scene_codegen and build_runner: ^2.16.2 in dev_dependencies. |
| Component sharing | May depend on greeter_components, but must not import another concrete theme package. |
| Asset paths | Must use Flutter package paths (packages/theme_ocean/assets/wallpaper.jpg). |
| Return contract | build<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:
documentis omitted, and the builder uses the compiled<name>SceneDocumentfrom*.scene.g.dart. - In Theme Studio: Studio passes the live edited
SceneDocument(includingthemeProperties) 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: catalogtoThemeDefinition, and read values inside your widgets withheadingStyle.getValue(node.properties)andheadingText.getValue(node.properties). - Stable persistence: Choice properties serialize enum
.namestrings intonode.properties(independent of UI display labels). IncludedefaultValueinchoicesand 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 aFormatExceptionnaming 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: presetstoThemeDefinitionand callpresets.validateDocument(document)in your theme builder. - Selected values are stored as strings in the scene’s root
themePropertiesmap (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
ThemeLayoutSlotreserves a uniquedefaultNode.idandcomponentId. ItsdefaultNodeprovides 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): EachThemeLayoutPresetsupplies alternativeSceneRectpositions 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 differentidare 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:
- Resolves the selected theme’s dependencies and generates
*.scene.g.dart. - 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. - Compiles theme code and assets into the Linux executable (runtime loading of uncompiled Dart code is not supported).
| Command | Mode & transport | Behavior |
|---|---|---|
build | Release, production Rust backend + native splash | Publishes symlinks at build/out/<theme>, build/out/backend, and build/out/akari-splash. |
run | Debug (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. |
preview | Debug, no backend or hot reload | Runs face-success and password-fallback (or --scenario) in one window and exits. |
run splash | Standalone window | Previews 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/andcrates/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
dartorflutterexecutables 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
0indicates success and requires a validresult.jsoninsideAKARI_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’stheme_artifactsmap.
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.