Commit bb2e7b52 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Add AppBar iconTheme parameter (#4693)

parent e5eabf24
...@@ -88,6 +88,8 @@ class ShrinePageState extends State<ShrinePage> { ...@@ -88,6 +88,8 @@ class ShrinePageState extends State<ShrinePage> {
appBar: new AppBar( appBar: new AppBar(
elevation: _appBarElevation, elevation: _appBarElevation,
backgroundColor: Theme.of(context).cardColor, backgroundColor: Theme.of(context).cardColor,
iconTheme: Theme.of(context).iconTheme,
brightness: Brightness.light,
flexibleSpace: new Container( flexibleSpace: new Container(
decoration: new BoxDecoration( decoration: new BoxDecoration(
border: new Border( border: new Border(
......
...@@ -14,13 +14,11 @@ import 'shrine/shrine_theme.dart' show ShrineTheme; ...@@ -14,13 +14,11 @@ import 'shrine/shrine_theme.dart' show ShrineTheme;
// isn't a standalone app with its own main() and MaterialApp. // isn't a standalone app with its own main() and MaterialApp.
Widget buildShrine(Widget child) { Widget buildShrine(Widget child) {
return new Theme( return new Theme(
data: new ThemeData(primarySwatch: Colors.grey), data: new ThemeData(
child: new IconTheme( primarySwatch: Colors.grey,
data: new IconThemeData(color: const Color(0xFF707070)), iconTheme: new IconThemeData(color: const Color(0xFF707070))
child: new ShrineTheme( ),
child: child child: new ShrineTheme(child: child)
)
)
); );
} }
......
...@@ -46,10 +46,6 @@ abstract class AppBarBottomWidget extends Widget { ...@@ -46,10 +46,6 @@ abstract class AppBarBottomWidget extends Widget {
/// AppBar's [collapsedHeight] and [bottomHeight] define how small the app bar /// AppBar's [collapsedHeight] and [bottomHeight] define how small the app bar
/// will become when the application is scrolled. /// will become when the application is scrolled.
/// ///
/// By default, icons within an app bar will use the
/// [ThemeData.primaryIconTheme]. This can be overridden by nesting an
/// [IconTheme] inside the [AppBar].
///
/// See also: /// See also:
/// ///
/// * [Scaffold] /// * [Scaffold]
...@@ -72,6 +68,7 @@ class AppBar extends StatelessWidget { ...@@ -72,6 +68,7 @@ class AppBar extends StatelessWidget {
this.elevation: 4, this.elevation: 4,
this.backgroundColor, this.backgroundColor,
this.brightness, this.brightness,
this.iconTheme,
this.textTheme, this.textTheme,
this.padding: EdgeInsets.zero, this.padding: EdgeInsets.zero,
double expandedHeight, double expandedHeight,
...@@ -120,23 +117,26 @@ class AppBar extends StatelessWidget { ...@@ -120,23 +117,26 @@ class AppBar extends StatelessWidget {
/// The following elevations have defined shadows: 1, 2, 3, 4, 6, 8, 9, 12, 16, 24 /// The following elevations have defined shadows: 1, 2, 3, 4, 6, 8, 9, 12, 16, 24
final int elevation; final int elevation;
/// The color to use for the app bar's material. This generally should be set /// The color to use for the app bar's material. Typically this should be set
/// in tandem with [brightness]. /// along with [brightness], [iconTheme], [textTheme].
/// ///
/// Defaults to [ThemeData.primaryColor]. /// Defaults to [ThemeData.primaryColor].
final Color backgroundColor; final Color backgroundColor;
/// The brightness of the app bar's material. This generally should be set in /// The brightness of the app bar's material. Typically this is set along
/// tandem with [backgroundColor]. /// with [backgroundColor], [iconTheme], [textTheme].
///
/// Defaults to [ThemeData.brightness].
/// ///
/// Icons within the app bar will continue to use /// Defaults to [ThemeData.primaryColorBrightness].
/// [ThemeData.primaryIconTheme]. If this clashes with the brightness
/// specified here, consider using an [IconTheme] inside the [AppBar].
final Brightness brightness; final Brightness brightness;
/// The typographic style to use for text in the app bar. /// The color, opacity, and size to use for app bar icons. Typically this
/// is set along with [backgroundColor], [brightness], [textTheme].
///
/// Defaults to [ThemeData.primaryIconTheme].
final IconThemeData iconTheme;
/// The typographic styles to use for text in the app bar. Typically this is
/// set along with [brightness] [backgroundColor], [iconTheme].
/// ///
/// Defaults to [ThemeData.primaryTextTheme]. /// Defaults to [ThemeData.primaryTextTheme].
final TextTheme textTheme; final TextTheme textTheme;
...@@ -175,6 +175,7 @@ class AppBar extends StatelessWidget { ...@@ -175,6 +175,7 @@ class AppBar extends StatelessWidget {
elevation: elevation ?? this.elevation, elevation: elevation ?? this.elevation,
backgroundColor: backgroundColor ?? this.backgroundColor, backgroundColor: backgroundColor ?? this.backgroundColor,
brightness: brightness ?? this.brightness, brightness: brightness ?? this.brightness,
iconTheme: iconTheme ?? this.iconTheme,
textTheme: textTheme ?? this.textTheme, textTheme: textTheme ?? this.textTheme,
padding: padding ?? this.padding, padding: padding ?? this.padding,
expandedHeight: expandedHeight ?? this._expandedHeight, expandedHeight: expandedHeight ?? this._expandedHeight,
...@@ -215,11 +216,11 @@ class AppBar extends StatelessWidget { ...@@ -215,11 +216,11 @@ class AppBar extends StatelessWidget {
final double statusBarHeight = MediaQuery.of(context).padding.top; final double statusBarHeight = MediaQuery.of(context).padding.top;
final ThemeData theme = Theme.of(context); final ThemeData theme = Theme.of(context);
IconThemeData iconTheme = theme.primaryIconTheme; IconThemeData appBarIconTheme = iconTheme ?? theme.primaryIconTheme;
TextStyle centerStyle = textTheme?.title ?? theme.primaryTextTheme.title; TextStyle centerStyle = textTheme?.title ?? theme.primaryTextTheme.title;
TextStyle sideStyle = textTheme?.body1 ?? theme.primaryTextTheme.body1; TextStyle sideStyle = textTheme?.body1 ?? theme.primaryTextTheme.body1;
Brightness brightness = this.brightness ?? theme.brightness; Brightness brightness = this.brightness ?? theme.primaryColorBrightness;
SystemChrome.setSystemUIOverlayStyle(brightness == Brightness.dark SystemChrome.setSystemUIOverlayStyle(brightness == Brightness.dark
? mojom.SystemUiOverlayStyle.light ? mojom.SystemUiOverlayStyle.light
: mojom.SystemUiOverlayStyle.dark); : mojom.SystemUiOverlayStyle.dark);
...@@ -231,8 +232,8 @@ class AppBar extends StatelessWidget { ...@@ -231,8 +232,8 @@ class AppBar extends StatelessWidget {
centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity)); centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity));
if (sideStyle?.color != null) if (sideStyle?.color != null)
sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity)); sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity));
iconTheme = iconTheme.copyWith( appBarIconTheme = appBarIconTheme.copyWith(
opacity: opacity * (iconTheme.opacity ?? 1.0) opacity: opacity * (appBarIconTheme.opacity ?? 1.0)
); );
} }
...@@ -262,7 +263,7 @@ class AppBar extends StatelessWidget { ...@@ -262,7 +263,7 @@ class AppBar extends StatelessWidget {
height: kToolBarHeight, height: kToolBarHeight,
child: new IconTheme.merge( child: new IconTheme.merge(
context: context, context: context,
data: iconTheme, data: appBarIconTheme,
child: new DefaultTextStyle( child: new DefaultTextStyle(
style: sideStyle, style: sideStyle,
child: new Row(children: toolBarRow) child: new Row(children: toolBarRow)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment