osam 6.3.7 copy "osam: ^6.3.7" to clipboard
osam: ^6.3.7 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 _PropertyNotifier.

_PropertyNotifier 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, _PropertyNotifier uses Equatable and storing last known "good" hashcode. It allows you to use mutable data in the domain layer safe.

_PropertyNotifier implements IProperty to prevent the setting of new value from the presentation layer.

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 {
  // good constructor structure for restoring entity from hive
  Counter([this._value]) {
    _value ??= _PropertyNotifier(0);
  }

  _PropertyNotifier<int> _value;

  IProperty<int> get value => _value;

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

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
0
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

unknown (LICENSE)

Dependencies

equatable, flutter, hive, path_provider

More

Packages that depend on osam