osam 6.4.1 copy "osam: ^6.4.1" to clipboard
osam: ^6.4.1 copied to clipboard

discontinued
outdated

Lightweight and predictable state management. Allows you to save all application state by using Hve library

OSAM #

GitHub Logo

Osam is a Lightweight library to manage and notify the state.

The core element is IProperty.

IProperty allows you to change a value and notify everything listening to it.

Same as ValueNotifier you can add listeners and remove listeners.

To decide should listeners get a notification, IProperty uses Equatable and storing last known "good" hashcode. It allows you to use mutable data in the domain layer safe.

Library have a rule to make your code more readable and healthy. To change IProperty's value you should use PropertyChanger. IPropertys can be changed only inside class extending from PropertyChanger.

To start change IPropertys you should use the method let to define what you are changing and methods set or apply to make actual change.

IProperty very actively uses in osam_flutter and good fits with it.

Example:

import 'package:flutter/material.dart';
import 'package:osam/osam.dart';

class Counter extends PropertyChanger {
  final IProperty<int> value;

  void increment() => let(value).apply((value) => value++);

  Counter({IProperty<int> value}) : value = value ?? IProperty(0);
}

void main() {
  final counter = Counter();
  runApp(Example(counter: counter));
}

class Example extends StatelessWidget {
  final Counter counter;

  const Example({Key key, this.counter}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () => counter.increment(),
        ),
        body: Center(
          child: ValueListenableBuilder(
            valueListenable: counter.value,
            builder: (_, value, __) => Text(
              value.toString(),
              style: const TextStyle(fontSize: 40),
            ),
          ),
        ),
      ),
    );
  }
}

Also, you can use the Persist repository to store your AppState and UIState. osam_flutter uses a persist repository to store all-state.

If you prefer to follow clean architecture principles, I recommend you to write use-case to change the state of the application. Usecase could be easily provided by UseCaseContainer

10
likes
30
pub points
0%
popularity

Publisher

verified publisherrenesanse.net

Lightweight and predictable state management. Allows you to save all application state by using Hve library

Repository (GitHub)
View/report issues

License

MIT (LICENSE)

Dependencies

equatable, flutter, hive, hive_flutter, path_provider

More

Packages that depend on osam