AppFlowy/frontend/appflowy_flutter/packages/appflowy_popover
Mathias Mogensen cdfb634aa6
chore: upgrade flutter to 3.10.1 (#2619)
* chore: upgrade flutter and dart

* ci: upgrade flutter in cicd

* fix: remove textstyle_extensions from flowy_infra

* ci: upgrade flutter in cicd

* fix: update flutter.toml

* fix: deprecations and ffi

* fix: move json_annotation to dependencies

Must have accidentally moved it to dev_dependencies when upgrading dependencies

* fix: update editor ref and use fold

* chore: try with generate true
2023-05-28 12:09:39 +08:00
..
example chore: upgrade flutter to 3.10.1 (#2619) 2023-05-28 12:09:39 +08:00
lib chore: update to Flutter 3.7.5 (#2000) 2023-04-04 12:48:56 +08:00
test Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
.gitignore Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
.metadata Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
analysis_options.yaml Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
CHANGELOG.md Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
LICENSE Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
pubspec.yaml chore: upgrade flutter to 3.10.1 (#2619) 2023-05-28 12:09:39 +08:00
README.md Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00
screenshot.png Feat/view map database (#1885) 2023-02-26 16:27:17 +08:00

AppFlowy Popover

A Popover can be used to display some content on top of another.

It can be used to display a dropdown menu.

A popover is a transient view that appears above other content onscreen when you tap a control or in an area. Typically, a popover includes an arrow pointing to the location from which it emerged. Popovers can be nonmodal or modal. A nonmodal popover is dismissed by tapping another part of the screen or a button on the popover. A modal popover is dismissed by tapping a Cancel or other button on the popover.

Source: Human Interface Guidelines.

Features

  • Basic popover style
  • Follow the target automatically
  • Nested popover support
  • Exclusive API

Example

Popover(
  // Define how to trigger the popover
  triggerActions: PopoverTriggerActionFlags.click,
  child: TextButton(child: Text("Popover"), onPressed: () {}),
  // Define the direction of the popover
  direction: PopoverDirection.bottomWithLeftAligned,
  popupBuilder(BuildContext context) {
    return PopoverMenu();
  },
);

Trigger the popover manually

Sometimes, if you want to trigger the popover manually, you can use a PopoverController.

class MyWidgetState extends State<GridDateCell> {
  late PopoverController _popover;

  @override
  void initState() {
    _popover = PopoverController();
    super.initState();
  }

  // triggered by another widget
  _onClick() {
    _popover.show();
  }

  @override
  Widget build(BuildContext context) {
    return Popover(
      controller: _popover,
      ...
    )
  }
}

Make several popovers exclusive

The popover has a mechanism to make sure there are only one popover is shown in a group of popovers. It's called PopoverMutex.

If you pass the same mutex object to the popovers, there will be only one popover is triggered.

class MyWidgetState extends State<GridDateCell> {
  final _popoverMutex = PopoverMutex();

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Popover(
          mutex: _popoverMutex,
          ...
        ),
        Popover(
          mutex: _popoverMutex,
          ...
        ),
        Popover(
          mutex: _popoverMutex,
          ...
        ),
      ]
    )
  }
}

API

Param Description Type
offset The offset between the popover and the child Offset
popupBuilder The function used to build the popover Widget Function(BuildContext context)
triggerActions Define the actions about how to trigger the popover int
mutex If multiple popovers are exclusive, pass the same mutex to them. PopoverMutex
direction The direction where the popover should be placed PopoverDirection
onClose The callback will be called after the popover is closed void Function()
child The child to trigger the popover Widget