Skip to content

Commit ca89fd9

Browse files
committed
fix: notify state changed after set state
1 parent ba3f2f3 commit ca89fd9

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

frontend/app_flowy/lib/plugins/grid/presentation/widgets/header/field_editor.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ class _FieldNameTextFieldState extends State<_FieldNameTextField> {
201201

202202
void listenOnPopoverChanged(BuildContext context) {
203203
if (_popoverCallback != null) {
204-
widget.popoverMutex.removePopoverStateListener(_popoverCallback!);
204+
widget.popoverMutex.removePopoverListener(_popoverCallback!);
205205
}
206-
_popoverCallback = widget.popoverMutex.listenOnPopoverStateChanged(() {
206+
_popoverCallback = widget.popoverMutex.listenOnPopoverChanged(() {
207207
if (focusNode.hasFocus) {
208208
final node = FocusScope.of(context);
209209
node.unfocus();

frontend/app_flowy/packages/appflowy_popover/lib/src/mutex.dart

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import 'popover.dart';
55
/// If multiple popovers are exclusive,
66
/// pass the same mutex to them.
77
class 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

Comments
 (0)