|
@@ -52,13 +52,13 @@ class AppFlowyPopover extends StatefulWidget {
|
|
State<AppFlowyPopover> createState() => AppFlowyPopoverState();
|
|
State<AppFlowyPopover> createState() => AppFlowyPopoverState();
|
|
}
|
|
}
|
|
|
|
|
|
-final _globalPopovers = List<AppFlowyPopoverState>.empty(growable: true);
|
|
|
|
-
|
|
|
|
class AppFlowyPopoverState extends State<AppFlowyPopover> {
|
|
class AppFlowyPopoverState extends State<AppFlowyPopover> {
|
|
final LayerLink layerLink = LayerLink();
|
|
final LayerLink layerLink = LayerLink();
|
|
OverlayEntry? _overlayEntry;
|
|
OverlayEntry? _overlayEntry;
|
|
bool hasMask = true;
|
|
bool hasMask = true;
|
|
|
|
|
|
|
|
+ static AppFlowyPopoverState? _popoverWithMask;
|
|
|
|
+
|
|
@override
|
|
@override
|
|
void initState() {
|
|
void initState() {
|
|
widget.controller?.state = this;
|
|
widget.controller?.state = this;
|
|
@@ -67,9 +67,11 @@ class AppFlowyPopoverState extends State<AppFlowyPopover> {
|
|
|
|
|
|
showOverlay() {
|
|
showOverlay() {
|
|
debugPrint("show overlay");
|
|
debugPrint("show overlay");
|
|
- _overlayEntry?.remove();
|
|
|
|
|
|
+ close();
|
|
|
|
|
|
- if (_globalPopovers.isNotEmpty) {
|
|
|
|
|
|
+ if (_popoverWithMask == null) {
|
|
|
|
+ _popoverWithMask = this;
|
|
|
|
+ } else {
|
|
hasMask = false;
|
|
hasMask = false;
|
|
}
|
|
}
|
|
debugPrint("has mask: $hasMask");
|
|
debugPrint("has mask: $hasMask");
|
|
@@ -80,13 +82,14 @@ class AppFlowyPopoverState extends State<AppFlowyPopover> {
|
|
if (hasMask) {
|
|
if (hasMask) {
|
|
children.add(_PopoverMask(
|
|
children.add(_PopoverMask(
|
|
decoration: widget.maskDecoration,
|
|
decoration: widget.maskDecoration,
|
|
- onTap: () => _closeAll(),
|
|
|
|
- onExit: () => _closeAll(),
|
|
|
|
|
|
+ onTap: () => close(),
|
|
|
|
+ onExit: () => close(),
|
|
));
|
|
));
|
|
}
|
|
}
|
|
|
|
|
|
children.add(CompositedTransformFollower(
|
|
children.add(CompositedTransformFollower(
|
|
link: layerLink,
|
|
link: layerLink,
|
|
|
|
+ showWhenUnlinked: false,
|
|
offset: widget.offset ?? Offset.zero,
|
|
offset: widget.offset ?? Offset.zero,
|
|
targetAnchor: widget.targetAnchor,
|
|
targetAnchor: widget.targetAnchor,
|
|
followerAnchor: widget.followerAnchor,
|
|
followerAnchor: widget.followerAnchor,
|
|
@@ -94,40 +97,28 @@ class AppFlowyPopoverState extends State<AppFlowyPopover> {
|
|
));
|
|
));
|
|
|
|
|
|
return Stack(children: children);
|
|
return Stack(children: children);
|
|
- // return widget.popupBuilder(context);
|
|
|
|
});
|
|
});
|
|
|
|
|
|
- _globalPopovers.add(this);
|
|
|
|
_overlayEntry = newEntry;
|
|
_overlayEntry = newEntry;
|
|
|
|
|
|
Overlay.of(context)?.insert(newEntry);
|
|
Overlay.of(context)?.insert(newEntry);
|
|
}
|
|
}
|
|
|
|
|
|
- _closeAll() {
|
|
|
|
- final copiedArr = [..._globalPopovers];
|
|
|
|
- for (var i = copiedArr.length - 1; i >= 0; i--) {
|
|
|
|
- copiedArr[i].close();
|
|
|
|
- }
|
|
|
|
- _globalPopovers.clear();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
close() {
|
|
close() {
|
|
- if (_globalPopovers.last == this) {
|
|
|
|
- _globalPopovers.removeLast();
|
|
|
|
|
|
+ if (_overlayEntry != null) {
|
|
|
|
+ _overlayEntry!.remove();
|
|
|
|
+ _overlayEntry = null;
|
|
|
|
+ if (_popoverWithMask == this) {
|
|
|
|
+ _popoverWithMask = null;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- _overlayEntry?.remove();
|
|
|
|
- _overlayEntry = null;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
- void dispose() {
|
|
|
|
- debugPrint("popover dispose");
|
|
|
|
- _overlayEntry?.remove();
|
|
|
|
- _overlayEntry = null;
|
|
|
|
- if (hasMask) {
|
|
|
|
- debugPrint("popover len: ${_globalPopovers.length}");
|
|
|
|
- }
|
|
|
|
- super.dispose();
|
|
|
|
|
|
+ void deactivate() {
|
|
|
|
+ debugPrint("deactivate");
|
|
|
|
+ close();
|
|
|
|
+ super.deactivate();
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -168,9 +159,9 @@ class _PopoverMaskState extends State<_PopoverMask> {
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
- void dispose() {
|
|
|
|
|
|
+ void deactivate() {
|
|
HardwareKeyboard.instance.removeHandler(_handleGlobalKeyEvent);
|
|
HardwareKeyboard.instance.removeHandler(_handleGlobalKeyEvent);
|
|
- super.dispose();
|
|
|
|
|
|
+ super.deactivate();
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|