Details
This package allows Flutter projects to utilize State Management to overcome some of the limitations enforced by the framework.
Its main use is to create data repositories or models that allow callers to be notified when changes are made to member fields. These changes are tracked internally and cause Widgets that use the data to be rebuilt.
No more calls to setState().
Features
Can be used (with more efficiency) to rebuild StatelessWidget. You can remove
all the verbose State code that is usually associated with a StatefulWidget.
Getting started
The package is very simple to use. Just add code like the following to your data model class:
@dataMonitor
abstract class ModelData extends DataNotifier {
@monitor
int count = 0;
@monitor
String name = 'A Name';
}
Caching Property Getters
You can cache property 'values' internally to great effect, when used correctly. For example, if you had to collect data from a source that was slow or complicated, you could use the following:
@dataMonitor
abstract class ModelData extends DataNotifier {
@monitor
String firstName = 'Joe';
@monitor
String lastName = 'Bloggs';
@cache
Future<String> get fullName async {
// Performs a big task asynchronously, such as getting data
// from an external database
return await humungous(firstName, lastName);
}
}
In this example, the return value from 'humungous' is cached and only ever recalculated when either 'firstName' or 'lastName' change.
Usage
A fully working Flutter Application that describes how to use the various
features is available in the /example directory.
Additional information
You can also use the data_monitor_generators package to automatically
generate boilerplate code from @annotations like the ones seen above
(using build_runner).