builder property

MenuAcceleratorChildBuilder builder
final

The optional MenuAcceleratorChildBuilder which is used to build the widget that displays the label itself.

The defaultLabelBuilder function serves as the default value for builder, rendering the label as a RichText widget with appropriate TextSpans for rendering the label with an underscore under the selected accelerator for the label when accelerators have been activated.

The arguments to the function are as follows:

  • The context supplies the BuildContext to use.
  • The label is the MenuAcceleratorLabel.label attribute for the relevant MenuAcceleratorLabel with the accelerator markers stripped out of it.
  • The index is the index of the accelerator character within the label.characters that applies to this accelerator. If it is -1, then the accelerator should not be highlighted. Otherwise, the given character should be highlighted somehow in the rendered label (typically with an underscore). Importantly, index is not an index into the String label, it is an index into the Characters iterable returned by label.characters, so that it is in terms of user-visible characters (a.k.a. grapheme clusters), not Unicode code points.

When writing the builder function, it's not necessary to take the current platform into account. On platforms which don't support accelerators (e.g. macOS and iOS), the passed accelerator index will always be -1, and the accelerator markers will already be stripped.

Implementation

final MenuAcceleratorChildBuilder builder;