example_button.dart 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. popupBuilder: (BuildContext context) {
  23. return PopoverMenu();
  24. },
  25. child: TextButton(
  26. onPressed: () {},
  27. child: const Text("First"),
  28. ),
  29. ),
  30. Popover(
  31. triggerActions:
  32. PopoverTriggerActionFlags.hover | PopoverTriggerActionFlags.click,
  33. mutex: popOverMutex,
  34. offset: const Offset(10, 0),
  35. popupBuilder: (BuildContext context) {
  36. return PopoverMenu();
  37. },
  38. child: TextButton(
  39. onPressed: () {},
  40. child: const Text("Second"),
  41. ),
  42. ),
  43. ]),
  44. );
  45. }
  46. }
  47. class ExampleButton extends StatelessWidget {
  48. final String label;
  49. final Offset? offset;
  50. final PopoverDirection? direction;
  51. const ExampleButton({
  52. Key? key,
  53. required this.label,
  54. this.direction,
  55. this.offset = Offset.zero,
  56. }) : super(key: key);
  57. @override
  58. Widget build(BuildContext context) {
  59. return Popover(
  60. triggerActions: PopoverTriggerActionFlags.click,
  61. offset: offset,
  62. direction: direction ?? PopoverDirection.rightWithTopAligned,
  63. child: TextButton(child: Text(label), onPressed: () {}),
  64. popupBuilder: (BuildContext context) {
  65. return PopoverMenu();
  66. },
  67. );
  68. }
  69. }