flutter_love_scope
provide flutter widgets for supporting solution base on flutter_scope and love.
Since flutter_love_scope
has knowledge dependencies of flutter_scope and love. It's good practice to learn them before using flutter_love_scope
. Here are documentation sites:
flutter_love_scope
included and re-exported package flutter_scope and love.
flutter_love_scope
also provide a configurable FinalSystem
for integrating
System
with flutter.
FinalSystem
is a configuration that creates a running system,
then expose its States<State>
and Observer<Event>
.
System<CounterState, CounterEvent> createCounterSystem() { ... }
...
FlutterScope(
configure: [
FinalSystem<CounterState, CounterEvent>(
equal: (scope) => createCounterSystem(),
),
],
child: Builder(
builder: (context) {
final myCounterStates = context.scope.getStates<CounterState>();
final myEventObserver = context.scope.get<Observer<CounterEvent>>();
return CounterPage(
counterStates: myCounterStates,
onIncreasePressed: () => myEventObserver.onData(Increment()),
);
},
),
);
Which simulates:
void flutterScope() async {
// create a running system then exposes its states and event observer
final System<CounterState, CounterEvent> system = createCounterSystem();
final (states, eventObserver) = runSystemThenExposeStatesAndEventObserver(system);
// resolve states and event observer in current scope
final States<CounterState> myCounterStates = states;
final Observer<CounterEvent> myEventObserver = eventObserver;
// notify user about state updates
final observation = myCounterStates.observe((count) {
print('You have pushed the button this many times: $count');
});
// simulate user tap increase button asynchronously
await Future.delayed(const Duration(seconds: 3));
myEventObserver.onData(Increment());
}
The MIT License (MIT)