rebuilder 0.2.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 78

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);
  final counterUpState = RebuilderState();
  final counterDownState = RebuilderState();
  final counterMulState = RebuilderState(); 

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

  void incrementCounterUp() {

  void decrementCounterDown() {

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

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

  void dispose() {}
2. Provide the CountersModel by using the DataModelProvider widget
final countersModel = 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
    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}');
  child: const Text('+'),
  onPressed: countersModel.incrementCounterUp,

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

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

Version 0.2.0 (08-06-19) #

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

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

  • First version of the package


import 'package:flutter/material.dart';

import 'package:rebuilder/rebuilder.dart';

import 'src/datamodels/app_data.dart';
import 'src/mainpage.dart';
import 'src/models/theme.dart';
import 'src/repository.dart';

void main() {
  final repository = Repository();
    repository: repository,

class App extends StatefulWidget {
  const App({this.repository});

  final Repository repository;

  _AppState createState() => _AppState();

class _AppState extends State<App> {
  AppModel appModel;

  void initState() {
    appModel = AppModel(repository: widget.repository);

  Widget build(BuildContext context) {
    return DataModelProvider<AppModel>(
      dataModel: appModel,
      child: MaterialPage(),

class MaterialPage extends StatelessWidget {
  Widget build(BuildContext context) {
    final appModel = DataModelProvider.of<AppModel>(context);

    return Rebuilder<RebuilderObject<String>>(
        dataModel: appModel.chosenTheme,
        rebuilderState: appModel.materialState,
        builder: (state, data) {
          return MaterialApp(
              title: 'Rebuilder example',
              theme: themes[data.value],
              home: MainPage());

Use this package as a library

1. Depend on it

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

  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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

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

  • Dart: 2.8.4
  • pana: 0.13.9+1
  • Flutter: 1.17.3

Analysis suggestions

Package not compatible with SDK dart

because of import path [rebuilder]

Health suggestions

Fix lib/src/data_provider.dart. (-0.50 points)

Analysis of lib/src/data_provider.dart reported 1 hint:

line 24 col 21: 'inheritFromWidgetOfExactType' is deprecated and shouldn't be used. Use dependOnInheritedWidgetOfExactType instead. This feature was deprecated after v1.12.1..

Maintenance suggestions

Package is getting outdated. (-6.58 points)

The package was last published 55 weeks ago.


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