Skip to content

Commit

Permalink
Add diagnosticable properties to togglable widgets (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jupi007 committed Feb 4, 2023
1 parent 958dc46 commit cc9097f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/src/controls/yaru_checkbox.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'yaru_check_button.dart';
Expand Down Expand Up @@ -125,6 +126,30 @@ class YaruCheckbox extends StatefulWidget implements YaruTogglable<bool?> {
@override
final bool autofocus;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
DiagnosticsProperty<bool?>(
'value',
checked,
description: checked == null
? 'mixed'
: checked == true
? 'checked'
: 'unchecked',
showName: false,
),
);
properties.add(
ObjectFlagProperty<ValueChanged<bool?>>(
'onChanged',
onChanged,
ifNull: 'disabled',
),
);
}

@override
YaruTogglableState<YaruCheckbox> createState() {
return _YaruCheckboxState();
Expand Down
21 changes: 21 additions & 0 deletions lib/src/controls/yaru_radio.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'yaru_checkbox.dart';
Expand Down Expand Up @@ -135,6 +136,26 @@ class YaruRadio<T> extends StatefulWidget implements YaruTogglable<T?> {
@override
final bool autofocus;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
FlagProperty(
'value',
value: checked,
ifTrue: 'selected',
ifFalse: 'unselected',
),
);
properties.add(
ObjectFlagProperty<ValueChanged<T?>>(
'onChanged',
onChanged,
ifNull: 'disabled',
),
);
}

@override
YaruTogglableState<YaruRadio<T?>> createState() {
return _YaruRadioState<T?>();
Expand Down
21 changes: 21 additions & 0 deletions lib/src/controls/yaru_switch.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'yaru_checkbox.dart';
Expand Down Expand Up @@ -101,6 +102,26 @@ class YaruSwitch extends StatefulWidget implements YaruTogglable<bool> {
@override
final bool autofocus;

@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
super.debugFillProperties(properties);
properties.add(
FlagProperty(
'value',
value: checked,
ifTrue: 'on',
ifFalse: 'off',
),
);
properties.add(
ObjectFlagProperty<ValueChanged<bool>>(
'onChanged',
onChanged,
ifNull: 'disabled',
),
);
}

@override
YaruTogglableState<YaruSwitch> createState() {
return _YaruSwitchState();
Expand Down

0 comments on commit cc9097f

Please sign in to comment.