Skip to content

Commit 4053511

Browse files
[two_dimensional_scrollables] Refactor Radio widgets in example
Refactors the `two_dimensional_scrollables` example to use a new `RadioGroup` widget. This removes the deprecated `groupValue` and `onChanged` properties from each individual `Radio` button and moves them to the parent `RadioGroup`.
1 parent bb1f879 commit 4053511

File tree

2 files changed

+27
-45
lines changed

2 files changed

+27
-45
lines changed

packages/two_dimensional_scrollables/example/lib/table_view/table_explorer.dart

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,38 +56,25 @@ class _TableExplorerState extends State<TableExplorer> {
5656
child: Row(
5757
children: <Widget>[
5858
const Spacer(),
59-
Radio<TableType>(
60-
value: TableType.simple,
59+
RadioGroup<TableType>(
6160
groupValue: _currentExample,
6261
onChanged: (TableType? value) {
63-
setState(() {
64-
_currentExample = value!;
65-
});
62+
if (value == null) return;
63+
setState(() => _currentExample = value);
6664
},
65+
child: Row(
66+
children: <Widget>[
67+
Radio<TableType>(value: TableType.simple),
68+
const Text('Simple'),
69+
_spacer,
70+
Radio<TableType>(value: TableType.merged),
71+
const Text('Merged'),
72+
_spacer,
73+
Radio<TableType>(value: TableType.infinite),
74+
const Text('Infinite'),
75+
],
76+
),
6777
),
68-
const Text('Simple'),
69-
_spacer,
70-
Radio<TableType>(
71-
value: TableType.merged,
72-
groupValue: _currentExample,
73-
onChanged: (TableType? value) {
74-
setState(() {
75-
_currentExample = value!;
76-
});
77-
},
78-
),
79-
const Text('Merged'),
80-
_spacer,
81-
Radio<TableType>(
82-
value: TableType.infinite,
83-
groupValue: _currentExample,
84-
onChanged: (TableType? value) {
85-
setState(() {
86-
_currentExample = value!;
87-
});
88-
},
89-
),
90-
const Text('Infinite'),
9178
const Spacer(),
9279
],
9380
),

packages/two_dimensional_scrollables/example/lib/tree_view/tree_explorer.dart

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,22 @@ class _TreeExplorerState extends State<TreeExplorer> {
5050
child: Row(
5151
children: <Widget>[
5252
const Spacer(),
53-
Radio<TreeType>(
54-
value: TreeType.simple,
53+
RadioGroup<TreeType>(
5554
groupValue: _currentExample,
5655
onChanged: (TreeType? value) {
57-
setState(() {
58-
_currentExample = value!;
59-
});
56+
if (value == null) return;
57+
setState(() => _currentExample = value);
6058
},
59+
child: Row(
60+
children: <Widget>[
61+
Radio<TreeType>(value: TreeType.simple),
62+
const Text('Simple'),
63+
_spacer,
64+
Radio<TreeType>(value: TreeType.custom),
65+
const Text('Custom'),
66+
],
67+
),
6168
),
62-
const Text('Simple'),
63-
_spacer,
64-
Radio<TreeType>(
65-
value: TreeType.custom,
66-
groupValue: _currentExample,
67-
onChanged: (TreeType? value) {
68-
setState(() {
69-
_currentExample = value!;
70-
});
71-
},
72-
),
73-
const Text('Custom'),
7469
const Spacer(),
7570
],
7671
),

0 commit comments

Comments
 (0)