scoper

Last updated:

0 purchases

scoper Image
scoper Images
Add to Cart

Description:

scoper

Scoper #
A minimal state management solution for Flutter. #

How to use: #
Create custom ExampleScope by extending Scope.
Use notifiyBuilders() to trigger rebuild of ScopeBuilder<ExampleScope>.
Use notifiyExecutors() to trigger execution of ScopeExecutor<ExampleScope>.
class CounterScope extends Scope {
int _counter = 0;
int _divider = 7;

increment() {
_counter++;
notifiyBuilders();

if(_counter % _divider == 0) {
notifiyExecutors();
}
}

get counter => _counter;
get divider => _divider;
}
copied to clipboard
Register your scopes by passing them to a ScopeRegistrant at the root of the widget-tree.
ScopeRegistrant(
scopes: [
CounterScope(),
ExampleScope(),
],
child: Container(
child: (...)
),
)
copied to clipboard
Use a ScopeBuilder<ExampleScope> to build widgets depending on the given scope.
ScopeBuilder<CounterScope>(
builder: (context, scope) {
return Text(scope.counter.toString());
},
),
copied to clipboard
Use a ScopeExecutor<ExampleScope> to execute certain logic depending on the given scope.
ScopeExecutor<CounterScope>(
executor: (context, scope) {
final message = "This number is divisible by " + scope.divider.toString();
final snackbar = SnackBar(content: Text(message));
ScaffoldMessenger.of(context).showSnackBar(snackbar);
},
child: Container(
child: (...)
),
)
copied to clipboard
Use get<ExampleScope> to get a scope from context and call it's methods (for example in onPressed).
context.get<CounterScope>().increment(),
copied to clipboard

Open for contribution and feedback! 😄

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.