Skip to main content

mot_flutter 0.1.0 copy "mot_flutter: ^0.1.0" to clipboard
mot_flutter: ^0.1.0 copied to clipboard

Flutter integration for MOT state management. Subscribe and forget.

MOT Flutter #

Subscribe and forget. State management for Flutter with automatic cleanup.

Installation #

dependencies:
  mot_flutter: ^0.1.0

This package re-exports mot and provides Flutter integration.

Quick Start #

import 'package:mot_flutter/mot_flutter.dart';

// 1. Create a model (lives outside the widget tree)
class Counter with Beacon {
  final count = BeaconField<int>(0);

  void increment() => count.value++;
}

// 2. Use in a StatefulWidget
class CounterWidget extends StatefulWidget {
  const CounterWidget({super.key});

  @override
  State<CounterWidget> createState() => _CounterWidgetState();
}

class _CounterWidgetState extends State<CounterWidget> {
  final model = Counter();

  @override
  void initState() {
    super.initState();
    // Subscribe and forget - cleanup is automatic
    model.count.observe(this, (self) => self.setState(() {}));
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Text('Count: ${model.count.value}'),
        ElevatedButton(
          onPressed: model.increment,
          child: const Text('+'),
        ),
      ],
    );
  }
}

The Pattern #

// In initState, observe the fields you need:
model.field.observe(this, (self) => self.setState(() {}));

// That's it. No dispose() needed.
// When the widget dies, the subscription is cleaned up automatically.

Fine-Grained Updates #

Only observe what you need:

@override
void initState() {
  super.initState();
  // Only rebuilds when name changes
  profile.name.observe(this, (self) => self.setState(() {}));
  // Won't rebuild when email or age changes
}

Philosophy #

"The domain lives outside the widget tree. The UI observes it."

MOT keeps your business logic separate from Flutter. Models are plain Dart classes that can be tested without Flutter.

Documentation #

License #

MIT

0
likes
150
points
10
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Flutter integration for MOT state management. Subscribe and forget.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, mot

More

Packages that depend on mot_flutter