mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: add exclusive
This commit is contained in:
parent
072d94ebe6
commit
defef552ed
@ -7,8 +7,17 @@ class PopoverMenu extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _PopoverMenuState extends State<PopoverMenu> {
|
class _PopoverMenuState extends State<PopoverMenu> {
|
||||||
final AppFlowyPopoverController popover = AppFlowyPopoverController();
|
final AppFlowyPopoverExclusive exclusive = AppFlowyPopoverExclusive();
|
||||||
final AppFlowyPopoverController hoverPopover = AppFlowyPopoverController();
|
late AppFlowyPopoverController firstPopover;
|
||||||
|
late AppFlowyPopoverController secondPopover;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
firstPopover = AppFlowyPopoverController(exclusive: exclusive);
|
||||||
|
secondPopover = AppFlowyPopoverController(exclusive: exclusive);
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@ -18,7 +27,7 @@ class _PopoverMenuState extends State<PopoverMenu> {
|
|||||||
child: ListView(children: [
|
child: ListView(children: [
|
||||||
const Text("App"),
|
const Text("App"),
|
||||||
AppFlowyPopover(
|
AppFlowyPopover(
|
||||||
controller: popover,
|
controller: firstPopover,
|
||||||
offset: const Offset(10, 0),
|
offset: const Offset(10, 0),
|
||||||
targetAnchor: Alignment.topRight,
|
targetAnchor: Alignment.topRight,
|
||||||
followerAnchor: Alignment.topLeft,
|
followerAnchor: Alignment.topLeft,
|
||||||
@ -27,20 +36,18 @@ class _PopoverMenuState extends State<PopoverMenu> {
|
|||||||
},
|
},
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
popover.show();
|
firstPopover.show();
|
||||||
},
|
},
|
||||||
onHover: (value) {
|
onHover: (value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
popover.show();
|
firstPopover.show();
|
||||||
} else {
|
|
||||||
popover.close();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text("First"),
|
child: const Text("First"),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
AppFlowyPopover(
|
AppFlowyPopover(
|
||||||
controller: hoverPopover,
|
controller: secondPopover,
|
||||||
offset: const Offset(10, 0),
|
offset: const Offset(10, 0),
|
||||||
targetAnchor: Alignment.topRight,
|
targetAnchor: Alignment.topRight,
|
||||||
followerAnchor: Alignment.topLeft,
|
followerAnchor: Alignment.topLeft,
|
||||||
@ -49,13 +56,11 @@ class _PopoverMenuState extends State<PopoverMenu> {
|
|||||||
},
|
},
|
||||||
child: TextButton(
|
child: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
hoverPopover.show();
|
secondPopover.show();
|
||||||
},
|
},
|
||||||
onHover: (value) {
|
onHover: (value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
hoverPopover.show();
|
secondPopover.show();
|
||||||
} else {
|
|
||||||
hoverPopover.close();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Text("Second"),
|
child: const Text("Second"),
|
||||||
|
@ -1,14 +1,29 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
|
class AppFlowyPopoverExclusive {
|
||||||
|
AppFlowyPopoverController? controller;
|
||||||
|
}
|
||||||
|
|
||||||
class AppFlowyPopoverController {
|
class AppFlowyPopoverController {
|
||||||
AppFlowyPopoverState? state;
|
AppFlowyPopoverState? state;
|
||||||
|
AppFlowyPopoverExclusive? exclusive;
|
||||||
|
|
||||||
|
AppFlowyPopoverController({this.exclusive});
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
state?.close();
|
state?.close();
|
||||||
|
if (exclusive != null && exclusive!.controller == this) {
|
||||||
|
exclusive!.controller = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
show() {
|
show() {
|
||||||
|
if (exclusive != null) {
|
||||||
|
debugPrint("show popover");
|
||||||
|
exclusive!.controller?.close();
|
||||||
|
exclusive!.controller = this;
|
||||||
|
}
|
||||||
state?.showOverlay();
|
state?.showOverlay();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -110,7 +125,7 @@ class AppFlowyPopoverState extends State<AppFlowyPopover> {
|
|||||||
_overlayEntry?.remove();
|
_overlayEntry?.remove();
|
||||||
_overlayEntry = null;
|
_overlayEntry = null;
|
||||||
if (hasMask) {
|
if (hasMask) {
|
||||||
debugPrint("len: ${_globalPopovers.length}");
|
debugPrint("popover len: ${_globalPopovers.length}");
|
||||||
}
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user