@@ -15,6 +15,312 @@ void main() {
15
15
debugResetSemanticsIdCounter ();
16
16
});
17
17
18
+ testWidgets ('MaterialButton defaults' , (WidgetTester tester) async {
19
+ final Finder rawButtonMaterial = find.descendant (
20
+ of: find.byType (MaterialButton ),
21
+ matching: find.byType (Material ),
22
+ );
23
+
24
+ // Enabled MaterialButton
25
+ await tester.pumpWidget (
26
+ Directionality (
27
+ textDirection: TextDirection .ltr,
28
+ child: MaterialButton (
29
+ onPressed: () { },
30
+ child: const Text ('button' ),
31
+ ),
32
+ ),
33
+ );
34
+ Material material = tester.widget <Material >(rawButtonMaterial);
35
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
36
+ expect (material.borderOnForeground, true );
37
+ expect (material.borderRadius, null );
38
+ expect (material.clipBehavior, Clip .none);
39
+ expect (material.color, null );
40
+ expect (material.elevation, 2.0 );
41
+ expect (material.shadowColor, const Color (0xff000000 ));
42
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
43
+ expect (material.textStyle.color, const Color (0xdd000000 ));
44
+ expect (material.textStyle.fontFamily, 'Roboto' );
45
+ expect (material.textStyle.fontSize, 14 );
46
+ expect (material.textStyle.fontWeight, FontWeight .w500);
47
+ expect (material.type, MaterialType .transparency);
48
+
49
+ final Offset center = tester.getCenter (find.byType (MaterialButton ));
50
+ await tester.startGesture (center);
51
+ await tester.pumpAndSettle ();
52
+
53
+ // Only elevation changes when enabled and pressed.
54
+ material = tester.widget <Material >(rawButtonMaterial);
55
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
56
+ expect (material.borderOnForeground, true );
57
+ expect (material.borderRadius, null );
58
+ expect (material.clipBehavior, Clip .none);
59
+ expect (material.color, null );
60
+ expect (material.elevation, 8.0 );
61
+ expect (material.shadowColor, const Color (0xff000000 ));
62
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
63
+ expect (material.textStyle.color, const Color (0xdd000000 ));
64
+ expect (material.textStyle.fontFamily, 'Roboto' );
65
+ expect (material.textStyle.fontSize, 14 );
66
+ expect (material.textStyle.fontWeight, FontWeight .w500);
67
+ expect (material.type, MaterialType .transparency);
68
+
69
+
70
+ // Disabled MaterialButton
71
+ await tester.pumpWidget (
72
+ const Directionality (
73
+ textDirection: TextDirection .ltr,
74
+ child: MaterialButton (
75
+ onPressed: null ,
76
+ child: Text ('button' ),
77
+ ),
78
+ ),
79
+ );
80
+ material = tester.widget <Material >(rawButtonMaterial);
81
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
82
+ expect (material.borderOnForeground, true );
83
+ expect (material.borderRadius, null );
84
+ expect (material.clipBehavior, Clip .none);
85
+ expect (material.color, null );
86
+ expect (material.elevation, 0.0 );
87
+ expect (material.shadowColor, const Color (0xff000000 ));
88
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
89
+ expect (material.textStyle.color, const Color (0x61000000 ));
90
+ expect (material.textStyle.fontFamily, 'Roboto' );
91
+ expect (material.textStyle.fontSize, 14 );
92
+ expect (material.textStyle.fontWeight, FontWeight .w500);
93
+ expect (material.type, MaterialType .transparency);
94
+ });
95
+
96
+ testWidgets ('FlatButton defaults' , (WidgetTester tester) async {
97
+ final Finder rawButtonMaterial = find.descendant (
98
+ of: find.byType (FlatButton ),
99
+ matching: find.byType (Material ),
100
+ );
101
+
102
+ // Enabled FlatButton
103
+ await tester.pumpWidget (
104
+ Directionality (
105
+ textDirection: TextDirection .ltr,
106
+ child: FlatButton (
107
+ onPressed: () { },
108
+ child: const Text ('button' ),
109
+ ),
110
+ ),
111
+ );
112
+ Material material = tester.widget <Material >(rawButtonMaterial);
113
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
114
+ expect (material.borderOnForeground, true );
115
+ expect (material.borderRadius, null );
116
+ expect (material.clipBehavior, Clip .none);
117
+ expect (material.color, null );
118
+ expect (material.elevation, 0.0 );
119
+ expect (material.shadowColor, const Color (0xff000000 ));
120
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
121
+ expect (material.textStyle.color, const Color (0xdd000000 ));
122
+ expect (material.textStyle.fontFamily, 'Roboto' );
123
+ expect (material.textStyle.fontSize, 14 );
124
+ expect (material.textStyle.fontWeight, FontWeight .w500);
125
+ expect (material.type, MaterialType .transparency);
126
+
127
+ final Offset center = tester.getCenter (find.byType (FlatButton ));
128
+ await tester.startGesture (center);
129
+ await tester.pumpAndSettle ();
130
+
131
+ material = tester.widget <Material >(rawButtonMaterial);
132
+ // No change vs enabled and not pressed.
133
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
134
+ expect (material.borderOnForeground, true );
135
+ expect (material.borderRadius, null );
136
+ expect (material.clipBehavior, Clip .none);
137
+ expect (material.color, null );
138
+ expect (material.elevation, 0.0 );
139
+ expect (material.shadowColor, const Color (0xff000000 ));
140
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
141
+ expect (material.textStyle.color, const Color (0xdd000000 ));
142
+ expect (material.textStyle.fontFamily, 'Roboto' );
143
+ expect (material.textStyle.fontSize, 14 );
144
+ expect (material.textStyle.fontWeight, FontWeight .w500);
145
+ expect (material.type, MaterialType .transparency);
146
+
147
+ // Disabled FlatButton
148
+ await tester.pumpWidget (
149
+ const Directionality (
150
+ textDirection: TextDirection .ltr,
151
+ child: FlatButton (
152
+ onPressed: null ,
153
+ child: Text ('button' ),
154
+ ),
155
+ ),
156
+ );
157
+ material = tester.widget <Material >(rawButtonMaterial);
158
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
159
+ expect (material.borderOnForeground, true );
160
+ expect (material.borderRadius, null );
161
+ expect (material.clipBehavior, Clip .none);
162
+ expect (material.color, null );
163
+ expect (material.elevation, 0.0 );
164
+ expect (material.shadowColor, const Color (0xff000000 ));
165
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
166
+ expect (material.textStyle.color, const Color (0x61000000 ));
167
+ expect (material.textStyle.fontFamily, 'Roboto' );
168
+ expect (material.textStyle.fontSize, 14 );
169
+ expect (material.textStyle.fontWeight, FontWeight .w500);
170
+ expect (material.type, MaterialType .transparency);
171
+ });
172
+
173
+ testWidgets ('RaisedButton defaults' , (WidgetTester tester) async {
174
+ final Finder rawButtonMaterial = find.descendant (
175
+ of: find.byType (RaisedButton ),
176
+ matching: find.byType (Material ),
177
+ );
178
+
179
+ // Enabled RaisedButton
180
+ await tester.pumpWidget (
181
+ Directionality (
182
+ textDirection: TextDirection .ltr,
183
+ child: RaisedButton (
184
+ onPressed: () { },
185
+ child: const Text ('button' ),
186
+ ),
187
+ ),
188
+ );
189
+ Material material = tester.widget <Material >(rawButtonMaterial);
190
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
191
+ expect (material.borderOnForeground, true );
192
+ expect (material.borderRadius, null );
193
+ expect (material.clipBehavior, Clip .none);
194
+ expect (material.color, const Color (0xffe0e0e0 ));
195
+ expect (material.elevation, 2.0 );
196
+ expect (material.shadowColor, const Color (0xff000000 ));
197
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
198
+ expect (material.textStyle.color, const Color (0xdd000000 ));
199
+ expect (material.textStyle.fontFamily, 'Roboto' );
200
+ expect (material.textStyle.fontSize, 14 );
201
+ expect (material.textStyle.fontWeight, FontWeight .w500);
202
+ expect (material.type, MaterialType .button);
203
+
204
+ final Offset center = tester.getCenter (find.byType (RaisedButton ));
205
+ await tester.startGesture (center);
206
+ await tester.pumpAndSettle ();
207
+
208
+ // Only elevation changes when enabled and pressed.
209
+ material = tester.widget <Material >(rawButtonMaterial);
210
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
211
+ expect (material.borderOnForeground, true );
212
+ expect (material.borderRadius, null );
213
+ expect (material.clipBehavior, Clip .none);
214
+ expect (material.color, const Color (0xffe0e0e0 ));
215
+ expect (material.elevation, 8.0 );
216
+ expect (material.shadowColor, const Color (0xff000000 ));
217
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
218
+ expect (material.textStyle.color, const Color (0xdd000000 ));
219
+ expect (material.textStyle.fontFamily, 'Roboto' );
220
+ expect (material.textStyle.fontSize, 14 );
221
+ expect (material.textStyle.fontWeight, FontWeight .w500);
222
+ expect (material.type, MaterialType .button);
223
+
224
+ // Disabled RaisedButton
225
+ await tester.pumpWidget (
226
+ const Directionality (
227
+ textDirection: TextDirection .ltr,
228
+ child: RaisedButton (
229
+ onPressed: null ,
230
+ child: Text ('button' ),
231
+ ),
232
+ ),
233
+ );
234
+ material = tester.widget <Material >(rawButtonMaterial);
235
+ expect (material.animationDuration, const Duration (milliseconds: 200 ));
236
+ expect (material.borderOnForeground, true );
237
+ expect (material.borderRadius, null );
238
+ expect (material.clipBehavior, Clip .none);
239
+ expect (material.color, const Color (0x61000000 ));
240
+ expect (material.elevation, 0.0 );
241
+ expect (material.shadowColor, const Color (0xff000000 ));
242
+ expect (material.shape, RoundedRectangleBorder (borderRadius: BorderRadius .circular (2.0 )));
243
+ expect (material.textStyle.color, const Color (0x61000000 ));
244
+ expect (material.textStyle.fontFamily, 'Roboto' );
245
+ expect (material.textStyle.fontSize, 14 );
246
+ expect (material.textStyle.fontWeight, FontWeight .w500);
247
+ expect (material.type, MaterialType .button);
248
+ });
249
+
250
+ testWidgets ('OutlineButton defaults' , (WidgetTester tester) async {
251
+ final Finder rawButtonMaterial = find.descendant (
252
+ of: find.byType (OutlineButton ),
253
+ matching: find.byType (Material ),
254
+ );
255
+
256
+ // Enabled OutlineButton
257
+ await tester.pumpWidget (
258
+ Directionality (
259
+ textDirection: TextDirection .ltr,
260
+ child: OutlineButton (
261
+ onPressed: () { },
262
+ child: const Text ('button' ),
263
+ ),
264
+ ),
265
+ );
266
+ Material material = tester.widget <Material >(rawButtonMaterial);
267
+ expect (material.animationDuration, const Duration (milliseconds: 75 ));
268
+ expect (material.borderOnForeground, true );
269
+ expect (material.borderRadius, null );
270
+ expect (material.clipBehavior, Clip .none);
271
+ expect (material.color, const Color (0x00000000 ));
272
+ expect (material.elevation, 0.0 );
273
+ expect (material.shadowColor, const Color (0xff000000 ));
274
+ expect (material.textStyle.color, const Color (0xdd000000 ));
275
+ expect (material.textStyle.fontFamily, 'Roboto' );
276
+ expect (material.textStyle.fontSize, 14 );
277
+ expect (material.textStyle.fontWeight, FontWeight .w500);
278
+ expect (material.type, MaterialType .button);
279
+
280
+ final Offset center = tester.getCenter (find.byType (OutlineButton ));
281
+ await tester.startGesture (center);
282
+ await tester.pumpAndSettle ();
283
+
284
+ // No change vs enabled and not pressed.
285
+ material = tester.widget <Material >(rawButtonMaterial);
286
+ expect (material.animationDuration, const Duration (milliseconds: 75 ));
287
+ expect (material.borderOnForeground, true );
288
+ expect (material.borderRadius, null );
289
+ expect (material.clipBehavior, Clip .none);
290
+ expect (material.color, const Color (0x00000000 ));
291
+ expect (material.elevation, 0.0 );
292
+ expect (material.shadowColor, const Color (0xff000000 ));
293
+ expect (material.textStyle.color, const Color (0xdd000000 ));
294
+ expect (material.textStyle.fontFamily, 'Roboto' );
295
+ expect (material.textStyle.fontSize, 14 );
296
+ expect (material.textStyle.fontWeight, FontWeight .w500);
297
+ expect (material.type, MaterialType .button);
298
+
299
+ // Disabled OutlineButton
300
+ await tester.pumpWidget (
301
+ const Directionality (
302
+ textDirection: TextDirection .ltr,
303
+ child: OutlineButton (
304
+ onPressed: null ,
305
+ child: Text ('button' ),
306
+ ),
307
+ ),
308
+ );
309
+ material = tester.widget <Material >(rawButtonMaterial);
310
+ expect (material.animationDuration, const Duration (milliseconds: 75 ));
311
+ expect (material.borderOnForeground, true );
312
+ expect (material.borderRadius, null );
313
+ expect (material.clipBehavior, Clip .none);
314
+ expect (material.color, const Color (0x00000000 ));
315
+ expect (material.elevation, 0.0 );
316
+ expect (material.shadowColor, const Color (0xff000000 ));
317
+ expect (material.textStyle.color, const Color (0x61000000 ));
318
+ expect (material.textStyle.fontFamily, 'Roboto' );
319
+ expect (material.textStyle.fontSize, 14 );
320
+ expect (material.textStyle.fontWeight, FontWeight .w500);
321
+ expect (material.type, MaterialType .button);
322
+ });
323
+
18
324
testWidgets ('Does FlatButton contribute semantics' , (WidgetTester tester) async {
19
325
final SemanticsTester semantics = SemanticsTester (tester);
20
326
await tester.pumpWidget (
@@ -645,4 +951,27 @@ void main() {
645
951
);
646
952
expect (tester.widget <Material >(rawButtonMaterial).shape, const StadiumBorder ());
647
953
});
954
+
955
+ testWidgets ('MaterialButton defaults' , (WidgetTester tester) async {
956
+ // Regression test for https://github.com/flutter/flutter/issues/30012.
957
+
958
+ final Finder rawButtonMaterial = find.descendant (
959
+ of: find.byType (MaterialButton ),
960
+ matching: find.byType (Material ),
961
+ );
962
+
963
+ await tester.pumpWidget (
964
+ const Directionality (
965
+ textDirection: TextDirection .ltr,
966
+ child: MaterialButton (
967
+ disabledColor: Color (0xff00ff00 ),
968
+ onPressed: null ,
969
+ child: Text ('button' ),
970
+ ),
971
+ ),
972
+ );
973
+
974
+ final Material material = tester.widget <Material >(rawButtonMaterial);
975
+ expect (material.color, const Color (0xff00ff00 ));
976
+ });
648
977
}
0 commit comments