example_button.dart 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import 'package:flutter/material.dart';
  2. import 'package:appflowy_popover/popover.dart';
  3. class PopoverMenu extends StatefulWidget {
  4. const PopoverMenu({Key? key}) : super(key: key);
  5. @override
  6. State<StatefulWidget> createState() => _PopoverMenuState();
  7. }
  8. class _PopoverMenuState extends State<PopoverMenu> {
  9. final PopoverMutex popOverMutex = PopoverMutex();
  10. @override
  11. Widget build(BuildContext context) {
  12. return Container(
  13. width: 200,
  14. height: 200,
  15. decoration: const BoxDecoration(color: Colors.yellow),
  16. child: ListView(children: [
  17. const Text("App"),
  18. Popover(
  19. triggerActions:
  20. PopoverTriggerActionFlags.hover | PopoverTriggerActionFlags.click,
  21. mutex: popOverMutex,
  22. offset: const Offset(10, 0),
  23. popupBuilder: (BuildContext context) {
  24. return const PopoverMenu();
  25. },
  26. child: TextButton(
  27. onPressed: () {},
  28. child: const Text("First"),
  29. ),
  30. ),
  31. Popover(
  32. triggerActions:
  33. PopoverTriggerActionFlags.hover | PopoverTriggerActionFlags.click,
  34. mutex: popOverMutex,
  35. offset: const Offset(10, 0),
  36. popupBuilder: (BuildContext context) {
  37. return const PopoverMenu();
  38. },
  39. child: TextButton(
  40. onPressed: () {},
  41. child: const Text("Second"),
  42. ),
  43. ),
  44. ]),
  45. );
  46. }
  47. }
  48. class ExampleButton extends StatelessWidget {
  49. final String label;
  50. final Offset? offset;
  51. final PopoverDirection? direction;
  52. const ExampleButton({
  53. Key? key,
  54. required this.label,
  55. this.direction,
  56. this.offset = Offset.zero,
  57. }) : super(key: key);
  58. @override
  59. Widget build(BuildContext context) {
  60. return Popover(
  61. triggerActions: PopoverTriggerActionFlags.click,
  62. offset: offset,
  63. direction: direction ?? PopoverDirection.rightWithTopAligned,
  64. child: TextButton(child: Text(label), onPressed: () {}),
  65. popupBuilder: (BuildContext context) {
  66. return const PopoverMenu();
  67. },
  68. );
  69. }
  70. }