notifier.dart 375 B

1234567891011121314151617181920
  1. import 'package:flutter/material.dart';
  2. class PublishNotifier<T> extends ChangeNotifier {
  3. T? _value;
  4. set value(T newValue) {
  5. _value = newValue;
  6. notifyListeners();
  7. }
  8. T? get currentValue => _value;
  9. void addPublishListener(void Function(T) callback) {
  10. super.addListener(() {
  11. if (_value != null) {
  12. callback(_value!);
  13. }
  14. });
  15. }
  16. }