update Tristate checkbox semantics to consider indeterminate as "unchecked" (#18297)

This commit is contained in:
Jonah Williams
2018-06-15 12:53:45 -07:00
committed by GitHub
parent bcaf026c08
commit 29e0e8b22f
2 changed files with 64 additions and 1 deletions

View File

@@ -339,7 +339,7 @@ abstract class RenderToggleable extends RenderConstrainedBox {
config.isEnabled = isInteractive;
if (isInteractive)
config.onTap = _handleTap;
config.isChecked = _value != false;
config.isChecked = _value == true;
}
@override

View File

@@ -202,6 +202,69 @@ void main() {
expect(checkBoxValue, null);
});
testWidgets('has semantics for tristate', (WidgetTester tester) async {
final SemanticsTester semantics = new SemanticsTester(tester);
await tester.pumpWidget(
new Material(
child: new Checkbox(
tristate: true,
value: null,
onChanged: (bool newValue) {},
),
),
);
expect(semantics.nodesWith(
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled
],
actions: <SemanticsAction>[SemanticsAction.tap],
), hasLength(1));
await tester.pumpWidget(
new Material(
child: new Checkbox(
tristate: true,
value: true,
onChanged: (bool newValue) {},
),
),
);
expect(semantics.nodesWith(
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
SemanticsFlag.isChecked,
],
actions: <SemanticsAction>[SemanticsAction.tap],
), hasLength(1));
await tester.pumpWidget(
new Material(
child: new Checkbox(
tristate: true,
value: false,
onChanged: (bool newValue) {},
),
),
);
expect(semantics.nodesWith(
flags: <SemanticsFlag>[
SemanticsFlag.hasCheckedState,
SemanticsFlag.hasEnabledState,
SemanticsFlag.isEnabled,
],
actions: <SemanticsAction>[SemanticsAction.tap],
), hasLength(1));
semantics.dispose();
});
testWidgets('has semantic events', (WidgetTester tester) async {
dynamic semanticEvent;
bool checkboxValue = false;