@@ -508,6 +508,149 @@ void main() {
508508 expect (appBar.surfaceTintColor, Colors .yellow);
509509 });
510510
511+ testWidgets ('AppBarTheme.iconTheme.color takes priority over IconButtonTheme.foregroundColor - M3' , (WidgetTester tester) async {
512+ const IconThemeData overallIconTheme = IconThemeData (color: Colors .yellow);
513+ await tester.pumpWidget (MaterialApp (
514+ theme: ThemeData (
515+ iconButtonTheme: IconButtonThemeData (
516+ style: IconButton .styleFrom (foregroundColor: Colors .red),
517+ ),
518+ appBarTheme: const AppBarTheme (iconTheme: overallIconTheme),
519+ useMaterial3: true ,
520+ ),
521+ home: Scaffold (
522+ appBar: AppBar (
523+ leading: IconButton (icon: const Icon (Icons .menu), onPressed: () {},),
524+ actions: < Widget > [ IconButton (icon: const Icon (Icons .add), onPressed: () {},) ],
525+ title: const Text ('Title' ),
526+ ),
527+ ),
528+ ));
529+
530+ final Color ? leadingIconButtonColor = _iconStyle (tester, Icons .menu)? .color;
531+ final Color ? actionIconButtonColor = _iconStyle (tester, Icons .add)? .color;
532+
533+ expect (leadingIconButtonColor, overallIconTheme.color);
534+ expect (actionIconButtonColor, overallIconTheme.color);
535+ });
536+
537+ testWidgets ('AppBarTheme.iconTheme.size takes priority over IconButtonTheme.iconSize - M3' , (WidgetTester tester) async {
538+ const IconThemeData overallIconTheme = IconThemeData (size: 30.0 );
539+ await tester.pumpWidget (MaterialApp (
540+ theme: ThemeData (
541+ iconButtonTheme: IconButtonThemeData (
542+ style: IconButton .styleFrom (iconSize: 32.0 ),
543+ ),
544+ appBarTheme: const AppBarTheme (iconTheme: overallIconTheme),
545+ useMaterial3: true ,
546+ ),
547+ home: Scaffold (
548+ appBar: AppBar (
549+ leading: IconButton (icon: const Icon (Icons .menu), onPressed: () {},),
550+ actions: < Widget > [ IconButton (icon: const Icon (Icons .add), onPressed: () {},) ],
551+ title: const Text ('Title' ),
552+ ),
553+ ),
554+ ));
555+
556+ final double ? leadingIconButtonSize = _iconStyle (tester, Icons .menu)? .fontSize;
557+ final double ? actionIconButtonSize = _iconStyle (tester, Icons .add)? .fontSize;
558+
559+ expect (leadingIconButtonSize, overallIconTheme.size);
560+ expect (actionIconButtonSize, overallIconTheme.size);
561+ });
562+
563+
564+ testWidgets ('AppBarTheme.actionsIconTheme.color takes priority over IconButtonTheme.foregroundColor - M3' , (WidgetTester tester) async {
565+ const IconThemeData actionsIconTheme = IconThemeData (color: Colors .yellow);
566+ final IconButtonThemeData iconButtonTheme = IconButtonThemeData (
567+ style: IconButton .styleFrom (foregroundColor: Colors .red),
568+ );
569+
570+ await tester.pumpWidget (MaterialApp (
571+ theme: ThemeData (
572+ iconButtonTheme: iconButtonTheme,
573+ appBarTheme: const AppBarTheme (actionsIconTheme: actionsIconTheme),
574+ useMaterial3: true ,
575+ ),
576+ home: Scaffold (
577+ appBar: AppBar (
578+ leading: IconButton (icon: const Icon (Icons .menu), onPressed: () {},),
579+ actions: < Widget > [ IconButton (icon: const Icon (Icons .add), onPressed: () {},) ],
580+ title: const Text ('Title' ),
581+ ),
582+ ),
583+ ));
584+
585+ final Color ? leadingIconButtonColor = _iconStyle (tester, Icons .menu)? .color;
586+ final Color ? actionIconButtonColor = _iconStyle (tester, Icons .add)? .color;
587+
588+ expect (leadingIconButtonColor, Colors .red); // leading color should come from iconButtonTheme
589+ expect (actionIconButtonColor, actionsIconTheme.color);
590+ });
591+
592+ testWidgets ('AppBarTheme.actionsIconTheme.size takes priority over IconButtonTheme.iconSize - M3' , (WidgetTester tester) async {
593+ const IconThemeData actionsIconTheme = IconThemeData (size: 30.0 );
594+ final IconButtonThemeData iconButtonTheme = IconButtonThemeData (
595+ style: IconButton .styleFrom (iconSize: 32.0 ),
596+ );
597+ await tester.pumpWidget (MaterialApp (
598+ theme: ThemeData (
599+ iconButtonTheme: iconButtonTheme,
600+ appBarTheme: const AppBarTheme (actionsIconTheme: actionsIconTheme),
601+ useMaterial3: true ,
602+ ),
603+ home: Scaffold (
604+ appBar: AppBar (
605+ leading: IconButton (icon: const Icon (Icons .menu), onPressed: () {},),
606+ actions: < Widget > [ IconButton (icon: const Icon (Icons .add), onPressed: () {},) ],
607+ title: const Text ('Title' ),
608+ ),
609+ ),
610+ ));
611+
612+ final double ? leadingIconButtonSize = _iconStyle (tester, Icons .menu)? .fontSize;
613+ final double ? actionIconButtonSize = _iconStyle (tester, Icons .add)? .fontSize;
614+
615+ expect (leadingIconButtonSize, 32.0 ); // The size of leading icon button should come from iconButtonTheme
616+ expect (actionIconButtonSize, actionsIconTheme.size);
617+ });
618+
619+ testWidgets ('AppBarTheme.foregroundColor takes priority over IconButtonTheme.foregroundColor - M3' , (WidgetTester tester) async {
620+ final IconButtonThemeData iconButtonTheme = IconButtonThemeData (
621+ style: IconButton .styleFrom (foregroundColor: Colors .red),
622+ );
623+ const AppBarTheme appBarTheme = AppBarTheme (
624+ foregroundColor: Colors .green,
625+ );
626+ final ThemeData themeData = ThemeData (
627+ iconButtonTheme: iconButtonTheme,
628+ appBarTheme: appBarTheme,
629+ useMaterial3: true ,
630+ );
631+
632+ await tester.pumpWidget (
633+ MaterialApp (
634+ theme: themeData,
635+ home: Scaffold (
636+ appBar: AppBar (
637+ title: const Text ('title' ),
638+ leading: IconButton (icon: const Icon (Icons .menu), onPressed: () {}),
639+ actions: < Widget > [
640+ IconButton (icon: const Icon (Icons .add), onPressed: () {}),
641+ ],
642+ ),
643+ ),
644+ ),
645+ );
646+
647+ final Color ? leadingIconButtonColor = _iconStyle (tester, Icons .menu)? .color;
648+ final Color ? actionIconButtonColor = _iconStyle (tester, Icons .add)? .color;
649+
650+ expect (leadingIconButtonColor, appBarTheme.foregroundColor);
651+ expect (actionIconButtonColor, appBarTheme.foregroundColor);
652+ });
653+
511654 testWidgets ('AppBar uses AppBarTheme.titleSpacing' , (WidgetTester tester) async {
512655 const double kTitleSpacing = 10 ;
513656 await tester.pumpWidget (MaterialApp (
@@ -760,3 +903,10 @@ DefaultTextStyle _getAppBarText(WidgetTester tester) {
760903 ).first,
761904 );
762905}
906+
907+ TextStyle ? _iconStyle (WidgetTester tester, IconData icon) {
908+ final RichText iconRichText = tester.widget <RichText >(
909+ find.descendant (of: find.byIcon (icon).first, matching: find.byType (RichText )),
910+ );
911+ return iconRichText.text.style;
912+ }
0 commit comments