example_button.dart 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:flutter/material.dart';
  2. import 'package:appflowy_popover/appflowy_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 Material(
  13. type: MaterialType.transparency,
  14. child: Container(
  15. width: 200,
  16. height: 200,
  17. decoration: BoxDecoration(
  18. color: Colors.white,
  19. borderRadius: const BorderRadius.all(Radius.circular(8)),
  20. boxShadow: [
  21. BoxShadow(
  22. color: Colors.grey.withOpacity(0.5),
  23. spreadRadius: 5,
  24. blurRadius: 7,
  25. offset: const Offset(0, 3), // changes position of shadow
  26. ),
  27. ],
  28. ),
  29. child: ListView(children: [
  30. Container(
  31. margin: const EdgeInsets.all(8),
  32. child: const Text("Popover",
  33. style: TextStyle(
  34. fontSize: 14,
  35. color: Colors.black,
  36. fontStyle: null,
  37. decoration: null)),
  38. ),
  39. Popover(
  40. triggerActions:
  41. PopoverTriggerFlags.hover | PopoverTriggerFlags.click,
  42. mutex: popOverMutex,
  43. offset: const Offset(10, 0),
  44. popupBuilder: (BuildContext context) {
  45. return const PopoverMenu();
  46. },
  47. child: TextButton(
  48. onPressed: () {},
  49. child: const Text("First"),
  50. ),
  51. ),
  52. Popover(
  53. triggerActions:
  54. PopoverTriggerFlags.hover | PopoverTriggerFlags.click,
  55. mutex: popOverMutex,
  56. offset: const Offset(10, 0),
  57. popupBuilder: (BuildContext context) {
  58. return const PopoverMenu();
  59. },
  60. child: TextButton(
  61. onPressed: () {},
  62. child: const Text("Second"),
  63. ),
  64. ),
  65. ]),
  66. ));
  67. }
  68. }
  69. class ExampleButton extends StatelessWidget {
  70. final String label;
  71. final Offset? offset;
  72. final PopoverDirection? direction;
  73. const ExampleButton({
  74. Key? key,
  75. required this.label,
  76. this.direction,
  77. this.offset = Offset.zero,
  78. }) : super(key: key);
  79. @override
  80. Widget build(BuildContext context) {
  81. return Popover(
  82. triggerActions: PopoverTriggerFlags.click,
  83. offset: offset,
  84. direction: direction ?? PopoverDirection.rightWithTopAligned,
  85. child: TextButton(child: Text(label), onPressed: () {}),
  86. popupBuilder: (BuildContext context) {
  87. return const PopoverMenu();
  88. },
  89. );
  90. }
  91. }