RadioGroup<T> class
A widget that creates a set of radio buttons in a single, interconnected group.
Individual Radio Button
Each radio button is a Radio widget housed inside of a Row along with a either the value itself if it is a widget or a Text widget with the value as a string to label the button for the user to know what the button is representing.
One of these is created for every value that comes into this builder.
Vertical Layout
When the RadioGroupOrientation.vertical orientation is selected, this returns a Column which contains the Row widgets described in the "Individual Radio Button" section above.
This example shows the creation of a radio group that is aligned vertically.
RadioGroupController myController = RadioGroupController();
RadioGroup(
controller: myController,
values: ["Choice1", "Choice2", "Choice3"],
)
Horizontal Layout
When the RadioGroupOrientation.horizontal orientation is selected, this returns a Wrap which contains the Row widgets described in the "Individual Radio Button" section above.
This example shows the creation of a radio group that is aligned horizontally. It also has a real time updating method sent into it which will be called every time the buttons switch.
RadioGroupController myController = RadioGroupController();
RadioGroup(
controller: myController,
values: ["Choice1", "Choice2", "Choice3"],
onChanged: (value) {
liveChangeHere();
},
orientation: RadioListOrientation.Horizontal,
)
Retrieving Selected Value
This example shows what to do if you want to see which choice is selected from the two examples above.
print("The chosen value is: ${myController.value.toString()}");
See also:
- RadioGroupController which is used to know which button in the group is selected as well as programmatically select a button.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- RadioGroup
Constructors
-
RadioGroup({GlobalKey<
RadioGroupState< ? key, RadioGroupController<T> >T> ? controller, required List<T> values, Widget labelBuilder(T value)?, void onChanged(T? value)?, int indexOfDefault = -1, RadioGroupOrientation orientation = RadioGroupOrientation.vertical, RadioGroupDecoration? decoration}) - Creates a widget which contains Radio buttons that a user can click to make selections within the app.
Properties
-
controller
→ RadioGroupController<
T> ? -
This allows for setting and getting the value of
this
radio group.final - decoration → RadioGroupDecoration?
-
The style and design of the radio group.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- indexOfDefault → int
-
The index in the values list of the radio button which will start out
selected.
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- labelBuilder → Widget Function(T value)?
-
A builder function to create the label for each radio button.
final
- onChanged → void Function(T? value)?
-
A function that is called whenever the user clicks a different radio
button than the on that is currently selected.
final
- orientation → RadioGroupOrientation
-
How the radio button list will be laid out on the screen.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
values
→ List<
T> -
The labels for each of the buttons (in order of how they will be
displayed).
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< RadioGroup< T> > -
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