example_button.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import 'package:flutter/material.dart';
  2. import 'package:appflowy_popover/popover.dart';
  3. class PopoverMenu extends StatefulWidget {
  4. @override
  5. State<StatefulWidget> createState() => _PopoverMenuState();
  6. }
  7. class _PopoverMenuState extends State<PopoverMenu> {
  8. final PopoverExclusive exclusive = PopoverExclusive();
  9. late PopoverController firstPopover;
  10. late PopoverController secondPopover;
  11. @override
  12. void initState() {
  13. firstPopover = PopoverController(exclusive: exclusive);
  14. secondPopover = PopoverController(exclusive: exclusive);
  15. super.initState();
  16. }
  17. @override
  18. Widget build(BuildContext context) {
  19. return Container(
  20. width: 200,
  21. height: 200,
  22. decoration: const BoxDecoration(color: Colors.yellow),
  23. child: ListView(children: [
  24. const Text("App"),
  25. Popover(
  26. controller: firstPopover,
  27. offset: const Offset(10, 0),
  28. targetAnchor: Alignment.topRight,
  29. followerAnchor: Alignment.topLeft,
  30. popupBuilder: (BuildContext context) {
  31. return PopoverMenu();
  32. },
  33. child: TextButton(
  34. onPressed: () {
  35. firstPopover.show();
  36. },
  37. onHover: (value) {
  38. if (value) {
  39. firstPopover.show();
  40. }
  41. },
  42. child: const Text("First"),
  43. ),
  44. ),
  45. Popover(
  46. controller: secondPopover,
  47. offset: const Offset(10, 0),
  48. targetAnchor: Alignment.topRight,
  49. followerAnchor: Alignment.topLeft,
  50. popupBuilder: (BuildContext context) {
  51. return PopoverMenu();
  52. },
  53. child: TextButton(
  54. onPressed: () {
  55. secondPopover.show();
  56. },
  57. onHover: (value) {
  58. if (value) {
  59. secondPopover.show();
  60. }
  61. },
  62. child: const Text("Second"),
  63. ),
  64. ),
  65. ]),
  66. );
  67. }
  68. }
  69. class ExampleButton extends StatelessWidget {
  70. final PopoverController _popover = PopoverController();
  71. final String label;
  72. final Alignment targetAnchor;
  73. final Alignment followerAnchor;
  74. final Offset? offset;
  75. ExampleButton({
  76. Key? key,
  77. required this.label,
  78. this.targetAnchor = Alignment.topLeft,
  79. this.followerAnchor = Alignment.topLeft,
  80. this.offset = Offset.zero,
  81. }) : super(key: key);
  82. @override
  83. Widget build(BuildContext context) {
  84. return Popover(
  85. controller: _popover,
  86. targetAnchor: targetAnchor,
  87. followerAnchor: followerAnchor,
  88. offset: offset,
  89. child: TextButton(
  90. onPressed: (() {
  91. _popover.show();
  92. }),
  93. child: Text(label),
  94. ),
  95. popupBuilder: (BuildContext context) {
  96. return PopoverMenu();
  97. },
  98. );
  99. }
  100. }