Skip to content

Commit 90f8767

Browse files
committed
Fix bug in RadioGroup where reset and didChange doesnt affect UI. Fixes #646, Fixes 647
1 parent a5eea05 commit 90f8767

File tree

2 files changed

+7
-21
lines changed

2 files changed

+7
-21
lines changed

example/lib/sources/complete_form.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,11 @@ class CompleteFormState extends State<CompleteForm> {
463463
const SizedBox(width: 20),
464464
Expanded(
465465
child: OutlineButton(
466-
focusNode: FocusNode(),
467466
color: Theme.of(context).accentColor,
468-
child: const Text('Reset',
469-
style: TextStyle(color: Colors.white)),
467+
child: Text(
468+
'Reset',
469+
style: TextStyle(color: Theme.of(context).accentColor),
470+
),
470471
onPressed: () {
471472
_formKey.currentState.reset();
472473
},

lib/src/widgets/grouped_radio.dart

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,6 @@ class GroupedRadio<T> extends StatefulWidget {
198198
}
199199

200200
class _GroupedRadioState<T> extends State<GroupedRadio<T>> {
201-
T selectedValue;
202-
203-
@override
204-
void initState() {
205-
super.initState();
206-
207-
selectedValue = widget.value;
208-
}
209-
210201
@override
211202
Widget build(BuildContext context) {
212203
final widgetList = <Widget>[];
@@ -254,7 +245,7 @@ class _GroupedRadioState<T> extends State<GroupedRadio<T>> {
254245
final optionValue = option.value;
255246
final isOptionDisabled = true == widget.disabled?.contains(optionValue);
256247
final control = Radio<T>(
257-
groupValue: selectedValue,
248+
groupValue: widget.value,
258249
activeColor: widget.activeColor,
259250
focusColor: widget.focusColor,
260251
hoverColor: widget.hoverColor,
@@ -263,10 +254,7 @@ class _GroupedRadioState<T> extends State<GroupedRadio<T>> {
263254
onChanged: isOptionDisabled
264255
? null
265256
: (T selected) {
266-
setState(() {
267-
selectedValue = selected;
268-
});
269-
widget.onChanged(selectedValue);
257+
widget.onChanged(selected);
270258
},
271259
);
272260

@@ -275,10 +263,7 @@ class _GroupedRadioState<T> extends State<GroupedRadio<T>> {
275263
onTap: isOptionDisabled
276264
? null
277265
: () {
278-
setState(() {
279-
selectedValue = optionValue;
280-
});
281-
widget.onChanged(selectedValue);
266+
widget.onChanged(optionValue);
282267
},
283268
);
284269

0 commit comments

Comments
 (0)