@@ -19,8 +19,10 @@ void main() {
19
19
expect (identical (FloatingActionButtonThemeData .lerp (data, data, 0.5 ), data), true );
20
20
});
21
21
22
- testWidgets ('Default values are used when no FloatingActionButton or FloatingActionButtonThemeData properties are specified' , (WidgetTester tester) async {
22
+ testWidgets ('Material3: Default values are used when no FloatingActionButton or FloatingActionButtonThemeData properties are specified' , (WidgetTester tester) async {
23
+ const ColorScheme colorScheme = ColorScheme .light ();
23
24
await tester.pumpWidget (MaterialApp (
25
+ theme: ThemeData .from (useMaterial3: true , colorScheme: colorScheme),
24
26
home: Scaffold (
25
27
floatingActionButton: FloatingActionButton (
26
28
onPressed: () { },
@@ -29,10 +31,33 @@ void main() {
29
31
),
30
32
));
31
33
32
- // The color scheme values are guaranteed to be non null since the default
33
- // [ThemeData] creates it with [ColorScheme.fromSwatch].
34
- expect (_getRawMaterialButton (tester).fillColor, ThemeData ().colorScheme.secondary);
35
- expect (_getRichText (tester).text.style! .color, ThemeData ().colorScheme.onSecondary);
34
+ expect (_getRawMaterialButton (tester).fillColor, colorScheme.primaryContainer);
35
+ expect (_getRichText (tester).text.style! .color, colorScheme.onPrimaryContainer);
36
+
37
+ // These defaults come directly from the [FloatingActionButton].
38
+ expect (_getRawMaterialButton (tester).elevation, 6 );
39
+ expect (_getRawMaterialButton (tester).highlightElevation, 6 );
40
+ expect (_getRawMaterialButton (tester).shape, const RoundedRectangleBorder (borderRadius: BorderRadius .all (Radius .circular (16.0 ))));
41
+ expect (_getRawMaterialButton (tester).splashColor, colorScheme.onPrimaryContainer.withOpacity (0.12 ));
42
+ expect (_getRawMaterialButton (tester).constraints, const BoxConstraints .tightFor (width: 56.0 , height: 56.0 ));
43
+ expect (_getIconSize (tester).width, 24.0 );
44
+ expect (_getIconSize (tester).height, 24.0 );
45
+ });
46
+
47
+ testWidgets ('Material2: Default values are used when no FloatingActionButton or FloatingActionButtonThemeData properties are specified' , (WidgetTester tester) async {
48
+ const ColorScheme colorScheme = ColorScheme .light ();
49
+ await tester.pumpWidget (MaterialApp (
50
+ theme: ThemeData .from (useMaterial3: false , colorScheme: colorScheme),
51
+ home: Scaffold (
52
+ floatingActionButton: FloatingActionButton (
53
+ onPressed: () { },
54
+ child: const Icon (Icons .add),
55
+ ),
56
+ ),
57
+ ));
58
+
59
+ expect (_getRawMaterialButton (tester).fillColor, colorScheme.secondary);
60
+ expect (_getRichText (tester).text.style! .color, colorScheme.onSecondary);
36
61
37
62
// These defaults come directly from the [FloatingActionButton].
38
63
expect (_getRawMaterialButton (tester).elevation, 6 );
@@ -191,7 +216,8 @@ void main() {
191
216
expect (_getIconSize (tester).height, iconSize);
192
217
});
193
218
194
- testWidgets ('FloatingActionButton.extended uses custom properties when specified in the theme' , (WidgetTester tester) async {
219
+ testWidgets ('Material3: FloatingActionButton.extended uses custom properties when specified in the theme' , (WidgetTester tester) async {
220
+ const ColorScheme colorScheme = ColorScheme .light ();
195
221
const Key iconKey = Key ('icon' );
196
222
const Key labelKey = Key ('label' );
197
223
const BoxConstraints constraints = BoxConstraints .tightFor (height: 100.0 );
@@ -200,7 +226,43 @@ void main() {
200
226
const TextStyle textStyle = TextStyle (letterSpacing: 2.0 );
201
227
202
228
await tester.pumpWidget (MaterialApp (
203
- theme: ThemeData ().copyWith (
229
+ theme: ThemeData (
230
+ useMaterial3: true ,
231
+ colorScheme: colorScheme,
232
+ ).copyWith (
233
+ floatingActionButtonTheme: const FloatingActionButtonThemeData (
234
+ extendedSizeConstraints: constraints,
235
+ extendedIconLabelSpacing: iconLabelSpacing,
236
+ extendedPadding: padding,
237
+ extendedTextStyle: textStyle,
238
+ ),
239
+ ),
240
+ home: Scaffold (
241
+ floatingActionButton: FloatingActionButton .extended (
242
+ onPressed: () { },
243
+ label: const Text ('Extended' , key: labelKey),
244
+ icon: const Icon (Icons .add, key: iconKey),
245
+ ),
246
+ ),
247
+ ));
248
+
249
+ expect (_getRawMaterialButton (tester).constraints, constraints);
250
+ expect (tester.getTopLeft (find.byKey (labelKey)).dx - tester.getTopRight (find.byKey (iconKey)).dx, iconLabelSpacing);
251
+ expect (tester.getTopLeft (find.byKey (iconKey)).dx - tester.getTopLeft (find.byType (FloatingActionButton )).dx, padding.start);
252
+ expect (tester.getTopRight (find.byType (FloatingActionButton )).dx - tester.getTopRight (find.byKey (labelKey)).dx, padding.end);
253
+ expect (_getRawMaterialButton (tester).textStyle, textStyle.copyWith (color: colorScheme.onPrimaryContainer));
254
+ });
255
+
256
+ testWidgets ('Material2: FloatingActionButton.extended uses custom properties when specified in the theme' , (WidgetTester tester) async {
257
+ const Key iconKey = Key ('icon' );
258
+ const Key labelKey = Key ('label' );
259
+ const BoxConstraints constraints = BoxConstraints .tightFor (height: 100.0 );
260
+ const double iconLabelSpacing = 33.0 ;
261
+ const EdgeInsetsDirectional padding = EdgeInsetsDirectional .only (start: 5.0 , end: 6.0 );
262
+ const TextStyle textStyle = TextStyle (letterSpacing: 2.0 );
263
+
264
+ await tester.pumpWidget (MaterialApp (
265
+ theme: ThemeData (useMaterial3: false ).copyWith (
204
266
floatingActionButtonTheme: const FloatingActionButtonThemeData (
205
267
extendedSizeConstraints: constraints,
206
268
extendedIconLabelSpacing: iconLabelSpacing,
@@ -225,15 +287,52 @@ void main() {
225
287
expect (_getRawMaterialButton (tester).textStyle, textStyle.copyWith (color: const Color (0xffffffff )));
226
288
});
227
289
228
- testWidgets ('FloatingActionButton.extended custom properties takes priority over FloatingActionButtonThemeData spacing' , (WidgetTester tester) async {
290
+ testWidgets ('Material3: FloatingActionButton.extended custom properties takes priority over FloatingActionButtonThemeData spacing' , (WidgetTester tester) async {
291
+ const ColorScheme colorScheme = ColorScheme .light ();
229
292
const Key iconKey = Key ('icon' );
230
293
const Key labelKey = Key ('label' );
231
294
const double iconLabelSpacing = 33.0 ;
232
295
const EdgeInsetsDirectional padding = EdgeInsetsDirectional .only (start: 5.0 , end: 6.0 );
233
296
const TextStyle textStyle = TextStyle (letterSpacing: 2.0 );
234
297
235
298
await tester.pumpWidget (MaterialApp (
236
- theme: ThemeData ().copyWith (
299
+ theme: ThemeData (
300
+ useMaterial3: true ,
301
+ colorScheme: colorScheme,
302
+ ).copyWith (
303
+ floatingActionButtonTheme: const FloatingActionButtonThemeData (
304
+ extendedIconLabelSpacing: 25.0 ,
305
+ extendedPadding: EdgeInsetsDirectional .only (start: 7.0 , end: 8.0 ),
306
+ extendedTextStyle: TextStyle (letterSpacing: 3.0 ),
307
+ ),
308
+ ),
309
+ home: Scaffold (
310
+ floatingActionButton: FloatingActionButton .extended (
311
+ onPressed: () { },
312
+ label: const Text ('Extended' , key: labelKey),
313
+ icon: const Icon (Icons .add, key: iconKey),
314
+ extendedIconLabelSpacing: iconLabelSpacing,
315
+ extendedPadding: padding,
316
+ extendedTextStyle: textStyle,
317
+ ),
318
+ ),
319
+ ));
320
+
321
+ expect (tester.getTopLeft (find.byKey (labelKey)).dx - tester.getTopRight (find.byKey (iconKey)).dx, iconLabelSpacing);
322
+ expect (tester.getTopLeft (find.byKey (iconKey)).dx - tester.getTopLeft (find.byType (FloatingActionButton )).dx, padding.start);
323
+ expect (tester.getTopRight (find.byType (FloatingActionButton )).dx - tester.getTopRight (find.byKey (labelKey)).dx, padding.end);
324
+ expect (_getRawMaterialButton (tester).textStyle, textStyle.copyWith (color: colorScheme.onPrimaryContainer));
325
+ });
326
+
327
+ testWidgets ('Material2: FloatingActionButton.extended custom properties takes priority over FloatingActionButtonThemeData spacing' , (WidgetTester tester) async {
328
+ const Key iconKey = Key ('icon' );
329
+ const Key labelKey = Key ('label' );
330
+ const double iconLabelSpacing = 33.0 ;
331
+ const EdgeInsetsDirectional padding = EdgeInsetsDirectional .only (start: 5.0 , end: 6.0 );
332
+ const TextStyle textStyle = TextStyle (letterSpacing: 2.0 );
333
+
334
+ await tester.pumpWidget (MaterialApp (
335
+ theme: ThemeData (useMaterial3: false ).copyWith (
237
336
floatingActionButtonTheme: const FloatingActionButtonThemeData (
238
337
extendedIconLabelSpacing: 25.0 ,
239
338
extendedPadding: EdgeInsetsDirectional .only (start: 7.0 , end: 8.0 ),
0 commit comments