dust_flutter

Flutter annotations and runtime APIs for code generated by Dust.

Use this package for typed Navigator 2.0 routing, ViewModel state management, and ARB-based localization. Dart models, JSON, validation, and HTTP clients live in dust_dart.

Installation

Most Flutter apps use both Dust packages:

flutter pub add dust_flutter dust_dart

dust_flutter provides Flutter annotations and runtime types. dust_dart provides the model derives used in the example below.

Install the Dust CLI by following the main installation guide. If the CLI and package versions differ, check the compatibility guide.

Quick Start

Define immutable state and a ViewModel that extends its generated base:

import 'package:dust_dart/derive.dart';
import 'package:dust_flutter/state.dart';
import 'package:flutter/material.dart';

part 'counter_view_model.g.dart';

@Derive([Eq(), CopyWith()])
class CounterState with _$CounterState {
  const CounterState({this.count = 0});

  final int count;
}

@ViewModel(state: CounterState)
class CounterViewModel extends $CounterViewModel {
  CounterViewModel(super.args);

  void increment() => emit(state.copyWith(count: state.count + 1));
}

Generate and verify the output:

dust build
dust check

Provide the generated scope and use typed context helpers:

CounterViewModelScope(
  args: (_) => const ViewModelArgs(),
  create: (_, args) => CounterViewModel(args),
  child: Builder(
    builder: (context) {
      final count = context.watchCounterViewModel().value.count;
      return TextButton(
        onPressed: context.readCounterViewModel().increment,
        child: Text('Count: $count'),
      );
    },
  ),
)

Features

Feature Status Provides
Routing Beta Typed route data, deep links, guards, redirects, shells, and transitions on Navigator 2.0.
State management Beta Typed ViewModel bases, scopes, selectors, effects, and async state.
i18n Beta ARB loading, locale fallback, generated app setup, and translated widgets.

Beta APIs may still receive refinements while these features are hardened.

Libraries

Import Provides
package:dust_flutter/route.dart Routing annotations and runtime types.
package:dust_flutter/state.dart State annotations, runtime types, and scope composition.
package:dust_flutter/i18n.dart Localization controller, asset loader, scope, and widgets.
package:dust_flutter/dust_flutter.dart Convenience export for every Flutter API.

Documentation

Report problems through the Dust issue tracker. Contributions follow the repository's contributor guide.

Licensed under the MIT License.

Libraries

dust_flutter
Unified Flutter runtime and annotations for Dust code generation.
i18n
Flutter i18n runtime for Dust-generated localization workflows.
route
Typed Flutter Navigator 2.0 routing annotations and runtime for Dust.
state
Typed Flutter state management annotations and runtime for Dust.