@@ -5,14 +5,14 @@ import 'popover.dart';
55/// If multiple popovers are exclusive,
66/// pass the same mutex to them.
77class PopoverMutex {
8- final ValueNotifier < PopoverState ?> _stateNotifier = ValueNotifier ( null );
8+ final _PopoverStateNotifier _stateNotifier = _PopoverStateNotifier ( );
99 PopoverMutex ();
1010
11- void removePopoverStateListener (VoidCallback listener) {
11+ void removePopoverListener (VoidCallback listener) {
1212 _stateNotifier.removeListener (listener);
1313 }
1414
15- VoidCallback listenOnPopoverStateChanged (VoidCallback callback) {
15+ VoidCallback listenOnPopoverChanged (VoidCallback callback) {
1616 listenerCallback () {
1717 callback ();
1818 }
@@ -21,24 +21,31 @@ class PopoverMutex {
2121 return listenerCallback;
2222 }
2323
24- void close () {
25- _stateNotifier.value? .close ();
26- }
24+ void close () => _stateNotifier.state? .close ();
2725
28- PopoverState ? get state => _stateNotifier.value ;
26+ PopoverState ? get state => _stateNotifier.state ;
2927
30- set state (PopoverState ? newState) {
31- if (_stateNotifier.value != null && _stateNotifier.value != newState) {
32- _stateNotifier.value? .close ();
33- }
34- _stateNotifier.value = newState;
35- }
28+ set state (PopoverState ? newState) => _stateNotifier.state = newState;
3629
3730 void removeState () {
38- _stateNotifier.value = null ;
31+ _stateNotifier.state = null ;
3932 }
4033
4134 void dispose () {
4235 _stateNotifier.dispose ();
4336 }
4437}
38+
39+ class _PopoverStateNotifier extends ChangeNotifier {
40+ PopoverState ? _state;
41+
42+ PopoverState ? get state => _state;
43+
44+ set state (PopoverState ? newState) {
45+ if (_state != null && _state != newState) {
46+ _state? .close ();
47+ }
48+ _state = newState;
49+ notifyListeners ();
50+ }
51+ }
0 commit comments