osam 2.6.5

  • Readme
  • Changelog
  • Example
  • Installing
  • 89


GitHub Logo This state management implements best solutions of Redux, Bloc, Provider and SOLID principles.

Glossary #

  • [Domain layer]

Store - is a Singleton that stores your State of application.

State - is a class that contains data like primitives, collections and other states.

Event - is a parent class for ModificationEvent that can contains "bundle" (payload).

ModificationEvent - is Event that implements Reducer to modify State of application.

Reducer - is a method in ModificationEvent that calls method of target State and returns it.

Middleware - is a class that working between sending event and calling it's Reducer and contains Conditin's to add and handle with your business logic.

Notice #

  • To catch your custom event in middleware, just create your own Event by extending Event or ModificationEvent.


  • [ModificationEvent]
class IncrementEvent extends ModificationEvent<AppState, int> {
  IncrementEvent({int bundle});

  get reducer => (AppState state, int bundle) => state..increment();
  • [Event for handle some actions]
class SomeSideEffectEvent extends Event<AppState, void>{}
  • [Middleware catching event]
class MyMiddleware extends Middleware<Store<AppState>> {
  bool isIncrement(Event event) {
    if (event is IncrementEvent) {
      Future.delayed(Duration(seconds: 1), () {
        store.dispatchEvent(event: IncrementEvent());
    return nextEvent(true);

  List<Condition> get conditions => [isIncrement];
  • [Presentation layer]

StoreProvider - is a wrapper of your entry point widget and Store to provide Store for all of Presenter's using Provider package (https://pub.dev/packages/provider).

Presenter - is a class that have access to Store and being glue based of Stream's to separate domain and presentation layers.

PresenterProvider - is a wrapper of your widget and Presenter to provide Presenter for all of widgets down of widget tree using Provider package.

  • [Rules]
  1. stateStream and propertyStream emits it's state/property only if last state is not equal to next state/property.

  2. State sends new it's condition to stateStream only by dispatching ModificationEvent to Store

  3. Modify your State's only by dispatching ModificationEvent's.

  4. Don't call StoreProvider and Store in widgets, use Presenter's and PresenterProvider's to handle with Store.

  5. Use Middlewares for all of your business rules.

  6. To throw Event through all of Middleware conditions stack, you must return in all of conditions this call:

nextEvent(true); // or false if you wouldn't
  1. "Recommendation" try to use worker_manager package to save your fps. https://pub.dev/packages/worker_manager
  • [Special features]
  1. State supports comparison based on comparison of its meaningful props. So you will never get the same as previous state in stateStream. So your UI won’t be called with the same data.

  2. State is the mutable class. Garbage collector won’t work so often. And already created Objects will be reused instead of creating new same ones.

  3. Store tracks app lifecycle and save its State when app goes to background and restore it when app back to foreground using Hive DB (https://pub.dev/packages/hive). So user can continue with the place/screen he stopped.

  4. Presenter supports dispose. So if user goes to another screen all needed clean up and closing subscriptions to State's will be done.

  5. In Presenter's you can listen to not only all new State but also propertyStream for listening only one property (which can be property of State or mapped Object from State). So UI will be rebuilt less time.

Best way I know, to understand how to use it - it's look at examples, enjoy ! =)

Examples #




  • Daniil telegram: @dsrenesanse

[2.4.1] - 8 dec 2019 3.51

*0.0.1 start osam ent

*0.0.2 edited event

*0.0.5 edited property stream

*1.0.0 refactored middleware

*1.1.1 edited example

*1.2.0 property stream to mapper

*1.3.0 added natty event

*1.3.4 edited presenter

*1.3.5 edited streams for type safety

*2.0.1 added null safety calls

*2.2.4 added persist

*2.2.9 chained persist with lifecycle

*2.3.0 added hive restoring workaround

*2.3.2 downgraded equatable

*2.3.3 updated equatable

*2.3.7 added generic type for event

*2.3.9 removed generic type for event

*2.4.0 added persist check

*2.4.1 changed Event for Middleware


example #

A new Flutter project.

Getting Started #

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  osam: ^2.6.5

2. Install it

You can install packages from the command line:

with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:osam/osam.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jan 21, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4
  • Flutter: 1.12.13+hotfix.5

Health suggestions

Format lib/domain/state/base_state.dart.

Run flutter format to format lib/domain/state/base_state.dart.

Format lib/domain/store/store.dart.

Run flutter format to format lib/domain/store/store.dart.

Format lib/persist/persist_repository.dart.

Run flutter format to format lib/persist/persist_repository.dart.

Format lib/presentation/store_provider.dart.

Run flutter format to format lib/presentation/store_provider.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0 <3.0.0
equatable ^1.0.2 1.0.2
flutter 0.0.0
hive ^1.3.0 1.3.0
hive_flutter ^0.3.0+1 0.3.0+1
meta ^1.1.8 1.1.8
path_provider ^1.5.1 1.5.1
provider ^4.0.2 4.0.2
Transitive dependencies
collection 1.14.11 1.14.12
nested 0.0.4
path 1.6.4
platform 2.2.1
pointycastle 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
build_runner any