@@ -19,8 +19,10 @@ void main() {
1919 expect (identical (FloatingActionButtonThemeData .lerp (data, data, 0.5 ), data), true );
2020 });
2121
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 ();
2324 await tester.pumpWidget (MaterialApp (
25+ theme: ThemeData .from (useMaterial3: true , colorScheme: colorScheme),
2426 home: Scaffold (
2527 floatingActionButton: FloatingActionButton (
2628 onPressed: () { },
@@ -29,10 +31,33 @@ void main() {
2931 ),
3032 ));
3133
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);
3661
3762 // These defaults come directly from the [FloatingActionButton].
3863 expect (_getRawMaterialButton (tester).elevation, 6 );
@@ -191,7 +216,8 @@ void main() {
191216 expect (_getIconSize (tester).height, iconSize);
192217 });
193218
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 ();
195221 const Key iconKey = Key ('icon' );
196222 const Key labelKey = Key ('label' );
197223 const BoxConstraints constraints = BoxConstraints .tightFor (height: 100.0 );
@@ -200,7 +226,43 @@ void main() {
200226 const TextStyle textStyle = TextStyle (letterSpacing: 2.0 );
201227
202228 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 (
204266 floatingActionButtonTheme: const FloatingActionButtonThemeData (
205267 extendedSizeConstraints: constraints,
206268 extendedIconLabelSpacing: iconLabelSpacing,
@@ -225,15 +287,52 @@ void main() {
225287 expect (_getRawMaterialButton (tester).textStyle, textStyle.copyWith (color: const Color (0xffffffff )));
226288 });
227289
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 ();
229292 const Key iconKey = Key ('icon' );
230293 const Key labelKey = Key ('label' );
231294 const double iconLabelSpacing = 33.0 ;
232295 const EdgeInsetsDirectional padding = EdgeInsetsDirectional .only (start: 5.0 , end: 6.0 );
233296 const TextStyle textStyle = TextStyle (letterSpacing: 2.0 );
234297
235298 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 (
237336 floatingActionButtonTheme: const FloatingActionButtonThemeData (
238337 extendedIconLabelSpacing: 25.0 ,
239338 extendedPadding: EdgeInsetsDirectional .only (start: 7.0 , end: 8.0 ),
0 commit comments