Skip to content

Commit 4d83575

Browse files
committed
fix: select option pannel didn't disappear
1 parent 39b0fe6 commit 4d83575

File tree

3 files changed

+61
-25
lines changed

3 files changed

+61
-25
lines changed

frontend/app_flowy/lib/plugins/board/presentation/toolbar/board_setting.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class BoardSettingList extends StatelessWidget {
5050
previous.selectedAction != current.selectedAction,
5151
listener: (context, state) {
5252
state.selectedAction.foldLeft(null, (_, action) {
53-
// FlowyOverlay.of(context).remove(identifier());
5453
onAction(action, settingContext);
5554
});
5655
},

frontend/app_flowy/lib/plugins/grid/presentation/widgets/cell/select_option_cell/select_option_editor.dart

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,47 @@ import 'text_field.dart';
2525

2626
const double _editorPanelWidth = 300;
2727

28-
class SelectOptionCellEditor extends StatelessWidget {
28+
class SelectOptionCellEditor extends StatefulWidget {
2929
final GridSelectOptionCellController cellController;
30-
3130
static double editorPanelWidth = 300;
3231

3332
const SelectOptionCellEditor({required this.cellController, Key? key})
3433
: super(key: key);
3534

35+
@override
36+
State<SelectOptionCellEditor> createState() => _SelectOptionCellEditorState();
37+
}
38+
39+
class _SelectOptionCellEditorState extends State<SelectOptionCellEditor> {
40+
late PopoverMutex popoverMutex;
41+
42+
@override
43+
void initState() {
44+
popoverMutex = PopoverMutex();
45+
super.initState();
46+
}
47+
3648
@override
3749
Widget build(BuildContext context) {
3850
return BlocProvider(
3951
create: (context) => SelectOptionCellEditorBloc(
40-
cellController: cellController,
52+
cellController: widget.cellController,
4153
)..add(const SelectOptionEditorEvent.initial()),
4254
child: BlocBuilder<SelectOptionCellEditorBloc, SelectOptionEditorState>(
4355
builder: (context, state) {
4456
return CustomScrollView(
4557
shrinkWrap: true,
4658
slivers: [
47-
SliverToBoxAdapter(child: _TextField()),
59+
SliverToBoxAdapter(
60+
child: _TextField(popoverMutex: popoverMutex),
61+
),
4862
const SliverToBoxAdapter(child: VSpace(6)),
4963
const SliverToBoxAdapter(child: TypeOptionSeparator()),
5064
const SliverToBoxAdapter(child: VSpace(6)),
5165
const SliverToBoxAdapter(child: _Title()),
52-
const SliverToBoxAdapter(child: _OptionList()),
66+
SliverToBoxAdapter(
67+
child: _OptionList(popoverMutex: popoverMutex),
68+
),
5369
],
5470
);
5571
},
@@ -59,7 +75,11 @@ class SelectOptionCellEditor extends StatelessWidget {
5975
}
6076

6177
class _OptionList extends StatelessWidget {
62-
const _OptionList({Key? key}) : super(key: key);
78+
final PopoverMutex popoverMutex;
79+
const _OptionList({
80+
required this.popoverMutex,
81+
Key? key,
82+
}) : super(key: key);
6383

6484
@override
6585
Widget build(BuildContext context) {
@@ -68,7 +88,10 @@ class _OptionList extends StatelessWidget {
6888
List<Widget> cells = [];
6989
cells.addAll(state.options.map((option) {
7090
return _SelectOptionCell(
71-
option, state.selectedOptions.contains(option));
91+
option: option,
92+
isSelected: state.selectedOptions.contains(option),
93+
popoverMutex: popoverMutex,
94+
);
7295
}).toList());
7396

7497
state.createOption.fold(
@@ -101,9 +124,13 @@ class _OptionList extends StatelessWidget {
101124
}
102125

103126
class _TextField extends StatelessWidget {
127+
final PopoverMutex popoverMutex;
104128
final TextfieldTagsController _tagController = TextfieldTagsController();
105129

106-
_TextField({Key? key}) : super(key: key);
130+
_TextField({
131+
required this.popoverMutex,
132+
Key? key,
133+
}) : super(key: key);
107134

108135
@override
109136
Widget build(BuildContext context) {
@@ -121,8 +148,11 @@ class _TextField extends StatelessWidget {
121148
selectedOptionMap: optionMap,
122149
distanceToText: _editorPanelWidth * 0.7,
123150
tagController: _tagController,
124-
onClick: () => FlowyOverlay.of(context)
125-
.remove(SelectOptionTypeOptionEditor.identifier),
151+
onClick: () {
152+
popoverMutex.close();
153+
// FlowyOverlay.of(context)
154+
// .remove(SelectOptionTypeOptionEditor.identifier);
155+
},
126156
newText: (text) {
127157
context
128158
.read<SelectOptionCellEditorBloc>()
@@ -189,9 +219,14 @@ class _CreateOptionCell extends StatelessWidget {
189219

190220
class _SelectOptionCell extends StatefulWidget {
191221
final SelectOptionPB option;
222+
final PopoverMutex popoverMutex;
192223
final bool isSelected;
193-
const _SelectOptionCell(this.option, this.isSelected, {Key? key})
194-
: super(key: key);
224+
const _SelectOptionCell({
225+
required this.option,
226+
required this.isSelected,
227+
required this.popoverMutex,
228+
Key? key,
229+
}) : super(key: key);
195230

196231
@override
197232
State<_SelectOptionCell> createState() => _SelectOptionCellState();
@@ -213,6 +248,7 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
213248
controller: _popoverController,
214249
offset: const Offset(20, 0),
215250
constraints: BoxConstraints.loose(const Size(200, 300)),
251+
mutex: widget.popoverMutex,
216252
child: SizedBox(
217253
height: GridSize.typeOptionItemHeight,
218254
child: Row(
@@ -257,8 +293,9 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
257293
.read<SelectOptionCellEditorBloc>()
258294
.add(SelectOptionEditorEvent.updateOption(updatedOption));
259295
},
260-
key: ValueKey(widget.option
261-
.id), // Use ValueKey to refresh the UI, otherwise, it will remain the old value.
296+
key: ValueKey(
297+
widget.option.id,
298+
), // Use ValueKey to refresh the UI, otherwise, it will remain the old value.
262299
);
263300
},
264301
);

frontend/app_flowy/packages/appflowy_popover/lib/popover.dart

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,41 @@ import 'package:flutter/services.dart';
66
/// If multiple popovers are exclusive,
77
/// pass the same mutex to them.
88
class PopoverMutex {
9-
final ValueNotifier<PopoverState?> _stateNofitier = ValueNotifier(null);
9+
final ValueNotifier<PopoverState?> _stateNotifier = ValueNotifier(null);
1010
PopoverMutex();
1111

1212
void removePopoverStateListener(VoidCallback listener) {
13-
_stateNofitier.removeListener(listener);
13+
_stateNotifier.removeListener(listener);
1414
}
1515

1616
VoidCallback listenOnPopoverStateChanged(VoidCallback callback) {
1717
listenerCallback() {
1818
callback();
1919
}
2020

21-
_stateNofitier.addListener(listenerCallback);
21+
_stateNotifier.addListener(listenerCallback);
2222
return listenerCallback;
2323
}
2424

2525
void close() {
26-
_stateNofitier.value?.close();
26+
_stateNotifier.value?.close();
2727
}
2828

29-
PopoverState? get state => _stateNofitier.value;
29+
PopoverState? get state => _stateNotifier.value;
3030

3131
set state(PopoverState? newState) {
32-
if (_stateNofitier.value != null && _stateNofitier.value != newState) {
33-
_stateNofitier.value?.close();
32+
if (_stateNotifier.value != null && _stateNotifier.value != newState) {
33+
_stateNotifier.value?.close();
3434
}
35-
_stateNofitier.value = newState;
35+
_stateNotifier.value = newState;
3636
}
3737

3838
void _removeState() {
39-
_stateNofitier.value = null;
39+
_stateNotifier.value = null;
4040
}
4141

4242
void dispose() {
43-
_stateNofitier.dispose();
43+
_stateNotifier.dispose();
4444
}
4545
}
4646

0 commit comments

Comments
 (0)