Skip to content

Commit 90908b0

Browse files
Revert "Prevent material switch from recreating its render object when it becomes disabled (#61398)" (#64062)
1 parent eef4220 commit 90908b0

5 files changed

Lines changed: 22 additions & 145 deletions

File tree

packages/flutter/lib/src/widgets/actions.dart

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,30 +1092,25 @@ class _FocusableActionDetectorState extends State<FocusableActionDetector> {
10921092

10931093
@override
10941094
Widget build(BuildContext context) {
1095-
final Map<Type, Action<Intent>> actions = widget.enabled && widget.actions != null
1096-
? widget.actions
1097-
: const <Type, Action<Intent>>{};
1098-
final Map<LogicalKeySet, Intent> shortcuts = widget.enabled && widget.shortcuts != null
1099-
? widget.shortcuts
1100-
: const <LogicalKeySet, Intent>{};
1101-
1102-
return Actions(actions: actions,
1103-
child: Shortcuts(
1104-
shortcuts: shortcuts,
1105-
child: MouseRegion(
1106-
onEnter: _handleMouseEnter,
1107-
onExit: _handleMouseExit,
1108-
cursor: widget.mouseCursor,
1109-
child: Focus(
1110-
focusNode: widget.focusNode,
1111-
autofocus: widget.autofocus,
1112-
canRequestFocus: _canRequestFocus,
1113-
onFocusChange: _handleFocusChange,
1114-
child: widget.child,
1115-
),
1116-
),
1095+
Widget child = MouseRegion(
1096+
onEnter: _handleMouseEnter,
1097+
onExit: _handleMouseExit,
1098+
cursor: widget.mouseCursor,
1099+
child: Focus(
1100+
focusNode: widget.focusNode,
1101+
autofocus: widget.autofocus,
1102+
canRequestFocus: _canRequestFocus,
1103+
onFocusChange: _handleFocusChange,
1104+
child: widget.child,
11171105
),
11181106
);
1107+
if (widget.enabled && widget.actions != null && widget.actions.isNotEmpty) {
1108+
child = Actions(actions: widget.actions, child: child);
1109+
}
1110+
if (widget.enabled && widget.shortcuts != null && widget.shortcuts.isNotEmpty) {
1111+
child = Shortcuts(shortcuts: widget.shortcuts, child: child);
1112+
}
1113+
return child;
11191114
}
11201115
}
11211116

packages/flutter/test/material/checkbox_test.dart

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ void main() {
7070
),
7171
));
7272

73-
expect(tester.getSemantics(find.byType(Checkbox)), matchesSemantics(
73+
expect(tester.getSemantics(find.byType(Focus)), matchesSemantics(
7474
hasCheckedState: true,
7575
hasEnabledState: true,
7676
isEnabled: true,
@@ -85,7 +85,7 @@ void main() {
8585
),
8686
));
8787

88-
expect(tester.getSemantics(find.byType(Checkbox)), matchesSemantics(
88+
expect(tester.getSemantics(find.byType(Focus)), matchesSemantics(
8989
hasCheckedState: true,
9090
hasEnabledState: true,
9191
isChecked: true,
@@ -101,15 +101,6 @@ void main() {
101101
),
102102
));
103103

104-
expect(tester.getSemantics(find.byWidgetPredicate((Widget widget) => widget.runtimeType.toString() == '_CheckboxRenderObjectWidget')), matchesSemantics(
105-
hasCheckedState: true,
106-
hasEnabledState: true,
107-
// isFocusable is delayed by 1 frame.
108-
isFocusable: true,
109-
));
110-
111-
await tester.pump();
112-
// isFocusable should be false now after the 1 frame delay.
113104
expect(tester.getSemantics(find.byWidgetPredicate((Widget widget) => widget.runtimeType.toString() == '_CheckboxRenderObjectWidget')), matchesSemantics(
114105
hasCheckedState: true,
115106
hasEnabledState: true,

packages/flutter/test/material/radio_test.dart

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -237,24 +237,7 @@ void main() {
237237
expect(semantics, hasSemantics(TestSemantics.root(
238238
children: <TestSemantics>[
239239
TestSemantics.rootChild(
240-
id: 1,
241-
flags: <SemanticsFlag>[
242-
SemanticsFlag.hasCheckedState,
243-
SemanticsFlag.hasEnabledState,
244-
SemanticsFlag.isInMutuallyExclusiveGroup,
245-
SemanticsFlag.isFocusable, // This flag is delayed by 1 frame.
246-
],
247-
),
248-
],
249-
), ignoreRect: true, ignoreTransform: true));
250-
251-
await tester.pump();
252-
253-
// Now the isFocusable should be gone.
254-
expect(semantics, hasSemantics(TestSemantics.root(
255-
children: <TestSemantics>[
256-
TestSemantics.rootChild(
257-
id: 1,
240+
id: 2,
258241
flags: <SemanticsFlag>[
259242
SemanticsFlag.hasCheckedState,
260243
SemanticsFlag.hasEnabledState,
@@ -275,7 +258,7 @@ void main() {
275258
expect(semantics, hasSemantics(TestSemantics.root(
276259
children: <TestSemantics>[
277260
TestSemantics.rootChild(
278-
id: 1,
261+
id: 2,
279262
flags: <SemanticsFlag>[
280263
SemanticsFlag.hasCheckedState,
281264
SemanticsFlag.isChecked,

packages/flutter/test/material/slider_test.dart

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,51 +1402,7 @@ void main() {
14021402
children: <TestSemantics>[
14031403
TestSemantics(
14041404
id: 4,
1405-
flags: <SemanticsFlag>[
1406-
SemanticsFlag.hasEnabledState,
1407-
// isFocusable is delayed by 1 frame.
1408-
SemanticsFlag.isFocusable,
1409-
],
1410-
value: '50%',
1411-
increasedValue: '55%',
1412-
decreasedValue: '45%',
1413-
textDirection: TextDirection.ltr,
1414-
),
1415-
],
1416-
),
1417-
],
1418-
),
1419-
],
1420-
),
1421-
],
1422-
),
1423-
ignoreRect: true,
1424-
ignoreTransform: true,
1425-
),
1426-
);
1427-
1428-
await tester.pump();
1429-
expect(
1430-
semantics,
1431-
hasSemantics(
1432-
TestSemantics.root(
1433-
children: <TestSemantics>[
1434-
TestSemantics(
1435-
id: 1,
1436-
textDirection: TextDirection.ltr,
1437-
children: <TestSemantics>[
1438-
TestSemantics(
1439-
id: 2,
1440-
children: <TestSemantics>[
1441-
TestSemantics(
1442-
id: 3,
1443-
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
1444-
children: <TestSemantics>[
1445-
TestSemantics(
1446-
id: 4,
1447-
flags: <SemanticsFlag>[
1448-
SemanticsFlag.hasEnabledState,
1449-
],
1405+
flags: <SemanticsFlag>[SemanticsFlag.hasEnabledState],
14501406
value: '50%',
14511407
increasedValue: '55%',
14521408
decreasedValue: '45%',
@@ -1464,7 +1420,6 @@ void main() {
14641420
ignoreTransform: true,
14651421
),
14661422
);
1467-
14681423
semantics.dispose();
14691424
}, variant: const TargetPlatformVariant(<TargetPlatform>{ TargetPlatform.android, TargetPlatform.fuchsia, TargetPlatform.linux, TargetPlatform.windows }));
14701425

packages/flutter/test/material/switch_test.dart

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,51 +1015,4 @@ void main() {
10151015

10161016
await tester.pumpAndSettle();
10171017
});
1018-
1019-
testWidgets('Material switch should not recreate its render object when disabled', (WidgetTester tester) async {
1020-
// Regression test for https://github.com/flutter/flutter/issues/61247.
1021-
bool value = true;
1022-
bool enabled = true;
1023-
StateSetter stateSetter;
1024-
await tester.pumpWidget(
1025-
Directionality(
1026-
textDirection: TextDirection.ltr,
1027-
child: StatefulBuilder(
1028-
builder: (BuildContext context, StateSetter setState) {
1029-
stateSetter = setState;
1030-
return Material(
1031-
child: Center(
1032-
child: Switch(
1033-
value: value,
1034-
onChanged: !enabled ? null : (bool newValue) {
1035-
setState(() {
1036-
value = newValue;
1037-
});
1038-
},
1039-
),
1040-
),
1041-
);
1042-
},
1043-
),
1044-
),
1045-
);
1046-
1047-
final RenderToggleable oldSwitchRenderObject = tester
1048-
.renderObject(find.byWidgetPredicate((Widget widget) => widget is LeafRenderObjectWidget));
1049-
1050-
stateSetter(() { value = false; });
1051-
await tester.pump();
1052-
// Disable the switch when the implicit animation begins.
1053-
stateSetter(() { enabled = false; });
1054-
await tester.pump();
1055-
1056-
final RenderToggleable updatedSwitchRenderObject = tester
1057-
.renderObject(find.byWidgetPredicate((Widget widget) => widget is LeafRenderObjectWidget));
1058-
1059-
1060-
expect(updatedSwitchRenderObject.isInteractive, false);
1061-
expect(updatedSwitchRenderObject, oldSwitchRenderObject);
1062-
expect(updatedSwitchRenderObject.position.isCompleted, false);
1063-
expect(updatedSwitchRenderObject.position.isDismissed, false);
1064-
});
10651018
}

0 commit comments

Comments
 (0)