Component - Radio buttons
This UI component shows a group of radio buttons. Users can select only one option at a time. It is useful for choosing one item from a small list.
This UI component shows a group of radio buttons. Users can select only one option at a time. It is useful for choosing one item from a small list.
Scaffold
├─ AppBar
│ └─ Text
└─ Column
├─ ListTile
│ ├─ Radio
│ └─ Text
├─ ListTile
│ ├─ Radio
│ └─ Text
└─ ListTile
├─ Radio
└─ TextWhat is the main purpose of a Radio button in Flutter?
Which of the following is the correct way to declare a Radio button with value 1 and groupValue 2?
Radio( ... )What will be the selected radio button after this code runs?
int selected = 2;
Column(
children: [
Radio(value: 1, groupValue: selected, onChanged: (val) {}),
Radio(value: 2, groupValue: selected, onChanged: (val) {}),
Radio(value: 3, groupValue: selected, onChanged: (val) {}),
],
)Identify the error in this Flutter code snippet for radio buttons:
int selected = 1;
Radio(
value: 1,
groupValue: selected,
onChanged: null,
)You want to create a group of radio buttons for colors: Red, Green, Blue. The selected color should update the UI when tapped. Which code snippet correctly implements this behavior?
class ColorSelector extends StatefulWidget {
@override
State<ColorSelector> createState() => _ColorSelectorState();
}
class _ColorSelectorState extends State<ColorSelector> {
String selectedColor = 'Red';
@override
Widget build(BuildContext context) {
return Column(
children: [
Radio<String>(
value: 'Red',
groupValue: selectedColor,
onChanged: (val) {
setState(() {
selectedColor = val!;
});
},
),
Radio<String>(
value: 'Green',
groupValue: selectedColor,
onChanged: (val) {
setState(() {
selectedColor = val!;
});
},
),
Radio<String>(
value: 'Blue',
groupValue: selectedColor,
onChanged: (val) {
setState(() {
selectedColor = val!;
});
},
),
],
);
}
}Pass the test and this pattern moves unknown