Repository: ubuntu/yaru.dart

Issue:
YaruRadioButton doesn't support togglable
If you set `YaruRadioButton` as togglable, this behaviour will be only available the radio widget itself. If you click on the label, the value will not be set to null.



Fix patch:
diff --git a/lib/src/controls/yaru_radio_button.dart b/lib/src/controls/yaru_radio_button.dart
index 30d7a602f..2707f48ab 100644
--- a/lib/src/controls/yaru_radio_button.dart
+++ b/lib/src/controls/yaru_radio_button.dart
@@ -65,7 +65,15 @@ class YaruRadioButton<T> extends StatelessWidget {
           ),
         ),
       ),
-      onToggled: onChanged != null ? () => onChanged!(value) : null,
+      onToggled: onChanged == null ? null : _onToggled,
     );
   }
+
+  void _onToggled() {
+    if (groupValue != value || !toggleable) {
+      onChanged!(value);
+    } else if (toggleable) {
+      onChanged!(null);
+    }
+  }
 }


Test patch:
diff --git a/test/controls/yaru_radio_button_test.dart b/test/controls/yaru_radio_button_test.dart
index b2b2ea812..2ee59d3b0 100644
--- a/test/controls/yaru_radio_button_test.dart
+++ b/test/controls/yaru_radio_button_test.dart
@@ -38,7 +38,11 @@ void main() {
 
   testWidgets('the labels react to taps', (tester) async {
     int? changedValue;
-    Widget builder({required int value, required int groupValue}) {
+    Widget builder({
+      required int value,
+      required int groupValue,
+      required bool toggleable,
+    }) {
       return MaterialApp(
         home: Scaffold(
           body: YaruRadioButton<int>(
@@ -46,17 +50,28 @@ void main() {
             subtitle: const Text('subtitle'),
             value: value,
             groupValue: groupValue,
+            toggleable: toggleable,
             onChanged: (v) => changedValue = v,
           ),
         ),
       );
     }
 
-    await tester.pumpWidget(builder(value: 1, groupValue: 1));
+    await tester
+        .pumpWidget(builder(value: 1, groupValue: 1, toggleable: false));
     await tester.tap(find.text('title'));
     expect(changedValue, equals(1));
 
-    await tester.pumpWidget(builder(value: 2, groupValue: 3));
+    await tester
+        .pumpWidget(builder(value: 2, groupValue: 3, toggleable: false));
+    await tester.tap(find.text('subtitle'));
+    expect(changedValue, equals(2));
+
+    await tester.pumpWidget(builder(value: 1, groupValue: 1, toggleable: true));
+    await tester.tap(find.text('title'));
+    expect(changedValue, equals(null));
+
+    await tester.pumpWidget(builder(value: 2, groupValue: 3, toggleable: true));
     await tester.tap(find.text('subtitle'));
     expect(changedValue, equals(2));
   });