Unverified Commit 38df107b authored by Mahesh Jamdade's avatar Mahesh Jamdade Committed by GitHub

Add enabled property to CheckboxlistTile (#102314)

parent d31c250e
......@@ -127,6 +127,7 @@ class CheckboxListTile extends StatelessWidget {
required this.onChanged,
this.activeColor,
this.checkColor,
this.enabled,
this.tileColor,
this.title,
this.subtitle,
......@@ -295,6 +296,13 @@ class CheckboxListTile extends StatelessWidget {
/// * [Feedback] for providing platform-specific feedback to certain actions.
final bool? enableFeedback;
/// Whether the CheckboxListTile is interactive.
///
/// If false, this list tile is styled with the disabled color from the
/// current [Theme] and the [ListTile.onTap] callback is
/// inoperative.
final bool? enabled;
void _handleValueChange() {
assert(onChanged != null);
switch (value) {
......@@ -314,7 +322,7 @@ class CheckboxListTile extends StatelessWidget {
Widget build(BuildContext context) {
final Widget control = Checkbox(
value: value,
onChanged: onChanged,
onChanged: enabled ?? true ? onChanged : null ,
activeColor: activeColor,
checkColor: checkColor,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
......@@ -345,7 +353,7 @@ class CheckboxListTile extends StatelessWidget {
trailing: trailing,
isThreeLine: isThreeLine,
dense: dense,
enabled: onChanged != null,
enabled: enabled ?? onChanged != null,
onTap: onChanged != null ? _handleValueChange : null,
selected: selected,
autofocus: autofocus,
......
......@@ -421,6 +421,47 @@ void main() {
expect(tileNode.hasPrimaryFocus, isTrue);
});
testWidgets('CheckboxListTile can be disabled', (WidgetTester tester) async {
bool? value = false;
bool enabled = true;
await tester.pumpWidget(
Material(
child: StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return wrap(
child: CheckboxListTile(
title: const Text('Title'),
enabled: enabled,
value: value,
onChanged: (bool? v) {
setState(() {
value = v;
enabled = !enabled;
});
},
),
);
},
),
),
);
final Finder checkbox = find.byType(Checkbox);
// verify initial values
expect(tester.widget<Checkbox>(checkbox).value, false);
expect(enabled, true);
// Tap the checkbox to disable CheckboxListTile
await tester.tap(checkbox);
await tester.pumpAndSettle();
expect(tester.widget<Checkbox>(checkbox).value, true);
expect(enabled, false);
await tester.tap(checkbox);
await tester.pumpAndSettle();
expect(tester.widget<Checkbox>(checkbox).value, true);
});
group('feedback', () {
late FeedbackTester feedback;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment