From 2b05e1696437546d27d8c2ed3ad4fa665bbfe6c8 Mon Sep 17 00:00:00 2001 From: AbdeMohlbi Date: Tue, 16 Sep 2025 10:26:17 +0100 Subject: [PATCH 1/2] refactor code to use RadioGroup instead of groupValue/onChanged in Radio --- .../diagrams/lib/src/radio_list_tile.dart | 178 +++++++----------- 1 file changed, 69 insertions(+), 109 deletions(-) diff --git a/packages/diagrams/lib/src/radio_list_tile.dart b/packages/diagrams/lib/src/radio_list_tile.dart index e1ea2426..6341626c 100644 --- a/packages/diagrams/lib/src/radio_list_tile.dart +++ b/packages/diagrams/lib/src/radio_list_tile.dart @@ -15,17 +15,13 @@ class LinkedLabelRadio extends StatelessWidget { const LinkedLabelRadio({ required this.label, required this.padding, - required this.groupValue, required this.value, - required this.onChanged, super.key, }); final String label; final EdgeInsets padding; - final bool groupValue; final bool value; - final ValueChanged onChanged; @override Widget build(BuildContext context) { @@ -33,13 +29,7 @@ class LinkedLabelRadio extends StatelessWidget { padding: padding, child: Row( children: [ - Radio( - groupValue: groupValue, - value: value, - onChanged: (bool? newValue) { - onChanged(newValue); - }, - ), + Radio(value: value), RichText( text: TextSpan( text: label, @@ -47,10 +37,11 @@ class LinkedLabelRadio extends StatelessWidget { color: Colors.blueAccent, decoration: TextDecoration.underline, ), - recognizer: TapGestureRecognizer() - ..onTap = () { - print('Label has been tapped.'); - }, + recognizer: + TapGestureRecognizer() + ..onTap = () { + print('Label has been tapped.'); + }, ), ), ], @@ -63,40 +54,21 @@ class LabeledRadio extends StatelessWidget { const LabeledRadio({ required this.label, required this.padding, - required this.groupValue, required this.value, - required this.onChanged, super.key, }); final String label; final EdgeInsets padding; - final bool groupValue; final bool value; - final ValueChanged onChanged; @override Widget build(BuildContext context) { return InkWell( - onTap: () { - if (value != groupValue) { - onChanged(value); - } - }, + onTap: () {}, child: Padding( padding: padding, - child: Row( - children: [ - Radio( - groupValue: groupValue, - value: value, - onChanged: (bool? newValue) { - onChanged(newValue); - }, - ), - Text(label), - ], - ), + child: Row(children: [Radio(value: value), Text(label)]), ), ); } @@ -127,29 +99,25 @@ class _RadioListTileDiagramState extends State { alignment: FractionalOffset.center, padding: const EdgeInsets.all(5.0), color: Colors.white, - child: Column( - children: [ - RadioListTile( - title: const Text('Lafayette'), - value: SingingCharacter.lafayette, - groupValue: _character, - onChanged: (SingingCharacter? value) { - setState(() { - _character = value; - }); - }, - ), - RadioListTile( - title: const Text('Thomas Jefferson'), - value: SingingCharacter.jefferson, - groupValue: _character, - onChanged: (SingingCharacter? value) { - setState(() { - _character = value; - }); - }, - ), - ], + child: RadioGroup( + groupValue: _character, + onChanged: (SingingCharacter? value) { + setState(() { + _character = value; + }); + }, + child: const Column( + children: [ + RadioListTile( + title: Text('Lafayette'), + value: SingingCharacter.lafayette, + ), + RadioListTile( + title: Text('Thomas Jefferson'), + value: SingingCharacter.jefferson, + ), + ], + ), ), ), ); @@ -161,31 +129,27 @@ class _RadioListTileDiagramState extends State { alignment: FractionalOffset.center, padding: const EdgeInsets.all(5.0), color: Colors.white, - child: Column( - children: [ - LinkedLabelRadio( - label: 'First tappable label text', - padding: const EdgeInsets.symmetric(horizontal: 5.0), - value: true, - groupValue: _isRadioSelected, - onChanged: (bool? newValue) { - setState(() { - _isRadioSelected = newValue!; - }); - }, - ), - LinkedLabelRadio( - label: 'Second tappable label text', - padding: const EdgeInsets.symmetric(horizontal: 5.0), - value: false, - groupValue: _isRadioSelected, - onChanged: (bool? newValue) { - setState(() { - _isRadioSelected = newValue!; - }); - }, - ), - ], + child: RadioGroup( + groupValue: _isRadioSelected, + onChanged: (bool? newValue) { + setState(() { + _isRadioSelected = newValue!; + }); + }, + child: const Column( + children: [ + LinkedLabelRadio( + label: 'First tappable label text', + padding: EdgeInsets.symmetric(horizontal: 5.0), + value: true, + ), + LinkedLabelRadio( + label: 'Second tappable label text', + padding: EdgeInsets.symmetric(horizontal: 5.0), + value: false, + ), + ], + ), ), ), ); @@ -197,31 +161,27 @@ class _RadioListTileDiagramState extends State { alignment: FractionalOffset.center, padding: const EdgeInsets.all(5.0), color: Colors.white, - child: Column( - children: [ - LabeledRadio( - label: 'This is the first label text', - padding: const EdgeInsets.symmetric(horizontal: 5.0), - value: true, - groupValue: _isRadioSelected, - onChanged: (bool? newValue) { - setState(() { - _isRadioSelected = newValue!; - }); - }, - ), - LabeledRadio( - label: 'This is the second label text', - padding: const EdgeInsets.symmetric(horizontal: 5.0), - value: false, - groupValue: _isRadioSelected, - onChanged: (bool? newValue) { - setState(() { - _isRadioSelected = newValue!; - }); - }, - ), - ], + child: RadioGroup( + groupValue: _isRadioSelected, + onChanged: (bool? newValue) { + setState(() { + _isRadioSelected = newValue!; + }); + }, + child: const Column( + children: [ + LabeledRadio( + label: 'This is the first label text', + padding: EdgeInsets.symmetric(horizontal: 5.0), + value: true, + ), + LabeledRadio( + label: 'This is the second label text', + padding: EdgeInsets.symmetric(horizontal: 5.0), + value: false, + ), + ], + ), ), ), ); From 144bfd1a2ca44b530b6fd4a92e223256fc3abccb Mon Sep 17 00:00:00 2001 From: Mohellebi abdessalem Date: Thu, 18 Sep 2025 18:08:40 +0100 Subject: [PATCH 2/2] formating --- packages/diagrams/lib/src/radio_list_tile.dart | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/packages/diagrams/lib/src/radio_list_tile.dart b/packages/diagrams/lib/src/radio_list_tile.dart index 6341626c..70ba1cf1 100644 --- a/packages/diagrams/lib/src/radio_list_tile.dart +++ b/packages/diagrams/lib/src/radio_list_tile.dart @@ -37,11 +37,10 @@ class LinkedLabelRadio extends StatelessWidget { color: Colors.blueAccent, decoration: TextDecoration.underline, ), - recognizer: - TapGestureRecognizer() - ..onTap = () { - print('Label has been tapped.'); - }, + recognizer: TapGestureRecognizer() + ..onTap = () { + print('Label has been tapped.'); + }, ), ), ], @@ -68,7 +67,12 @@ class LabeledRadio extends StatelessWidget { onTap: () {}, child: Padding( padding: padding, - child: Row(children: [Radio(value: value), Text(label)]), + child: Row( + children: [ + Radio(value: value), + Text(label), + ], + ), ), ); }