From bb2e7b5250c062c375be4c3f0af603658650189e Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Wed, 22 Jun 2016 15:19:31 -0700 Subject: [PATCH] Add AppBar iconTheme parameter (#4693) --- .../lib/demo/shrine/shrine_page.dart | 2 + .../flutter_gallery/lib/demo/shrine_demo.dart | 12 +++--- .../flutter/lib/src/material/app_bar.dart | 39 ++++++++++--------- 3 files changed, 27 insertions(+), 26 deletions(-) diff --git a/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart b/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart index ff0bfe112a..8a4d592e02 100644 --- a/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart +++ b/examples/flutter_gallery/lib/demo/shrine/shrine_page.dart @@ -88,6 +88,8 @@ class ShrinePageState extends State { appBar: new AppBar( elevation: _appBarElevation, backgroundColor: Theme.of(context).cardColor, + iconTheme: Theme.of(context).iconTheme, + brightness: Brightness.light, flexibleSpace: new Container( decoration: new BoxDecoration( border: new Border( diff --git a/examples/flutter_gallery/lib/demo/shrine_demo.dart b/examples/flutter_gallery/lib/demo/shrine_demo.dart index f283f05b36..22fea5850b 100644 --- a/examples/flutter_gallery/lib/demo/shrine_demo.dart +++ b/examples/flutter_gallery/lib/demo/shrine_demo.dart @@ -14,13 +14,11 @@ import 'shrine/shrine_theme.dart' show ShrineTheme; // isn't a standalone app with its own main() and MaterialApp. Widget buildShrine(Widget child) { return new Theme( - data: new ThemeData(primarySwatch: Colors.grey), - child: new IconTheme( - data: new IconThemeData(color: const Color(0xFF707070)), - child: new ShrineTheme( - child: child - ) - ) + data: new ThemeData( + primarySwatch: Colors.grey, + iconTheme: new IconThemeData(color: const Color(0xFF707070)) + ), + child: new ShrineTheme(child: child) ); } diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 4a80c70c3c..82e265135d 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -46,10 +46,6 @@ abstract class AppBarBottomWidget extends Widget { /// AppBar's [collapsedHeight] and [bottomHeight] define how small the app bar /// 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: /// /// * [Scaffold] @@ -72,6 +68,7 @@ class AppBar extends StatelessWidget { this.elevation: 4, this.backgroundColor, this.brightness, + this.iconTheme, this.textTheme, this.padding: EdgeInsets.zero, double expandedHeight, @@ -120,23 +117,26 @@ class AppBar extends StatelessWidget { /// The following elevations have defined shadows: 1, 2, 3, 4, 6, 8, 9, 12, 16, 24 final int elevation; - /// The color to use for the app bar's material. This generally should be set - /// in tandem with [brightness]. + /// The color to use for the app bar's material. Typically this should be set + /// along with [brightness], [iconTheme], [textTheme]. /// /// Defaults to [ThemeData.primaryColor]. final Color backgroundColor; - /// The brightness of the app bar's material. This generally should be set in - /// tandem with [backgroundColor]. + /// The brightness of the app bar's material. Typically this is set along + /// with [backgroundColor], [iconTheme], [textTheme]. /// - /// Defaults to [ThemeData.brightness]. - /// - /// Icons within the app bar will continue to use - /// [ThemeData.primaryIconTheme]. If this clashes with the brightness - /// specified here, consider using an [IconTheme] inside the [AppBar]. + /// Defaults to [ThemeData.primaryColorBrightness]. 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]. final TextTheme textTheme; @@ -175,6 +175,7 @@ class AppBar extends StatelessWidget { elevation: elevation ?? this.elevation, backgroundColor: backgroundColor ?? this.backgroundColor, brightness: brightness ?? this.brightness, + iconTheme: iconTheme ?? this.iconTheme, textTheme: textTheme ?? this.textTheme, padding: padding ?? this.padding, expandedHeight: expandedHeight ?? this._expandedHeight, @@ -215,11 +216,11 @@ class AppBar extends StatelessWidget { final double statusBarHeight = MediaQuery.of(context).padding.top; final ThemeData theme = Theme.of(context); - IconThemeData iconTheme = theme.primaryIconTheme; + IconThemeData appBarIconTheme = iconTheme ?? theme.primaryIconTheme; TextStyle centerStyle = textTheme?.title ?? theme.primaryTextTheme.title; TextStyle sideStyle = textTheme?.body1 ?? theme.primaryTextTheme.body1; - Brightness brightness = this.brightness ?? theme.brightness; + Brightness brightness = this.brightness ?? theme.primaryColorBrightness; SystemChrome.setSystemUIOverlayStyle(brightness == Brightness.dark ? mojom.SystemUiOverlayStyle.light : mojom.SystemUiOverlayStyle.dark); @@ -231,8 +232,8 @@ class AppBar extends StatelessWidget { centerStyle = centerStyle.copyWith(color: centerStyle.color.withOpacity(opacity)); if (sideStyle?.color != null) sideStyle = sideStyle.copyWith(color: sideStyle.color.withOpacity(opacity)); - iconTheme = iconTheme.copyWith( - opacity: opacity * (iconTheme.opacity ?? 1.0) + appBarIconTheme = appBarIconTheme.copyWith( + opacity: opacity * (appBarIconTheme.opacity ?? 1.0) ); } @@ -262,7 +263,7 @@ class AppBar extends StatelessWidget { height: kToolBarHeight, child: new IconTheme.merge( context: context, - data: iconTheme, + data: appBarIconTheme, child: new DefaultTextStyle( style: sideStyle, child: new Row(children: toolBarRow)