mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: select option pannel didn't disappear
This commit is contained in:
parent
39b0fe69b5
commit
4d835757d2
@ -50,7 +50,6 @@ class BoardSettingList extends StatelessWidget {
|
||||
previous.selectedAction != current.selectedAction,
|
||||
listener: (context, state) {
|
||||
state.selectedAction.foldLeft(null, (_, action) {
|
||||
// FlowyOverlay.of(context).remove(identifier());
|
||||
onAction(action, settingContext);
|
||||
});
|
||||
},
|
||||
|
@ -25,31 +25,47 @@ import 'text_field.dart';
|
||||
|
||||
const double _editorPanelWidth = 300;
|
||||
|
||||
class SelectOptionCellEditor extends StatelessWidget {
|
||||
class SelectOptionCellEditor extends StatefulWidget {
|
||||
final GridSelectOptionCellController cellController;
|
||||
|
||||
static double editorPanelWidth = 300;
|
||||
|
||||
const SelectOptionCellEditor({required this.cellController, Key? key})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
State<SelectOptionCellEditor> createState() => _SelectOptionCellEditorState();
|
||||
}
|
||||
|
||||
class _SelectOptionCellEditorState extends State<SelectOptionCellEditor> {
|
||||
late PopoverMutex popoverMutex;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
popoverMutex = PopoverMutex();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider(
|
||||
create: (context) => SelectOptionCellEditorBloc(
|
||||
cellController: cellController,
|
||||
cellController: widget.cellController,
|
||||
)..add(const SelectOptionEditorEvent.initial()),
|
||||
child: BlocBuilder<SelectOptionCellEditorBloc, SelectOptionEditorState>(
|
||||
builder: (context, state) {
|
||||
return CustomScrollView(
|
||||
shrinkWrap: true,
|
||||
slivers: [
|
||||
SliverToBoxAdapter(child: _TextField()),
|
||||
SliverToBoxAdapter(
|
||||
child: _TextField(popoverMutex: popoverMutex),
|
||||
),
|
||||
const SliverToBoxAdapter(child: VSpace(6)),
|
||||
const SliverToBoxAdapter(child: TypeOptionSeparator()),
|
||||
const SliverToBoxAdapter(child: VSpace(6)),
|
||||
const SliverToBoxAdapter(child: _Title()),
|
||||
const SliverToBoxAdapter(child: _OptionList()),
|
||||
SliverToBoxAdapter(
|
||||
child: _OptionList(popoverMutex: popoverMutex),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
@ -59,7 +75,11 @@ class SelectOptionCellEditor extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _OptionList extends StatelessWidget {
|
||||
const _OptionList({Key? key}) : super(key: key);
|
||||
final PopoverMutex popoverMutex;
|
||||
const _OptionList({
|
||||
required this.popoverMutex,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -68,7 +88,10 @@ class _OptionList extends StatelessWidget {
|
||||
List<Widget> cells = [];
|
||||
cells.addAll(state.options.map((option) {
|
||||
return _SelectOptionCell(
|
||||
option, state.selectedOptions.contains(option));
|
||||
option: option,
|
||||
isSelected: state.selectedOptions.contains(option),
|
||||
popoverMutex: popoverMutex,
|
||||
);
|
||||
}).toList());
|
||||
|
||||
state.createOption.fold(
|
||||
@ -101,9 +124,13 @@ class _OptionList extends StatelessWidget {
|
||||
}
|
||||
|
||||
class _TextField extends StatelessWidget {
|
||||
final PopoverMutex popoverMutex;
|
||||
final TextfieldTagsController _tagController = TextfieldTagsController();
|
||||
|
||||
_TextField({Key? key}) : super(key: key);
|
||||
_TextField({
|
||||
required this.popoverMutex,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -121,8 +148,11 @@ class _TextField extends StatelessWidget {
|
||||
selectedOptionMap: optionMap,
|
||||
distanceToText: _editorPanelWidth * 0.7,
|
||||
tagController: _tagController,
|
||||
onClick: () => FlowyOverlay.of(context)
|
||||
.remove(SelectOptionTypeOptionEditor.identifier),
|
||||
onClick: () {
|
||||
popoverMutex.close();
|
||||
// FlowyOverlay.of(context)
|
||||
// .remove(SelectOptionTypeOptionEditor.identifier);
|
||||
},
|
||||
newText: (text) {
|
||||
context
|
||||
.read<SelectOptionCellEditorBloc>()
|
||||
@ -189,9 +219,14 @@ class _CreateOptionCell extends StatelessWidget {
|
||||
|
||||
class _SelectOptionCell extends StatefulWidget {
|
||||
final SelectOptionPB option;
|
||||
final PopoverMutex popoverMutex;
|
||||
final bool isSelected;
|
||||
const _SelectOptionCell(this.option, this.isSelected, {Key? key})
|
||||
: super(key: key);
|
||||
const _SelectOptionCell({
|
||||
required this.option,
|
||||
required this.isSelected,
|
||||
required this.popoverMutex,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<_SelectOptionCell> createState() => _SelectOptionCellState();
|
||||
@ -213,6 +248,7 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
|
||||
controller: _popoverController,
|
||||
offset: const Offset(20, 0),
|
||||
constraints: BoxConstraints.loose(const Size(200, 300)),
|
||||
mutex: widget.popoverMutex,
|
||||
child: SizedBox(
|
||||
height: GridSize.typeOptionItemHeight,
|
||||
child: Row(
|
||||
@ -257,8 +293,9 @@ class _SelectOptionCellState extends State<_SelectOptionCell> {
|
||||
.read<SelectOptionCellEditorBloc>()
|
||||
.add(SelectOptionEditorEvent.updateOption(updatedOption));
|
||||
},
|
||||
key: ValueKey(widget.option
|
||||
.id), // Use ValueKey to refresh the UI, otherwise, it will remain the old value.
|
||||
key: ValueKey(
|
||||
widget.option.id,
|
||||
), // Use ValueKey to refresh the UI, otherwise, it will remain the old value.
|
||||
);
|
||||
},
|
||||
);
|
||||
|
@ -6,11 +6,11 @@ import 'package:flutter/services.dart';
|
||||
/// If multiple popovers are exclusive,
|
||||
/// pass the same mutex to them.
|
||||
class PopoverMutex {
|
||||
final ValueNotifier<PopoverState?> _stateNofitier = ValueNotifier(null);
|
||||
final ValueNotifier<PopoverState?> _stateNotifier = ValueNotifier(null);
|
||||
PopoverMutex();
|
||||
|
||||
void removePopoverStateListener(VoidCallback listener) {
|
||||
_stateNofitier.removeListener(listener);
|
||||
_stateNotifier.removeListener(listener);
|
||||
}
|
||||
|
||||
VoidCallback listenOnPopoverStateChanged(VoidCallback callback) {
|
||||
@ -18,29 +18,29 @@ class PopoverMutex {
|
||||
callback();
|
||||
}
|
||||
|
||||
_stateNofitier.addListener(listenerCallback);
|
||||
_stateNotifier.addListener(listenerCallback);
|
||||
return listenerCallback;
|
||||
}
|
||||
|
||||
void close() {
|
||||
_stateNofitier.value?.close();
|
||||
_stateNotifier.value?.close();
|
||||
}
|
||||
|
||||
PopoverState? get state => _stateNofitier.value;
|
||||
PopoverState? get state => _stateNotifier.value;
|
||||
|
||||
set state(PopoverState? newState) {
|
||||
if (_stateNofitier.value != null && _stateNofitier.value != newState) {
|
||||
_stateNofitier.value?.close();
|
||||
if (_stateNotifier.value != null && _stateNotifier.value != newState) {
|
||||
_stateNotifier.value?.close();
|
||||
}
|
||||
_stateNofitier.value = newState;
|
||||
_stateNotifier.value = newState;
|
||||
}
|
||||
|
||||
void _removeState() {
|
||||
_stateNofitier.value = null;
|
||||
_stateNotifier.value = null;
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
_stateNofitier.dispose();
|
||||
_stateNotifier.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user