example_button.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import 'package:flutter/material.dart';
  2. import 'package:appflowy_popover/appflowy_popover.dart';
  3. class PopoverMenu extends StatelessWidget {
  4. final AppFlowyPopoverController popover = AppFlowyPopoverController();
  5. @override
  6. Widget build(BuildContext context) {
  7. return Container(
  8. width: 200,
  9. height: 200,
  10. decoration: const BoxDecoration(color: Colors.yellow),
  11. child: ListView(children: [
  12. const Text("App"),
  13. AppFlowyPopover(
  14. controller: popover,
  15. offset: const Offset(10, 0),
  16. targetAnchor: Alignment.topRight,
  17. followerAnchor: Alignment.topLeft,
  18. popupBuilder: (BuildContext context) {
  19. return PopoverMenu();
  20. },
  21. child: TextButton(
  22. onPressed: () {
  23. popover.show();
  24. },
  25. child: const Text("Second"),
  26. ),
  27. ),
  28. ]),
  29. );
  30. }
  31. }
  32. class ExampleButton extends StatelessWidget {
  33. final AppFlowyPopoverController _popover = AppFlowyPopoverController();
  34. final String label;
  35. final Alignment targetAnchor;
  36. final Alignment followerAnchor;
  37. final Offset? offset;
  38. ExampleButton({
  39. Key? key,
  40. required this.label,
  41. this.targetAnchor = Alignment.topLeft,
  42. this.followerAnchor = Alignment.topLeft,
  43. this.offset = Offset.zero,
  44. }) : super(key: key);
  45. @override
  46. Widget build(BuildContext context) {
  47. return AppFlowyPopover(
  48. controller: _popover,
  49. targetAnchor: targetAnchor,
  50. followerAnchor: followerAnchor,
  51. offset: offset,
  52. child: TextButton(
  53. onPressed: (() {
  54. _popover.show();
  55. }),
  56. child: Text(label),
  57. ),
  58. popupBuilder: (BuildContext context) {
  59. return PopoverMenu();
  60. },
  61. );
  62. }
  63. }