rebuilder 0.2.0

rebuilder pub package

Rebuilder is an easy and minimalistic state management library for Flutter.

It consists of:

  • A DataModel class to extend to create a class where lives the data and the business logic for the UI.

  • A DataModelProvider that provides this model to the widgets tree by using an InheritedWidget.

  • A RebuilderState that holds the state of a Rebuilder widget.

  • The Rebuilder widget that represents the entity which rebuilds every time the rebuild method of the associated RebuilderState's state property is called.

  • The RebuilderObject: an object bound to a RebuilderState in order to rebuild the Rebuilder widget associated to this state whenever a new value is set.

Examples built with this library: #
  • Rebuilder example. Check out the example app to know how to:

    • Implement a counter
    • Use the DataModel to separate the UI from the business logic
    • Implement a dynamic theme changer with a RebuilderObject
    • Bind a function to a RebuilderObject
    • Sharing data between widgets
    • Update only a subtree of widgets
  • Quiz game: a simple trivia game built with Flutter and this package.

Getting started #

1. Define a DataModel
class CountersModel extends DataModel {
  CountersModel() {

    // Initialize the instance of the `RebuilderObject` with
    // with an instance of a `RebuilderState` that will be bound
    // to a `Rebuilder` widget.
    counterDown = RebuilderObject<int>.init(
        rebuilderState: counterDownState,
        initialData: 100,
        onChange: _onCounterDownChange);
  }
  
  // STATES
  final counterUpState = RebuilderState();
  final counterDownState = RebuilderState();
  final counterMulState = RebuilderState(); 

  // COUNTERS
  int counterUp = 0;
  int counterMul = 2;
  RebuilderObject<int> counterDown;

  // METHODS
  void incrementCounterUp() {
    counterUp++;
    counterUpState.rebuild();
  }

  void decrementCounterDown() {
    counterDown.value--;

    // Using the `RebuilderObject` the `rebuild` method of the
    // counterDownState will automatically be called.
    //
    // states.counterDownState.rebuild();
  }

  void _onCounterDownChange() {
    print('Value changed: ${counterDown.value}');
  }

  @override
  void dispose() {}
}
2. Provide the CountersModel by using the DataModelProvider widget
final countersModel = CountersModel()

DataModelProvider<CountersModel>(
          dataModel: countersModel,
          child: const CountersPage(),
);
3. Get the CountersModel instance from the context of a widget in the tree
  Widget build(BuildContext context) {
    final countersModel = DataModelProvider.of<CountersModel>(context);
4. Bind the RebuilderState instances to the Rebuilder widgets in the view
Rebuilder<CountersModel>(
    dataModel: countersModel,
    rebuilderState: countersModel.counterUpState,
    builder: (state, data) {
      // Accessing to `counterUp` in the `DataModel`
      // derived class provided through the `data` parameter
      return Text('${data.counterUp}');
      // 
      // It is possible to directly access to `counterUp`
      // without using the `dataModel` parameter:
      //
      // builder: (state, _) {
      // return Text('${countersModel.counterUp}');
    }),
RaisedButton(
  child: const Text('+'),
  onPressed: countersModel.incrementCounterUp,
),


 
Rebuilder<RebuilderObject>(
  dataModel: countersModel.counterDown,
  rebuilderState: countersModel.counterDownState,
  builder: (state, data) {
    return Text('${data.value}');
  }),
RaisedButton(
  child: const Text('-'),
  onPressed: countersModel.decrementCounterDown,
)



Rebuilder<CountersModel>(
  dataModel: countersModel,
  rebuilderState: countersModel.counterMulState,
  builder: (state, data) {
    return Column(children: <Widget>[
      Text('${data.counterMul}'),
      RaisedButton(
          child: const Text('*'),
          onPressed: () {
            data.counterMul *= 2;
            if (data.counterMul > 65536) {
              data.counterMul = 2;
            }
            state.rebuild();                                          
            }),
    ]);
  }),

Version 0.2.0 (08-06-19) #

  • Breaking change: the class StateWrapper was renamed to RebuilderState.
  • Code refactoring
  • Updated readme.md: added a trivia game example.

Version 0.1.0+1 (31-05-19) #

  • First version of the package

example/README.md

Examples built with this library: #
  • Rebuilder example. Check out the example app to know how to:

    • Implement a counter
    • Use the DataModel to separate the UI from the business logic
    • Implement a dynamic theme changer with a RebuilderObject
    • Bind a function to a RebuilderObject
    • Sharing data between widgets
    • Update only a subtree of widgets
  • Quiz game: a simple trivia game built with Flutter and this package.

Use this package as a library

1. Depend on it

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


dependencies:
  rebuilder: ^0.2.0

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:rebuilder/rebuilder.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
63
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]
81
Learn more about scoring.

We analyzed this package on Aug 20, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

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