@@ -25,31 +25,47 @@ import 'text_field.dart';
2525
2626const 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
6177class _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
103126class _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
190220class _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 );
0 commit comments