@@ -91,6 +91,43 @@ void main() {
91
91
expect (tester.getBottomLeft (find.byType (CupertinoSearchTextField )).dy, 87.0 );
92
92
});
93
93
94
+ testWidgets ('Opens the search view when the search field is tapped' , (WidgetTester tester) async {
95
+ await tester.pumpWidget (const example.SliverNavBarApp ());
96
+
97
+ // Navigate to a page with a search field.
98
+ final Finder nextButton = find.text ('Bottom Automatic mode' );
99
+ expect (nextButton, findsOneWidget);
100
+ await tester.tap (nextButton);
101
+ await tester.pumpAndSettle ();
102
+
103
+ expect (find.widgetWithText (CupertinoSearchTextField , 'Search' ), findsOneWidget);
104
+ expect (find.text ('Tap on the search field to open the search view' ), findsOneWidget);
105
+ // A decoy 'Cancel' button used in the animation.
106
+ expect (find.widgetWithText (CupertinoButton , 'Cancel' ), findsOneWidget);
107
+
108
+ // Tap on the search field to open the search view.
109
+ await tester.tap (find.byType (CupertinoSearchTextField ), warnIfMissed: false );
110
+ await tester.pumpAndSettle ();
111
+
112
+ expect (find.widgetWithText (CupertinoSearchTextField , 'Enter search text' ), findsOneWidget);
113
+ expect (find.text ('Tap on the search field to open the search view' ), findsNothing);
114
+ expect (find.widgetWithText (CupertinoButton , 'Cancel' ), findsOneWidget);
115
+
116
+ await tester.enterText (find.byType (CupertinoSearchTextField ), 'a' );
117
+ await tester.pumpAndSettle ();
118
+
119
+ expect (find.text ('The text has changed to: a' ), findsOneWidget);
120
+
121
+ // Tap on the 'Cancel' button to close the search view.
122
+ await tester.tap (find.widgetWithText (CupertinoButton , 'Cancel' ));
123
+ await tester.pumpAndSettle ();
124
+
125
+ expect (find.widgetWithText (CupertinoSearchTextField , 'Search' ), findsOneWidget);
126
+ expect (find.text ('Tap on the search field to open the search view' ), findsOneWidget);
127
+ // A decoy 'Cancel' button used in the animation.
128
+ expect (find.widgetWithText (CupertinoButton , 'Cancel' ), findsOneWidget);
129
+ });
130
+
94
131
testWidgets ('CupertinoSliverNavigationBar with previous route has back button' , (
95
132
WidgetTester tester,
96
133
) async {
@@ -104,7 +141,7 @@ void main() {
104
141
expect (nextButton1, findsNothing);
105
142
106
143
// Go back to the previous page.
107
- final Finder backButton1 = find.byType (CupertinoButton );
144
+ final Finder backButton1 = find.byType (CupertinoButton ).first ;
108
145
expect (backButton1, findsOneWidget);
109
146
await tester.tap (backButton1);
110
147
await tester.pumpAndSettle ();
@@ -118,7 +155,7 @@ void main() {
118
155
expect (nextButton2, findsNothing);
119
156
120
157
// Go back to the previous page.
121
- final Finder backButton2 = find.byType (CupertinoButton );
158
+ final Finder backButton2 = find.byType (CupertinoButton ).first ;
122
159
expect (backButton2, findsOneWidget);
123
160
await tester.tap (backButton2);
124
161
await tester.pumpAndSettle ();
0 commit comments