Skip to content

Commit b6420a7

Browse files
authored
[material_ui] Port PR (#184807) from flutter/flutter to material_ui (#11972)
Most Material and Cupertino code was copied over from flutter/flutter in #11888, but a few PRs landed after that copy. This PR copies one of those PRs to this repo. Ports over flutter/flutter#184807. Work towards flutter/flutter#188441 ## Pre-Review Checklist **Test exemption: cherry-pick of PR from flutter/flutter** **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 87d3770 commit b6420a7

1 file changed

Lines changed: 32 additions & 50 deletions

File tree

packages/material_ui/test/material_button_test.dart

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import 'package:flutter/rendering.dart';
88
import 'package:flutter_test/flutter_test.dart';
99
import 'package:material_ui/material_ui.dart';
1010

11-
import 'semantics_tester.dart';
12-
1311
void main() {
1412
setUp(() {
1513
debugResetSemanticsIdCounter();
@@ -637,15 +635,13 @@ void main() {
637635
testWidgets(
638636
'Disabled MaterialButton has same semantic size as enabled and exposes disabled semantics',
639637
(WidgetTester tester) async {
640-
final semantics = SemanticsTester(tester);
641-
642-
const expectedButtonSize = Rect.fromLTRB(0.0, 0.0, 116.0, 48.0);
643-
// Button is in center of screen
644-
final expectedButtonTransform = Matrix4.identity()
645-
..translate(
646-
TestSemantics.fullScreen.width / 2 - expectedButtonSize.width / 2,
647-
TestSemantics.fullScreen.height / 2 - expectedButtonSize.height / 2,
648-
);
638+
const expectedButtonSize = Size(116.0, 48.0);
639+
// Button is in center of the 800x600 test screen.
640+
final expectedButtonTransform = Matrix4.diagonal3Values(
641+
tester.view.devicePixelRatio,
642+
tester.view.devicePixelRatio,
643+
1.0,
644+
)..translate(400.0 - expectedButtonSize.width / 2, 300.0 - expectedButtonSize.height / 2);
649645

650646
// enabled button
651647
await tester.pumpWidget(
@@ -665,28 +661,21 @@ void main() {
665661
),
666662
);
667663

664+
final SemanticsNode enabledSemantics = tester.getSemantics(find.byType(MaterialButton));
668665
expect(
669-
semantics,
670-
hasSemantics(
671-
TestSemantics.root(
672-
children: <TestSemantics>[
673-
TestSemantics.rootChild(
674-
id: 1,
675-
rect: expectedButtonSize,
676-
transform: expectedButtonTransform,
677-
label: 'Button',
678-
actions: <SemanticsAction>[SemanticsAction.tap, SemanticsAction.focus],
679-
flags: <SemanticsFlag>[
680-
SemanticsFlag.hasEnabledState,
681-
SemanticsFlag.isButton,
682-
SemanticsFlag.isEnabled,
683-
SemanticsFlag.isFocusable,
684-
],
685-
),
686-
],
687-
),
666+
enabledSemantics,
667+
matchesSemantics(
668+
label: 'Button',
669+
hasTapAction: true,
670+
hasFocusAction: true,
671+
hasEnabledState: true,
672+
isButton: true,
673+
isEnabled: true,
674+
isFocusable: true,
675+
size: expectedButtonSize,
688676
),
689677
);
678+
expect(enabledSemantics.transform, expectedButtonTransform);
690679

691680
// disabled button
692681
await tester.pumpWidget(
@@ -704,29 +693,22 @@ void main() {
704693
),
705694
);
706695

696+
final SemanticsNode disabledSemantics = tester.getSemantics(find.byType(MaterialButton));
707697
expect(
708-
semantics,
709-
hasSemantics(
710-
TestSemantics.root(
711-
children: <TestSemantics>[
712-
TestSemantics.rootChild(
713-
id: 1,
714-
rect: expectedButtonSize,
715-
transform: expectedButtonTransform,
716-
label: 'Button',
717-
flags: <SemanticsFlag>[
718-
SemanticsFlag.hasEnabledState,
719-
SemanticsFlag.isButton,
720-
SemanticsFlag.isFocusable,
721-
],
722-
actions: <SemanticsAction>[SemanticsAction.focus],
723-
),
724-
],
725-
),
698+
disabledSemantics,
699+
matchesSemantics(
700+
label: 'Button',
701+
hasFocusAction: true,
702+
hasEnabledState: true,
703+
isButton: true,
704+
isFocusable: true,
705+
size: expectedButtonSize,
726706
),
727707
);
728-
729-
semantics.dispose();
708+
expect(disabledSemantics.transform, expectedButtonTransform);
709+
final SemanticsData semanticsData = disabledSemantics.getSemanticsData();
710+
expect(semanticsData.hasFlag(SemanticsFlag.isEnabled), isFalse);
711+
expect(semanticsData.hasAction(SemanticsAction.tap), isFalse);
730712
},
731713
);
732714

0 commit comments

Comments
 (0)