Active Property Change Notifier

Actively pushes changes of itself and nested objects, including which property is changed, values before and after.

In other words, this can be partially observed, by either obtaining stream from propertyChangesStreamOnPath for one specific property, or combaining when on stream from propertyChangesStream for multiple properties.

PackageVersion on

How to use

  1. Add dependencies

    In pubspec.yaml, add the dependencies and run pub get to fetch the them.

      # other dependencies ...
      # other dependencies ...
  2. Declare data structure by mixin, add part of and annotations

    part 'main.g.dart';
    // other code ...
    mixin ObservableData on ActivePropertyChangeNotifier{
       int simpleProperty;
       String simpleStringProperty;
       ObservableData nestedData;
    // other code ...

    Usage of annotations

    • NotifyPropertyChange on the mixin to generate change notification codes
    • CustomField for object fields (since their type may not be properly obtained)
    • propagateChanges for other ActivePropertyChangeNotifier fields so that their changes would be streamed by the current one
  3. Run code generation

    Run the command flutter pub run build_runner build to generate all the change notification boilerplates.

  4. Enjoy

    ObservableData testSubject = ObservableDataImpl();
        print("changes found in property ${change.propertyPath}.");
        // change.previousValue for value before change
        // change.currentValue for value after change
    testSubject.nestedData.simpleProperty = 30;
    // output
    // > changes found in property nestedData/simpleStringProperty.

Flutter Example

Since it comes with Streams of property changes, use with StreamBuilder is easy.

  stream: testSubject
     .map((change) => change.currentValue),
  builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
      // code for other status ...
      if (snapshot.hasData) {
        return Text("count: ${}");


Current design may vulnerable to race condition.

await Future.wait([
    Duration(milliseconds: 50),
    () => testSubject.simpleProperty = 11 // this update never reflected.
  Future(() async {
    var stuff = testSubject.simpleProperty;
    await Future.delayed(Duration(milliseconds: 500));
    testSubject.simpleProperty = stuff + 100;

To avoid that, it should be used in situation with only one update source, e.g. only one "thread" doing the update, or use other state managment tools based on immutable states, such as Redux, MobX etc.


  • Unsubscribe the original when other ActivePropertyChangeNotifier instance is assign to fields annotated with PropagateChanges
  • Allow customise generated class name
  • Handle array
  • Avoid manually typing property path
  • Unit tests
  • Document & API reference