example_button.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 PopoverMutex popOverMutex = PopoverMutex();
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. width: 200,
  13. height: 200,
  14. decoration: const BoxDecoration(color: Colors.yellow),
  15. child: ListView(children: [
  16. const Text("App"),
  17. Popover(
  18. triggerActions:
  19. PopoverTriggerActionFlags.hover | PopoverTriggerActionFlags.click,
  20. mutex: popOverMutex,
  21. offset: const Offset(10, 0),
  22. targetAnchor: Alignment.topRight,
  23. followerAnchor: Alignment.topLeft,
  24. popupBuilder: (BuildContext context) {
  25. return PopoverMenu();
  26. },
  27. child: TextButton(
  28. onPressed: () {},
  29. child: const Text("First"),
  30. ),
  31. ),
  32. Popover(
  33. triggerActions:
  34. PopoverTriggerActionFlags.hover | PopoverTriggerActionFlags.click,
  35. mutex: popOverMutex,
  36. offset: const Offset(10, 0),
  37. targetAnchor: Alignment.topRight,
  38. followerAnchor: Alignment.topLeft,
  39. popupBuilder: (BuildContext context) {
  40. return PopoverMenu();
  41. },
  42. child: TextButton(
  43. onPressed: () {},
  44. child: const Text("Second"),
  45. ),
  46. ),
  47. ]),
  48. );
  49. }
  50. }
  51. class ExampleButton extends StatelessWidget {
  52. final String label;
  53. final Alignment targetAnchor;
  54. final Alignment followerAnchor;
  55. final Offset? offset;
  56. const ExampleButton({
  57. Key? key,
  58. required this.label,
  59. this.targetAnchor = Alignment.topLeft,
  60. this.followerAnchor = Alignment.topLeft,
  61. this.offset = Offset.zero,
  62. }) : super(key: key);
  63. @override
  64. Widget build(BuildContext context) {
  65. return Popover(
  66. targetAnchor: targetAnchor,
  67. followerAnchor: followerAnchor,
  68. triggerActions: PopoverTriggerActionFlags.click,
  69. offset: offset,
  70. child: TextButton(child: Text(label), onPressed: () {}),
  71. popupBuilder: (BuildContext context) {
  72. return PopoverMenu();
  73. },
  74. );
  75. }
  76. }