AnchoredPopupMenuButton<T> class
A reusable popup menu trigger that opens a custom menu anchored to itself.
The public API is intentionally split into:
- Core behavior: items, onSelected, triggerBuilder
- Layout tweaks: layout
- Visual styling: style
The menu resolves its vertical placement from layout, then keeps itself inside the safe area and screen padding. Consumers provide the visual trigger through triggerBuilder, keeping menu behavior reusable across different surfaces.
Example:
AnchoredPopupMenuButton<String>(
items: const [
PopupMenuItem(
value: 'refresh',
child: Text('Refresh'),
),
],
onSelected: print,
style: const AnchoredPopupMenuStyle(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
),
triggerBuilder: (context, onPressed) {
return FilledButton.icon(
onPressed: onPressed,
icon: const Icon(Icons.more_vert),
label: const Text('Open menu'),
);
},
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- AnchoredPopupMenuButton
Constructors
-
AnchoredPopupMenuButton({Key? key, required List<
PopupMenuEntry< items, required ValueChanged<T> >T> onSelected, required Widget triggerBuilder(BuildContext context, VoidCallback? onPressed), bool enabled = true, String? tooltip, AnchoredPopupMenuLayout layout = const AnchoredPopupMenuLayout(), AnchoredPopupMenuStyle style = const AnchoredPopupMenuStyle()}) -
Creates an anchored popup menu trigger.
const
Properties
- enabled → bool
-
Whether the trigger can open the popup menu.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
items
→ List<
PopupMenuEntry< T> > -
The popup menu entries shown when the trigger is pressed.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- layout → AnchoredPopupMenuLayout
-
Sizing and positioning configuration for the popup menu.
final
-
onSelected
→ ValueChanged<
T> -
Called with the selected value after the popup menu closes.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- style → AnchoredPopupMenuStyle
-
Surface and transition styling for the popup menu.
final
- tooltip → String?
-
Optional tooltip shown around the trigger.
final
- triggerBuilder → Widget Function(BuildContext context, VoidCallback? onPressed)
-
Builds the visual trigger.
final
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited