@@ -11,6 +11,7 @@ import 'package:flutter/widgets.dart';
1111
1212import 'app_bar_theme.dart' ;
1313import 'back_button.dart' ;
14+ import 'color_scheme.dart' ;
1415import 'constants.dart' ;
1516import 'debug.dart' ;
1617import 'flexible_space_bar.dart' ;
@@ -196,6 +197,7 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
196197 this .shadowColor,
197198 this .shape,
198199 this .backgroundColor,
200+ this .foregroundColor,
199201 this .brightness,
200202 this .iconTheme,
201203 this .actionsIconTheme,
@@ -357,20 +359,68 @@ class AppBar extends StatefulWidget implements PreferredSizeWidget {
357359 /// zero.
358360 final ShapeBorder ? shape;
359361
360- /// The color to use for the app bar's material. Typically this should be set
361- /// along with [brightness] , [iconTheme] , [textTheme] .
362+ /// The fill color to use for the app bar's [Material] .
362363 ///
363- /// If this property is null, then [AppBarTheme.color] of
364- /// [ThemeData.appBarTheme] is used. If that is also null, then
365- /// [ThemeData.primaryColor] is used.
364+ /// If null, then the [AppBarTheme.color] is used. If that value is also
365+ /// null, then [AppBar] uses the overall theme's [ColorScheme.primary] if the
366+ /// overall theme's brightness is [Brightness.light] , and [ColorScheme.surface]
367+ /// if the overall theme's [brightness] is [Brightness.dark] .
368+ ///
369+ /// See also:
370+ ///
371+ /// * [foregroundColor] , which specifies the color for icons and text within
372+ /// the app bar.
373+ /// * [Theme.of] , which returns the current overall Material theme as
374+ /// a [ThemeData].
375+ /// * [ThemeData.colorScheme] , the thirteen colors that most Material widget
376+ /// default colors are based on.
377+ /// * [ColorScheme.brightness] , which indicates if the overall [Theme]
378+ /// is light or dark.
366379 final Color ? backgroundColor;
367380
368- /// The brightness of the app bar's material. Typically this is set along
369- /// with [backgroundColor] , [iconTheme] , [textTheme] .
381+ /// The default color for [Text] and [Icon] s within the app bar.
370382 ///
371- /// If this property is null, then [AppBarTheme.brightness] of
372- /// [ThemeData.appBarTheme] is used. If that is also null, then
373- /// [ThemeData.primaryColorBrightness] is used.
383+ /// If null, then [AppBarTheme.foregroundColor] is used. If that
384+ /// value is also null, then [AppBar] uses the overall theme's
385+ /// [ColorScheme.onPrimary] if the overall theme's brightness is
386+ /// [Brightness.light] , and [ColorScheme.onSurface] if the overall
387+ /// theme's [brightness] is [Brightness.dark] .
388+ ///
389+ /// This color is used to configure [DefaultTextStyle] that contains
390+ /// the app bar's children, and the default [IconTheme] widgets that
391+ /// are created if [iconTheme] and [actionsIconTheme] are null.
392+ ///
393+ /// See also:
394+ ///
395+ /// * [backgroundColor] , which specifies the app bar's background color.
396+ /// * [Theme.of] , which returns the current overall Material theme as
397+ /// a [ThemeData].
398+ /// * [ThemeData.colorScheme] , the thirteen colors that most Material widget
399+ /// default colors are based on.
400+ /// * [ColorScheme.brightness] , which indicates if the overall [Theme]
401+ /// is light or dark.
402+ final Color ? foregroundColor;
403+
404+ /// Determines the brightness of the [SystemUiOverlayStyle] : for
405+ /// [Brightness.dark] , [SystemUiOverlayStyle.light] is used and fo
406+ /// [Brightness.light] , [SystemUiOverlayStyle.dark] is used.
407+ ///
408+ /// If this value is null then [AppBarTheme.brightness] is used
409+ /// and if that's null then overall theme's brightness is used.
410+ ///
411+ /// The AppBar is built within a `AnnotatedRegion<SystemUiOverlayStyle>`
412+ /// which causes [SystemChrome.setSystemUIOverlayStyle] to be called
413+ /// automatically. Apps should not enclose the AppBar with
414+ /// their own [AnnotatedRegion] .
415+ ///
416+ /// See also:
417+ ///
418+ /// * [Theme.of] , which returns the current overall Material theme as
419+ /// a [ThemeData].
420+ /// * [ThemeData.colorScheme] , the thirteen colors that most Material widget
421+ /// default colors are based on.
422+ /// * [ColorScheme.brightness] , which indicates if the overall [Theme]
423+ /// is light or dark.
374424 final Brightness ? brightness;
375425
376426 /// The color, opacity, and size to use for app bar icons. Typically this
@@ -499,6 +549,7 @@ class _AppBarState extends State<AppBar> {
499549 assert (! widget.primary || debugCheckHasMediaQuery (context));
500550 assert (debugCheckHasMaterialLocalizations (context));
501551 final ThemeData theme = Theme .of (context);
552+ final ColorScheme colorScheme = theme.colorScheme;
502553 final AppBarTheme appBarTheme = AppBarTheme .of (context);
503554 final ScaffoldState ? scaffold = Scaffold .maybeOf (context);
504555 final ModalRoute <dynamic >? parentRoute = ModalRoute .of (context);
@@ -510,18 +561,25 @@ class _AppBarState extends State<AppBar> {
510561
511562 final double toolbarHeight = widget.toolbarHeight ?? kToolbarHeight;
512563
564+ final Color backgroundColor = widget.backgroundColor
565+ ?? appBarTheme.color
566+ ?? (colorScheme.brightness == Brightness .dark ? colorScheme.surface : colorScheme.primary);
567+ final Color foregroundColor = widget.foregroundColor
568+ ?? appBarTheme.foregroundColor
569+ ?? (colorScheme.brightness == Brightness .dark ? colorScheme.onSurface : colorScheme.onPrimary);
570+
513571 IconThemeData overallIconTheme = widget.iconTheme
514572 ?? appBarTheme.iconTheme
515- ?? theme.primaryIconTheme ;
573+ ?? theme.iconTheme. copyWith (color : foregroundColor) ;
516574 IconThemeData actionsIconTheme = widget.actionsIconTheme
517575 ?? appBarTheme.actionsIconTheme
518576 ?? overallIconTheme;
519577 TextStyle ? centerStyle = widget.textTheme? .headline6
520578 ?? appBarTheme.textTheme? .headline6
521- ?? theme.primaryTextTheme.headline6;
579+ ?? theme.primaryTextTheme.headline6? . copyWith (color : foregroundColor) ;
522580 TextStyle ? sideStyle = widget.textTheme? .bodyText2
523581 ?? appBarTheme.textTheme? .bodyText2
524- ?? theme.primaryTextTheme.bodyText2;
582+ ?? theme.primaryTextTheme.bodyText2? . copyWith (color : foregroundColor) ;
525583
526584 if (widget.toolbarOpacity != 1.0 ) {
527585 final double opacity = const Interval (0.25 , 1.0 , curve: Curves .fastOutSlowIn).transform (widget.toolbarOpacity);
@@ -530,10 +588,10 @@ class _AppBarState extends State<AppBar> {
530588 if (sideStyle? .color != null )
531589 sideStyle = sideStyle! .copyWith (color: sideStyle.color! .withOpacity (opacity));
532590 overallIconTheme = overallIconTheme.copyWith (
533- opacity: opacity * (overallIconTheme.opacity ?? 1.0 )
591+ opacity: opacity * (overallIconTheme.opacity ?? 1.0 ),
534592 );
535593 actionsIconTheme = actionsIconTheme.copyWith (
536- opacity: opacity * (actionsIconTheme.opacity ?? 1.0 )
594+ opacity: opacity * (actionsIconTheme.opacity ?? 1.0 ),
537595 );
538596 }
539597
@@ -707,21 +765,19 @@ class _AppBarState extends State<AppBar> {
707765 ],
708766 );
709767 }
768+
710769 final Brightness brightness = widget.brightness
711770 ?? appBarTheme.brightness
712- ?? theme.primaryColorBrightness ;
771+ ?? colorScheme.brightness ;
713772 final SystemUiOverlayStyle overlayStyle = brightness == Brightness .dark
714773 ? SystemUiOverlayStyle .light
715774 : SystemUiOverlayStyle .dark;
716-
717775 return Semantics (
718776 container: true ,
719777 child: AnnotatedRegion <SystemUiOverlayStyle >(
720778 value: overlayStyle,
721779 child: Material (
722- color: widget.backgroundColor
723- ?? appBarTheme.color
724- ?? theme.primaryColor,
780+ color: backgroundColor,
725781 elevation: widget.elevation
726782 ?? appBarTheme.elevation
727783 ?? _defaultElevation,
0 commit comments