enhanced_change_notifier 0.1.4 copy "enhanced_change_notifier: ^0.1.4" to clipboard
enhanced_change_notifier: ^0.1.4 copied to clipboard

A enhanced version of ChangeNotifier introduces new features `target`, `once`, and `immediate`.

enhanced_change_notifier #

pub package pub points

Support for targeted notifications on object property changes.

Enhanced ChangeNotifiers introduce three new features in addition to all existing ChangeNotifier capabilities in Flutter Core:

  • target: notifies listeners at the moment a specified property changes.
  • once: notifies listeners only once at the moment of a change.
  • immediate: allows notifications to be sent immediately after a listener is registered and upon subsequent changes.

Platform Support #

Android iOS MacOS Web Linux Windows

Requirements #

  • Flutter >=3.0.0 <4.0.0
  • Dart >=2.17.0

Getting started #

published on pub.flutter-io.cn, run this Flutter command

flutter pub add enhanced_change_notifier

Usage in Dart #

import 'package:enhanced_change_notifier/enhanced_change_notifier.dart';

class AppModel extends EnhancedChangeNotifier {
  String? _token;

  String? get token => _token;
  set token(String? token) {
    _token = token;
    notifyListeners("token");
  }
}

// GlobalFactory helps create a global singleton instance.
final GlobalFactory<AppModel> appStateModel = GlobalFactory(() => AppModel());

function _e_anyChangedListener() {
  print("any property is changed");
}

function _e_tokenChangedListener(String property) {
  print("$property is changed");
}

function _e_onceListener(String property) {
  print("$property is changed, will notify only once.");
}

function _e_immediateListener(String property) {
  print("$property is changed, will send immediately after listener is registered.");
}

appStateModel.getInstance().addListener(_e_anyChangedListener);
appStateModel.getInstance().addListener(_e_tokenChangedListener, target: 'token');
appStateModel.getInstance().addListener(_e_onceListener, target: 'token', once: true);
appStateModel.getInstance().addListener(_e_immediateListener, target: 'token', immediate: true);

Additional information #

Feel free to file an issue if you have any problem.

1
likes
0
points
157
downloads

Publisher

unverified uploader

Weekly Downloads

A enhanced version of ChangeNotifier introduces new features `target`, `once`, and `immediate`.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on enhanced_change_notifier