with_controller 1.0.2

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 #

  1. Add with_controller to your pubspec.yaml
  2. Run flutter pub get in your terminal
  3. 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,
          )
        ],
      ),
    );
  }
}

[1.0.0] - 01-25-2020

  • Added WithController widget.

[1.0.1] - 01-25-2020

  • Added examples in /examples.

[1.0.2] - 02-13-2020

  • Bumped mobx dependency version to ^1.0.2.

example/with_controller.dart

import 'package:mobx/mobx.dart';
import 'package:flutter/material.dart';
import 'package:with_controller/with_controller.dart';

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,
          )
        ],
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  with_controller: ^1.0.2

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:with_controller/with_controller.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
31
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
65
Learn more about scoring.

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

  • Dart: 2.7.1
  • pana: 0.13.5
  • Flutter: 1.12.13+hotfix.7

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
mobx ^1.0.2 1.0.2
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test