1 | // Copyright 2014 The Flutter Authors. All rights reserved. |
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | import 'package:flutter/material.dart'; |
6 | import 'package:flutter_localizations/flutter_localizations.dart'; |
7 | import 'package:flutter_test/flutter_test.dart'; |
8 | |
9 | void main() { |
10 | testWidgets('Material2 - Text baseline with CJK locale' , (WidgetTester tester) async { |
11 | // This test in combination with 'Text baseline with EN locale' verify the baselines |
12 | // used to align text with ideographic baselines are reasonable. We are currently |
13 | // using the alphabetic baseline to lay out as the ideographic baseline is not yet |
14 | // properly implemented. When the ideographic baseline is better defined and implemented, |
15 | // the values of this test should change very slightly. See the issue this is based off |
16 | // of: https://github.com/flutter/flutter/issues/25782. |
17 | final Key targetKey = UniqueKey(); |
18 | await tester.pumpWidget( |
19 | MaterialApp( |
20 | theme: ThemeData(useMaterial3: false), |
21 | routes: <String, WidgetBuilder>{ |
22 | '/next' : (BuildContext context) { |
23 | return const Text('Next' ); |
24 | }, |
25 | }, |
26 | localizationsDelegates: GlobalMaterialLocalizations.delegates, |
27 | supportedLocales: const <Locale>[ |
28 | Locale('en' , 'US' ), |
29 | Locale('es' , 'ES' ), |
30 | Locale('zh' , 'CN' ), |
31 | ], |
32 | locale: const Locale('zh' , 'CN' ), |
33 | home: Material( |
34 | child: Center( |
35 | child: Builder( |
36 | key: targetKey, |
37 | builder: (BuildContext context) { |
38 | return PopupMenuButton<int>( |
39 | onSelected: (int value) { |
40 | Navigator.pushNamed(context, '/next' ); |
41 | }, |
42 | itemBuilder: (BuildContext context) { |
43 | return <PopupMenuItem<int>>[ |
44 | const PopupMenuItem<int>( |
45 | value: 1, |
46 | child: Text('hello, world' , style: TextStyle(color: Colors.blue)), |
47 | ), |
48 | const PopupMenuItem<int>( |
49 | value: 2, |
50 | child: Text('你好,世界' , style: TextStyle(color: Colors.blue)), |
51 | ), |
52 | ]; |
53 | }, |
54 | ); |
55 | }, |
56 | ), |
57 | ), |
58 | ), |
59 | ), |
60 | ); |
61 | |
62 | await tester.tap(find.byKey(targetKey)); |
63 | await tester.pumpAndSettle(); |
64 | |
65 | expect(find.text('hello, world' ), findsOneWidget); |
66 | expect(find.text('你好,世界' ), findsOneWidget); |
67 | |
68 | expect(tester.getTopLeft(find.text('hello, world' )).dy, 299.5); |
69 | expect(tester.getBottomLeft(find.text('hello, world' )).dy, 316.5); |
70 | |
71 | expect(tester.getTopLeft(find.text('你好,世界' )).dy, 347.5); |
72 | expect(tester.getBottomLeft(find.text('你好,世界' )).dy, 364.5); |
73 | }); |
74 | |
75 | testWidgets('Material3 - Text baseline with CJK locale' , (WidgetTester tester) async { |
76 | // This test in combination with 'Text baseline with EN locale' verify the baselines |
77 | // used to align text with ideographic baselines are reasonable. We are currently |
78 | // using the alphabetic baseline to lay out as the ideographic baseline is not yet |
79 | // properly implemented. When the ideographic baseline is better defined and implemented, |
80 | // the values of this test should change very slightly. See the issue this is based off |
81 | // of: https://github.com/flutter/flutter/issues/25782. |
82 | final Key targetKey = UniqueKey(); |
83 | await tester.pumpWidget( |
84 | MaterialApp( |
85 | routes: <String, WidgetBuilder>{ |
86 | '/next' : (BuildContext context) { |
87 | return const Text('Next' ); |
88 | }, |
89 | }, |
90 | localizationsDelegates: GlobalMaterialLocalizations.delegates, |
91 | supportedLocales: const <Locale>[ |
92 | Locale('en' , 'US' ), |
93 | Locale('es' , 'ES' ), |
94 | Locale('zh' , 'CN' ), |
95 | ], |
96 | locale: const Locale('zh' , 'CN' ), |
97 | home: Material( |
98 | child: Center( |
99 | child: Builder( |
100 | key: targetKey, |
101 | builder: (BuildContext context) { |
102 | return PopupMenuButton<int>( |
103 | onSelected: (int value) { |
104 | Navigator.pushNamed(context, '/next' ); |
105 | }, |
106 | itemBuilder: (BuildContext context) { |
107 | return <PopupMenuItem<int>>[ |
108 | const PopupMenuItem<int>( |
109 | value: 1, |
110 | child: Text('hello, world' , style: TextStyle(color: Colors.blue)), |
111 | ), |
112 | const PopupMenuItem<int>( |
113 | value: 2, |
114 | child: Text('你好,世界' , style: TextStyle(color: Colors.blue)), |
115 | ), |
116 | ]; |
117 | }, |
118 | ); |
119 | }, |
120 | ), |
121 | ), |
122 | ), |
123 | ), |
124 | ); |
125 | |
126 | await tester.tap(find.byKey(targetKey)); |
127 | await tester.pumpAndSettle(); |
128 | |
129 | expect(find.text('hello, world' ), findsOneWidget); |
130 | expect(find.text('你好,世界' ), findsOneWidget); |
131 | |
132 | expect(tester.getTopLeft(find.text('hello, world' )).dy, 298.0); |
133 | expect(tester.getBottomLeft(find.text('hello, world' )).dy, 318.0); |
134 | |
135 | expect(tester.getTopLeft(find.text('你好,世界' )).dy, 346.0); |
136 | expect(tester.getBottomLeft(find.text('你好,世界' )).dy, 366.0); |
137 | }); |
138 | |
139 | testWidgets('Material2 - Text baseline with EN locale' , (WidgetTester tester) async { |
140 | // This test in combination with 'Text baseline with CJK locale' verify the baselines |
141 | // used to align text with ideographic baselines are reasonable. We are currently |
142 | // using the alphabetic baseline to lay out as the ideographic baseline is not yet |
143 | // properly implemented. When the ideographic baseline is better defined and implemented, |
144 | // the values of this test should change very slightly. See the issue this is based off |
145 | // of: https://github.com/flutter/flutter/issues/25782. |
146 | final Key targetKey = UniqueKey(); |
147 | await tester.pumpWidget( |
148 | MaterialApp( |
149 | theme: ThemeData(useMaterial3: false), |
150 | routes: <String, WidgetBuilder>{ |
151 | '/next' : (BuildContext context) { |
152 | return const Text('Next' ); |
153 | }, |
154 | }, |
155 | localizationsDelegates: GlobalMaterialLocalizations.delegates, |
156 | supportedLocales: const <Locale>[ |
157 | Locale('en' , 'US' ), |
158 | Locale('es' , 'ES' ), |
159 | Locale('zh' , 'CN' ), |
160 | ], |
161 | locale: const Locale('en' , 'US' ), |
162 | home: Material( |
163 | child: Center( |
164 | child: Builder( |
165 | key: targetKey, |
166 | builder: (BuildContext context) { |
167 | return PopupMenuButton<int>( |
168 | onSelected: (int value) { |
169 | Navigator.pushNamed(context, '/next' ); |
170 | }, |
171 | itemBuilder: (BuildContext context) { |
172 | return <PopupMenuItem<int>>[ |
173 | const PopupMenuItem<int>( |
174 | value: 1, |
175 | child: Text('hello, world' , style: TextStyle(color: Colors.blue)), |
176 | ), |
177 | const PopupMenuItem<int>( |
178 | value: 2, |
179 | child: Text('你好,世界' , style: TextStyle(color: Colors.blue)), |
180 | ), |
181 | ]; |
182 | }, |
183 | ); |
184 | }, |
185 | ), |
186 | ), |
187 | ), |
188 | ), |
189 | ); |
190 | |
191 | await tester.tap(find.byKey(targetKey)); |
192 | await tester.pumpAndSettle(); |
193 | |
194 | expect(find.text('hello, world' ), findsOneWidget); |
195 | expect(find.text('你好,世界' ), findsOneWidget); |
196 | |
197 | expect(tester.getTopLeft(find.text('hello, world' )).dy, 300.0); |
198 | expect(tester.getBottomLeft(find.text('hello, world' )).dy, 316.0); |
199 | |
200 | expect(tester.getTopLeft(find.text('你好,世界' )).dy, 348.0); |
201 | expect(tester.getBottomLeft(find.text('你好,世界' )).dy, 364.0); |
202 | }); |
203 | |
204 | testWidgets('Material3 - Text baseline with EN locale' , (WidgetTester tester) async { |
205 | // This test in combination with 'Text baseline with CJK locale' verify the baselines |
206 | // used to align text with ideographic baselines are reasonable. We are currently |
207 | // using the alphabetic baseline to lay out as the ideographic baseline is not yet |
208 | // properly implemented. When the ideographic baseline is better defined and implemented, |
209 | // the values of this test should change very slightly. See the issue this is based off |
210 | // of: https://github.com/flutter/flutter/issues/25782. |
211 | final Key targetKey = UniqueKey(); |
212 | await tester.pumpWidget( |
213 | MaterialApp( |
214 | routes: <String, WidgetBuilder>{ |
215 | '/next' : (BuildContext context) { |
216 | return const Text('Next' ); |
217 | }, |
218 | }, |
219 | localizationsDelegates: GlobalMaterialLocalizations.delegates, |
220 | supportedLocales: const <Locale>[ |
221 | Locale('en' , 'US' ), |
222 | Locale('es' , 'ES' ), |
223 | Locale('zh' , 'CN' ), |
224 | ], |
225 | locale: const Locale('en' , 'US' ), |
226 | home: Material( |
227 | child: Center( |
228 | child: Builder( |
229 | key: targetKey, |
230 | builder: (BuildContext context) { |
231 | return PopupMenuButton<int>( |
232 | onSelected: (int value) { |
233 | Navigator.pushNamed(context, '/next' ); |
234 | }, |
235 | itemBuilder: (BuildContext context) { |
236 | return <PopupMenuItem<int>>[ |
237 | const PopupMenuItem<int>( |
238 | value: 1, |
239 | child: Text('hello, world' , style: TextStyle(color: Colors.blue)), |
240 | ), |
241 | const PopupMenuItem<int>( |
242 | value: 2, |
243 | child: Text('你好,世界' , style: TextStyle(color: Colors.blue)), |
244 | ), |
245 | ]; |
246 | }, |
247 | ); |
248 | }, |
249 | ), |
250 | ), |
251 | ), |
252 | ), |
253 | ); |
254 | |
255 | await tester.tap(find.byKey(targetKey)); |
256 | await tester.pumpAndSettle(); |
257 | |
258 | expect(find.text('hello, world' ), findsOneWidget); |
259 | expect(find.text('你好,世界' ), findsOneWidget); |
260 | |
261 | expect(tester.getTopLeft(find.text('hello, world' )).dy, 298.0); |
262 | expect(tester.getBottomLeft(find.text('hello, world' )).dy, 318.0); |
263 | |
264 | expect(tester.getTopLeft(find.text('你好,世界' )).dy, 346.0); |
265 | expect(tester.getBottomLeft(find.text('你好,世界' )).dy, 366.0); |
266 | }); |
267 | } |
268 | |