Skip to content

Commit 764705e

Browse files
authored
Remove last material dependency from cupertino tests (#184781)
This removes the last material dependency from the cupertino test library. It refactors tests that were relying on SelectableText. **Code freeze override: this is necessary to complete decoupling, and will not cause cupertino_ui to be incompatible with the upcoming stable release.** ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance. **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. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [AI contribution guidelines]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#ai-contribution-guidelines [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 688b19d commit 764705e

1 file changed

Lines changed: 131 additions & 57 deletions

File tree

packages/flutter/test/cupertino/text_selection_test.dart

Lines changed: 131 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import 'dart:ui' as ui show BoxHeightStyle;
1111

1212
import 'package:flutter/cupertino.dart';
1313
import 'package:flutter/foundation.dart';
14-
import 'package:flutter/material.dart';
1514
import 'package:flutter/rendering.dart';
1615
import 'package:flutter/services.dart';
1716
import 'package:flutter_test/flutter_test.dart';
@@ -58,6 +57,21 @@ class _LongCupertinoLocalizations extends DefaultCupertinoLocalizations {
5857

5958
const _LongCupertinoLocalizations _longLocalizations = _LongCupertinoLocalizations();
6059

60+
class _RichTextController extends TextEditingController {
61+
_RichTextController({required this.textSpan}) : super(text: textSpan.toPlainText());
62+
63+
final TextSpan textSpan;
64+
65+
@override
66+
TextSpan buildTextSpan({
67+
required BuildContext context,
68+
TextStyle? style,
69+
required bool withComposing,
70+
}) {
71+
return textSpan;
72+
}
73+
}
74+
6175
void main() {
6276
TestWidgetsFlutterBinding.ensureInitialized();
6377
final mockClipboard = MockClipboard();
@@ -728,26 +742,38 @@ void main() {
728742
testWidgets(
729743
'iOS selection handles scale with rich text (selection height style tight)',
730744
(WidgetTester tester) async {
745+
final focusNode = FocusNode();
746+
addTearDown(focusNode.dispose);
747+
final controller = _RichTextController(
748+
textSpan: const TextSpan(
749+
children: <InlineSpan>[
750+
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
751+
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
752+
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
753+
],
754+
),
755+
);
756+
addTearDown(controller.dispose);
757+
731758
await tester.pumpWidget(
732-
const CupertinoApp(
759+
CupertinoApp(
733760
home: Center(
734-
child: SelectableText.rich(
735-
TextSpan(
736-
children: <InlineSpan>[
737-
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
738-
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
739-
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
740-
],
741-
),
761+
child: CupertinoTextField(
762+
controller: controller,
763+
focusNode: focusNode,
764+
style: const TextStyle(fontSize: 100.0),
765+
cursorColor: const Color.fromARGB(0, 0, 0, 0),
742766
selectionHeightStyle: ui.BoxHeightStyle.tight,
767+
selectionControls: cupertinoTextSelectionControls,
768+
readOnly: true,
769+
decoration: null,
770+
padding: EdgeInsets.zero,
743771
),
744772
),
745773
),
746774
);
747775

748-
final EditableText editableTextWidget = tester.widget(find.byType(EditableText));
749776
final EditableTextState editableTextState = tester.state(find.byType(EditableText));
750-
final TextEditingController controller = editableTextWidget.controller;
751777

752778
// Double tap to select the second word.
753779
const index = 4;
@@ -810,25 +836,37 @@ void main() {
810836
testWidgets(
811837
'iOS selection handles scale with rich text (selection height style includeLineSpacingMiddle) (default)',
812838
(WidgetTester tester) async {
839+
final focusNode = FocusNode();
840+
addTearDown(focusNode.dispose);
841+
final controller = _RichTextController(
842+
textSpan: const TextSpan(
843+
children: <InlineSpan>[
844+
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
845+
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
846+
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
847+
],
848+
),
849+
);
850+
addTearDown(controller.dispose);
851+
813852
await tester.pumpWidget(
814-
const CupertinoApp(
853+
CupertinoApp(
815854
home: Center(
816-
child: SelectableText.rich(
817-
TextSpan(
818-
children: <InlineSpan>[
819-
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
820-
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
821-
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
822-
],
823-
),
855+
child: CupertinoTextField(
856+
controller: controller,
857+
focusNode: focusNode,
858+
style: const TextStyle(fontSize: 100.0),
859+
cursorColor: const Color.fromARGB(0, 0, 0, 0),
860+
selectionControls: cupertinoTextSelectionControls,
861+
readOnly: true,
862+
decoration: null,
863+
padding: EdgeInsets.zero,
824864
),
825865
),
826866
),
827867
);
828868

829-
final EditableText editableTextWidget = tester.widget(find.byType(EditableText));
830869
final EditableTextState editableTextState = tester.state(find.byType(EditableText));
831-
final TextEditingController controller = editableTextWidget.controller;
832870

833871
// Double tap to select the second word.
834872
const index = 4;
@@ -894,27 +932,39 @@ void main() {
894932
testWidgets(
895933
'iOS selection handles scale with rich text (grapheme clusters) (selection height style tight)',
896934
(WidgetTester tester) async {
935+
final focusNode = FocusNode();
936+
addTearDown(focusNode.dispose);
937+
final controller = _RichTextController(
938+
textSpan: const TextSpan(
939+
children: <InlineSpan>[
940+
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
941+
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
942+
TextSpan(text: '👨‍👩‍👦 ', style: TextStyle(fontSize: 35.0)),
943+
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
944+
],
945+
),
946+
);
947+
addTearDown(controller.dispose);
948+
897949
await tester.pumpWidget(
898-
const CupertinoApp(
950+
CupertinoApp(
899951
home: Center(
900-
child: SelectableText.rich(
901-
TextSpan(
902-
children: <InlineSpan>[
903-
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
904-
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
905-
TextSpan(text: '👨‍👩‍👦 ', style: TextStyle(fontSize: 35.0)),
906-
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
907-
],
908-
),
952+
child: CupertinoTextField(
953+
controller: controller,
954+
focusNode: focusNode,
955+
style: const TextStyle(fontSize: 100.0),
956+
cursorColor: const Color.fromARGB(0, 0, 0, 0),
909957
selectionHeightStyle: ui.BoxHeightStyle.tight,
958+
selectionControls: cupertinoTextSelectionControls,
959+
readOnly: true,
960+
decoration: null,
961+
padding: EdgeInsets.zero,
910962
),
911963
),
912964
),
913965
);
914966

915-
final EditableText editableTextWidget = tester.widget(find.byType(EditableText));
916967
final EditableTextState editableTextState = tester.state(find.byType(EditableText));
917-
final TextEditingController controller = editableTextWidget.controller;
918968

919969
// Double tap to select the second word.
920970
const index = 4;
@@ -977,26 +1027,38 @@ void main() {
9771027
testWidgets(
9781028
'iOS selection handles scale with rich text (grapheme clusters) (selection height style includeLineSpacingMiddle) (default)',
9791029
(WidgetTester tester) async {
1030+
final focusNode = FocusNode();
1031+
addTearDown(focusNode.dispose);
1032+
final controller = _RichTextController(
1033+
textSpan: const TextSpan(
1034+
children: <InlineSpan>[
1035+
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
1036+
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
1037+
TextSpan(text: '👨‍👩‍👦 ', style: TextStyle(fontSize: 35.0)),
1038+
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
1039+
],
1040+
),
1041+
);
1042+
addTearDown(controller.dispose);
1043+
9801044
await tester.pumpWidget(
981-
const CupertinoApp(
1045+
CupertinoApp(
9821046
home: Center(
983-
child: SelectableText.rich(
984-
TextSpan(
985-
children: <InlineSpan>[
986-
TextSpan(text: 'abc ', style: TextStyle(fontSize: 100.0)),
987-
TextSpan(text: 'def ', style: TextStyle(fontSize: 50.0)),
988-
TextSpan(text: '👨‍👩‍👦 ', style: TextStyle(fontSize: 35.0)),
989-
TextSpan(text: 'hij', style: TextStyle(fontSize: 25.0)),
990-
],
991-
),
1047+
child: CupertinoTextField(
1048+
controller: controller,
1049+
focusNode: focusNode,
1050+
style: const TextStyle(fontSize: 100.0),
1051+
cursorColor: const Color.fromARGB(0, 0, 0, 0),
1052+
selectionControls: cupertinoTextSelectionControls,
1053+
readOnly: true,
1054+
decoration: null,
1055+
padding: EdgeInsets.zero,
9921056
),
9931057
),
9941058
),
9951059
);
9961060

997-
final EditableText editableTextWidget = tester.widget(find.byType(EditableText));
9981061
final EditableTextState editableTextState = tester.state(find.byType(EditableText));
999-
final TextEditingController controller = editableTextWidget.controller;
10001062

10011063
// Double tap to select the second word.
10021064
const index = 4;
@@ -1059,25 +1121,37 @@ void main() {
10591121
testWidgets(
10601122
'iOS selection handles scaling falls back to preferredLineHeight when the current frame does not match the previous with a tight selection height style',
10611123
(WidgetTester tester) async {
1124+
final focusNode = FocusNode();
1125+
addTearDown(focusNode.dispose);
1126+
final controller = _RichTextController(
1127+
textSpan: const TextSpan(
1128+
children: <InlineSpan>[
1129+
TextSpan(text: 'abc', style: TextStyle(fontSize: 40.0)),
1130+
TextSpan(text: 'def', style: TextStyle(fontSize: 50.0)),
1131+
],
1132+
),
1133+
);
1134+
addTearDown(controller.dispose);
1135+
10621136
await tester.pumpWidget(
1063-
const CupertinoApp(
1137+
CupertinoApp(
10641138
home: Center(
1065-
child: SelectableText.rich(
1066-
TextSpan(
1067-
children: <InlineSpan>[
1068-
TextSpan(text: 'abc', style: TextStyle(fontSize: 40.0)),
1069-
TextSpan(text: 'def', style: TextStyle(fontSize: 50.0)),
1070-
],
1071-
),
1139+
child: CupertinoTextField(
1140+
controller: controller,
1141+
focusNode: focusNode,
1142+
style: const TextStyle(fontSize: 50.0),
1143+
cursorColor: const Color.fromARGB(0, 0, 0, 0),
10721144
selectionHeightStyle: ui.BoxHeightStyle.tight,
1145+
selectionControls: cupertinoTextSelectionControls,
1146+
readOnly: true,
1147+
decoration: null,
1148+
padding: EdgeInsets.zero,
10731149
),
10741150
),
10751151
),
10761152
);
10771153

1078-
final EditableText editableTextWidget = tester.widget(find.byType(EditableText));
10791154
final EditableTextState editableTextState = tester.state(find.byType(EditableText));
1080-
final TextEditingController controller = editableTextWidget.controller;
10811155

10821156
// Double tap to select the second word.
10831157
const index = 4;

0 commit comments

Comments
 (0)