diff --git a/dev/manual_tests/card_collection.dart b/dev/manual_tests/card_collection.dart index f8ea7b907c..a44cf15741 100644 --- a/dev/manual_tests/card_collection.dart +++ b/dev/manual_tests/card_collection.dart @@ -248,8 +248,7 @@ class CardCollectionState extends State { controller: cardModel.textController, ), ) - : new DefaultTextStyle.merge( - context: context, + : DefaultTextStyle.merge( style: cardLabelStyle.copyWith( fontSize: _varyFontSizes ? 5.0 + index : null ), diff --git a/packages/flutter/lib/src/material/app_bar.dart b/packages/flutter/lib/src/material/app_bar.dart index 92c4905eca..0ccf004ba4 100644 --- a/packages/flutter/lib/src/material/app_bar.dart +++ b/packages/flutter/lib/src/material/app_bar.dart @@ -438,8 +438,7 @@ class _AppBarState extends State { Widget appBar = new ClipRect( child: new CustomSingleChildLayout( delegate: const _ToolbarContainerLayout(), - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: appBarIconTheme, child: new DefaultTextStyle( style: sideStyle, diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 0c8fd4578f..285c88f789 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart @@ -347,8 +347,7 @@ class _BottomNavigationBarState extends State with TickerPr alignment: FractionalOffset.bottomCenter, child: new Container( margin: const EdgeInsets.only(bottom: 10.0), - child: new DefaultTextStyle.merge( - context: context, + child: DefaultTextStyle.merge( style: new TextStyle( fontSize: 14.0, color: colorTween.evaluate(_animations[i]), @@ -419,8 +418,7 @@ class _BottomNavigationBarState extends State with TickerPr margin: const EdgeInsets.only(bottom: 10.0), child: new FadeTransition( opacity: _animations[i], - child: new DefaultTextStyle.merge( - context: context, + child: DefaultTextStyle.merge( style: const TextStyle( fontSize: 14.0, color: Colors.white diff --git a/packages/flutter/lib/src/material/button.dart b/packages/flutter/lib/src/material/button.dart index 182c2dfa7a..7ebcf77bf3 100644 --- a/packages/flutter/lib/src/material/button.dart +++ b/packages/flutter/lib/src/material/button.dart @@ -292,8 +292,7 @@ class _MaterialButtonState extends State { final double height = widget.height ?? buttonTheme.height; final int elevation = (_highlight ? widget.highlightElevation : widget.elevation) ?? 0; final bool hasColorOrElevation = (widget.color != null || elevation > 0); - Widget contents = new IconTheme.merge( - context: context, + Widget contents = IconTheme.merge( data: new IconThemeData( color: textColor ), diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index 4e11babe96..f44377fd1c 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart @@ -466,8 +466,7 @@ class DataTable extends StatelessWidget { ? (placeholder ? Colors.black38 : Colors.black87) : (placeholder ? Colors.white30 : Colors.white70) ), - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: new IconThemeData( color: isLightTheme ? Colors.black54 : Colors.white70 ), diff --git a/packages/flutter/lib/src/material/floating_action_button.dart b/packages/flutter/lib/src/material/floating_action_button.dart index acaed34965..2d3a5214cf 100644 --- a/packages/flutter/lib/src/material/floating_action_button.dart +++ b/packages/flutter/lib/src/material/floating_action_button.dart @@ -124,8 +124,7 @@ class _FloatingActionButtonState extends State { } Widget result = new Center( - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: new IconThemeData(color: iconColor), child: widget.child ) diff --git a/packages/flutter/lib/src/material/grid_tile_bar.dart b/packages/flutter/lib/src/material/grid_tile_bar.dart index bca6c095a9..b7cb165454 100644 --- a/packages/flutter/lib/src/material/grid_tile_bar.dart +++ b/packages/flutter/lib/src/material/grid_tile_bar.dart @@ -124,8 +124,7 @@ class GridTileBar extends StatelessWidget { height: (title != null && subtitle != null) ? 68.0 : 48.0, child: new Theme( data: darkTheme, - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: const IconThemeData(color: Colors.white), child: new Row( crossAxisAlignment: CrossAxisAlignment.center, diff --git a/packages/flutter/lib/src/material/icon_button.dart b/packages/flutter/lib/src/material/icon_button.dart index 08c42d5814..6628607fa4 100644 --- a/packages/flutter/lib/src/material/icon_button.dart +++ b/packages/flutter/lib/src/material/icon_button.dart @@ -151,8 +151,7 @@ class IconButton extends StatelessWidget { width: iconSize, child: new Align( alignment: alignment, - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: new IconThemeData( size: iconSize, color: currentColor diff --git a/packages/flutter/lib/src/material/icon_theme.dart b/packages/flutter/lib/src/material/icon_theme.dart index 9e69aa042a..bdc63993db 100644 --- a/packages/flutter/lib/src/material/icon_theme.dart +++ b/packages/flutter/lib/src/material/icon_theme.dart @@ -28,17 +28,20 @@ class IconTheme extends InheritedWidget { /// Creates an icon theme that controls the color, opacity, and size of /// descendant widgets, and merges in the current icon theme, if any. /// - /// The [context], [data], and [child] arguments must not be null. - factory IconTheme.merge({ + /// The [data] and [child] arguments must not be null. + static Widget merge({ Key key, - @required BuildContext context, @required IconThemeData data, @required Widget child }) { - return new IconTheme( - key: key, - data: _getInheritedIconThemeData(context).merge(data), - child: child + return new Builder( + builder: (BuildContext context) { + return new IconTheme( + key: key, + data: _getInheritedIconThemeData(context).merge(data), + child: child, + ); + }, ); } diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index ca12aa56e4..bf9c562273 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -439,8 +439,7 @@ class InputDecorator extends StatelessWidget { new Container( margin: new EdgeInsets.only(top: iconTop), width: isDense ? 40.0 : 48.0, - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: new IconThemeData( color: isFocused ? activeColor : Colors.black45, size: isDense ? 18.0 : 24.0, diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index a0d856add7..bd927281b1 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -345,8 +345,7 @@ class ListTile extends StatelessWidget { final List children = []; if (leading != null) { - children.add(new IconTheme.merge( - context: context, + children.add(IconTheme.merge( data: new IconThemeData(color: _iconColor(theme, tileTheme)), child: new Container( margin: const EdgeInsets.only(right: 16.0), diff --git a/packages/flutter/lib/src/material/paginated_data_table.dart b/packages/flutter/lib/src/material/paginated_data_table.dart index 4d7205ff31..b517457c18 100644 --- a/packages/flutter/lib/src/material/paginated_data_table.dart +++ b/packages/flutter/lib/src/material/paginated_data_table.dart @@ -377,8 +377,7 @@ class PaginatedDataTableState extends State { // See https://material.google.com/components/data-tables.html#data-tables-tables-within-cards style: _selectedRowCount > 0 ? themeData.textTheme.subhead.copyWith(color: themeData.accentColor) : themeData.textTheme.title.copyWith(fontWeight: FontWeight.w400), - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: const IconThemeData( opacity: 0.54 ), @@ -413,8 +412,7 @@ class PaginatedDataTableState extends State { ), new DefaultTextStyle( style: footerTextStyle, - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: const IconThemeData( opacity: 0.54 ), diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index 66e6e13a74..4ad5fff3e5 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -160,8 +160,7 @@ class _PopupMenuItemState> extends State { ); if (!widget.enabled) { final bool isDark = theme.brightness == Brightness.dark; - item = new IconTheme.merge( - context: context, + item = IconTheme.merge( data: new IconThemeData(opacity: isDark ? 0.5 : 0.38), child: item ); diff --git a/packages/flutter/lib/src/material/tabs.dart b/packages/flutter/lib/src/material/tabs.dart index 9b0a07e673..525db630bf 100644 --- a/packages/flutter/lib/src/material/tabs.dart +++ b/packages/flutter/lib/src/material/tabs.dart @@ -138,8 +138,7 @@ class _TabStyle extends AnimatedWidget { return new DefaultTextStyle( style: textStyle.copyWith(color: color), - child: new IconTheme.merge( - context: context, + child: IconTheme.merge( data: new IconThemeData( size: 24.0, color: color, diff --git a/packages/flutter/lib/src/material/two_level_list.dart b/packages/flutter/lib/src/material/two_level_list.dart index 9c4f319497..3dad002491 100644 --- a/packages/flutter/lib/src/material/two_level_list.dart +++ b/packages/flutter/lib/src/material/two_level_list.dart @@ -201,8 +201,7 @@ class _TwoLevelSublistState extends State with SingleTickerProv ), child: new Column( children: [ - new IconTheme.merge( - context: context, + IconTheme.merge( data: new IconThemeData(color: _iconColor.evaluate(_easeInAnimation)), child: new TwoLevelListItem( onTap: _handleOnTap, diff --git a/packages/flutter/lib/src/widgets/text.dart b/packages/flutter/lib/src/widgets/text.dart index 98abbcc4fd..e7b3059cec 100644 --- a/packages/flutter/lib/src/widgets/text.dart +++ b/packages/flutter/lib/src/widgets/text.dart @@ -41,15 +41,15 @@ class DefaultTextStyle extends InheritedWidget { maxLines = null, overflow = TextOverflow.clip; - /// Creates a default text style that inherits from the given [BuildContext]. + /// Creates a default text style that overrides the text styles in scope at + /// this point in the widget tree. /// /// The given [style] is merged with the [style] from the default text style - /// for the given [BuildContext] and, if non-null, the given [textAlign] - /// replaces the [textAlign] from the default text style for the given - /// [BuildContext]. - factory DefaultTextStyle.merge({ + /// for the [BuildContext] where the widget is inserted, and any of the other + /// arguments that are not null replace the corresponding properties on that + /// same default text style. + static Widget merge({ Key key, - @required BuildContext context, TextStyle style, TextAlign textAlign, bool softWrap, @@ -57,17 +57,20 @@ class DefaultTextStyle extends InheritedWidget { int maxLines, @required Widget child, }) { - assert(context != null); assert(child != null); - final DefaultTextStyle parent = DefaultTextStyle.of(context); - return new DefaultTextStyle( - key: key, - style: parent.style.merge(style), - textAlign: textAlign ?? parent.textAlign, - softWrap: softWrap ?? parent.softWrap, - overflow: overflow ?? parent.overflow, - maxLines: maxLines ?? parent.maxLines, - child: child + return new Builder( + builder: (BuildContext context) { + final DefaultTextStyle parent = DefaultTextStyle.of(context); + return new DefaultTextStyle( + key: key, + style: parent.style.merge(style), + textAlign: textAlign ?? parent.textAlign, + softWrap: softWrap ?? parent.softWrap, + overflow: overflow ?? parent.overflow, + maxLines: maxLines ?? parent.maxLines, + child: child + ); + }, ); } diff --git a/packages/flutter/test/material/popup_menu_test.dart b/packages/flutter/test/material/popup_menu_test.dart index f0e484fd63..863b5cbb3e 100644 --- a/packages/flutter/test/material/popup_menu_test.dart +++ b/packages/flutter/test/material/popup_menu_test.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; void main() { testWidgets('Navigator.push works within a PopupMenuButton', (WidgetTester tester) async { + final Key targetKey = new UniqueKey(); await tester.pumpWidget( new MaterialApp( routes: { @@ -17,6 +18,7 @@ void main() { home: new Material( child: new Center( child: new Builder( + key: targetKey, builder: (BuildContext context) { return new PopupMenuButton( onSelected: (int value) { @@ -38,7 +40,7 @@ void main() { ) ); - await tester.tap(find.byType(Builder)); + await tester.tap(find.byKey(targetKey)); await tester.pump(); await tester.pump(const Duration(seconds: 1)); // finish the menu animation