RadioGroup<T> class

A group for radios.

This widget treats all radios, such as RawRadio, Radio, CupertinoRadio in the sub tree with the same type T as a group. Radios with different types are not included in the group.

This widget handles the group value for the radios in the subtree with the same value type.

Using this widget also provides keyboard navigation and semantics for the radio buttons that matches APG.

The keyboard behaviors are:

  • Tab and Shift+Tab: moves focus into and out of radio group. When focus moves into a radio group and a radio button is select, focus is set on selected button. Otherwise, it focus the first radio button in reading order.
  • Space: toggle the selection on the focused radio button.
  • Right and down arrow key: move selection to next radio button in the group in reading order.
  • Left and up arrow key: move selection to previous radio button in the group in reading order.

Arrow keys will wrap around if it reach the first or last radio in the group.

Here is an example of RadioGroup widget.

Try using tab, arrow keys, and space to see how the widget responds.

link

To create a local project with this code sample, run:
flutter create --sample=widgets.RadioGroup.1 mysample

Inheritance

Constructors

RadioGroup.new({Key? key, T? groupValue, required ValueChanged<T?> onChanged, required Widget child})
Creates a radio group.
const

Properties

child Widget
This widget can only have one child. To lay out multiple children, let this widget's child be a widget such as Row, Column, or Stack, which have a children property, and then provide the children to that widget.
final
groupValue → T?
The selected value under this radio group.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
onChanged ValueChanged<T?>
Called when selection has changed.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<StatefulWidget>
Creates the mutable state for this widget at a given location in the tree.
override
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

Static Methods

maybeOf<T>(BuildContext context) RadioGroupRegistry<T>?
Gets the RadioGroupRegistry from the above the context.