with_controller

Creator: coderz1093

Last updated:

0 purchases

with_controller Image
with_controller Images

Languages

Categories

Add to Cart

Description:

with controller

with_controller #
A WithController widget is a convenience widget for reducing MobX boilerplate burden when you need to initialize a store (and dispose it) and create reactions (and dispose them).
Getting Started #
Instalation #

Add with_controller to your pubspec.yaml
Run flutter pub get in your terminal
That's it!

Example #
class MyCounterStore {
@observable
int counter = 0;

@action
void increment() => counter++;
}

class MyHomePage extends StatelessWidget {
final String title = "Awesome!";

@override
Widget build(BuildContext context) {
return WithController<MyCounterStore>(
controller: (ctx) => MyCounterStore(),
reactions: [
(controller) => autorun((r) => print(controller.counter)),
(controller) => when((r) => controller.counter == 10, () => print("Wow!")),
],
disposer: (controller) => print("You could do something fancy here"),
builder: (context, controller) => Column(
children: [
Text(title),
RaisedButton(
child: Text("Click Me"),
onPressed: controller.increment,
)
],
),
);
}
}
copied to clipboard

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.