Skip to content
82 changes: 32 additions & 50 deletions packages/flutter/test/material/material_button_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';

import 'semantics_tester.dart';

void main() {
setUp(() {
debugResetSemanticsIdCounter();
Expand Down Expand Up @@ -637,15 +635,13 @@ void main() {
testWidgets(
'Disabled MaterialButton has same semantic size as enabled and exposes disabled semantics',
(WidgetTester tester) async {
final semantics = SemanticsTester(tester);

const expectedButtonSize = Rect.fromLTRB(0.0, 0.0, 116.0, 48.0);
// Button is in center of screen
final expectedButtonTransform = Matrix4.identity()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we keep the check for transform?

I think we can directly compare SemanticsNode.transform

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kept — expect(enabledSemantics.transform, expectedButtonTransform) and the same for disabledSemantics are now in the test (lines 678 and 708). The expectedButtonTransform constant is preserved.

..translate(
TestSemantics.fullScreen.width / 2 - expectedButtonSize.width / 2,
TestSemantics.fullScreen.height / 2 - expectedButtonSize.height / 2,
);
const expectedButtonSize = Size(116.0, 48.0);
// Button is in center of the 800x600 test screen.
final expectedButtonTransform = Matrix4.diagonal3Values(
tester.view.devicePixelRatio,
tester.view.devicePixelRatio,
1.0,
)..translate(400.0 - expectedButtonSize.width / 2, 300.0 - expectedButtonSize.height / 2);

// enabled button
await tester.pumpWidget(
Expand All @@ -665,28 +661,21 @@ void main() {
),
);

final SemanticsNode enabledSemantics = tester.getSemantics(find.byType(MaterialButton));
expect(
semantics,
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
rect: expectedButtonSize,
transform: expectedButtonTransform,
label: 'Button',
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
flags: <SemanticsFlag>[
SemanticsFlag.hasEnabledState,
SemanticsFlag.isButton,
SemanticsFlag.isEnabled,
SemanticsFlag.isFocusable,
],
),
],
),
enabledSemantics,
matchesSemantics(
label: 'Button',
hasTapAction: true,
hasFocusAction: true,
hasEnabledState: true,
isButton: true,
isEnabled: true,
isFocusable: true,
size: expectedButtonSize,
),
);
expect(enabledSemantics.transform, expectedButtonTransform);

// disabled button
await tester.pumpWidget(
Expand All @@ -704,29 +693,22 @@ void main() {
),
);

final SemanticsNode disabledSemantics = tester.getSemantics(find.byType(MaterialButton));
expect(
semantics,
hasSemantics(
TestSemantics.root(
children: <TestSemantics>[
TestSemantics.rootChild(
id: 1,
rect: expectedButtonSize,
transform: expectedButtonTransform,
label: 'Button',
flags: <SemanticsFlag>[
SemanticsFlag.hasEnabledState,
SemanticsFlag.isButton,
SemanticsFlag.isFocusable,
],
actions: <SemanticsAction>[SemanticsAction.focus],
),
],
),
disabledSemantics,
matchesSemantics(
label: 'Button',
hasFocusAction: true,
hasEnabledState: true,
isButton: true,
isFocusable: true,
size: expectedButtonSize,
),
Comment thread
chunhtai marked this conversation as resolved.
);

semantics.dispose();
expect(disabledSemantics.transform, expectedButtonTransform);
final SemanticsData semanticsData = disabledSemantics.getSemanticsData();
expect(semanticsData.hasFlag(SemanticsFlag.isEnabled), isFalse);
expect(semanticsData.hasAction(SemanticsAction.tap), isFalse);
},
);

Expand Down
Loading