diff --git a/packages/flutter/lib/src/material/popup_menu.dart b/packages/flutter/lib/src/material/popup_menu.dart index a764df677f..11218f80b6 100644 --- a/packages/flutter/lib/src/material/popup_menu.dart +++ b/packages/flutter/lib/src/material/popup_menu.dart @@ -656,7 +656,7 @@ class _PopupMenuRoute extends PopupRoute { Widget menu = _PopupMenu(route: this, semanticLabel: semanticLabel); if (popupMenuTheme != null) - menu = PopupMenuTheme(textStyle: popupMenuTheme.textStyle, child: menu); + menu = PopupMenuTheme(data: PopupMenuThemeData(textStyle: popupMenuTheme.textStyle), child: menu); if (theme != null) menu = Theme(data: theme, child: menu); diff --git a/packages/flutter/lib/src/material/popup_menu_theme.dart b/packages/flutter/lib/src/material/popup_menu_theme.dart index ef24902bb7..fa2904479c 100644 --- a/packages/flutter/lib/src/material/popup_menu_theme.dart +++ b/packages/flutter/lib/src/material/popup_menu_theme.dart @@ -124,20 +124,13 @@ class PopupMenuThemeData extends Diagnosticable { class PopupMenuTheme extends InheritedWidget { /// Creates a popup menu theme that controls the configurations for /// popup menus in its widget subtree. - PopupMenuTheme({ + /// + /// The data argument must not be null. + const PopupMenuTheme({ Key key, - Color color, - ShapeBorder shape, - double elevation, - TextStyle textStyle, + @required this.data, Widget child, - }) : data = PopupMenuThemeData( - color: color, - shape: shape, - elevation: elevation, - textStyle: textStyle, - ), - super(key: key, child: child); + }) : assert(data != null), super(key: key, child: child); /// The properties for descendant popup menu widgets. final PopupMenuThemeData data; diff --git a/packages/flutter/lib/src/material/toggle_buttons_theme.dart b/packages/flutter/lib/src/material/toggle_buttons_theme.dart index c845c0801f..66c8b40b27 100644 --- a/packages/flutter/lib/src/material/toggle_buttons_theme.dart +++ b/packages/flutter/lib/src/material/toggle_buttons_theme.dart @@ -216,38 +216,13 @@ class ToggleButtonsThemeData extends Diagnosticable { class ToggleButtonsTheme extends InheritedWidget { /// Creates a toggle buttons theme that controls the color and border /// parameters for [ToggleButtons]. - ToggleButtonsTheme({ + /// + /// The data argument must not be null. + const ToggleButtonsTheme({ Key key, - Color color, - Color selectedColor, - Color disabledColor, - Color fillColor, - Color focusColor, - Color highlightColor, - Color hoverColor, - Color splashColor, - Color borderColor, - Color selectedBorderColor, - Color disabledBorderColor, - BorderRadius borderRadius, - double borderWidth, + @required this.data, Widget child, - }) : data = ToggleButtonsThemeData( - color: color, - selectedColor: selectedColor, - disabledColor: disabledColor, - fillColor: fillColor, - focusColor: focusColor, - highlightColor: highlightColor, - hoverColor: hoverColor, - splashColor: splashColor, - borderColor: borderColor, - selectedBorderColor: selectedBorderColor, - disabledBorderColor: disabledBorderColor, - borderRadius: borderRadius, - borderWidth: borderWidth, - ), - super(key: key, child: child); + }) : assert(data != null), super(key: key, child: child); /// Specifies the color and border values for descendant [ToggleButtons] widgets. final ToggleButtonsThemeData data; @@ -269,4 +244,4 @@ class ToggleButtonsTheme extends InheritedWidget { @override bool updateShouldNotify(ToggleButtonsTheme oldWidget) => data != oldWidget.data; -} \ No newline at end of file +} diff --git a/packages/flutter/lib/src/material/tooltip_theme.dart b/packages/flutter/lib/src/material/tooltip_theme.dart index 0316d33a1a..2976db8cf0 100644 --- a/packages/flutter/lib/src/material/tooltip_theme.dart +++ b/packages/flutter/lib/src/material/tooltip_theme.dart @@ -196,9 +196,11 @@ class TooltipThemeData extends Diagnosticable { /// /// ```dart /// TooltipTheme( -/// decoration: BoxDecoration( -/// color: Colors.blue.withOpacity(0.9), -/// borderRadius: BorderRadius.zero, +/// data: TooltipThemeData( +/// decoration: BoxDecoration( +/// color: Colors.blue.withOpacity(0.9), +/// borderRadius: BorderRadius.zero, +/// ), /// ), /// child: Tooltip( /// message: 'Example tooltip', @@ -214,32 +216,13 @@ class TooltipThemeData extends Diagnosticable { class TooltipTheme extends InheritedWidget { /// Creates a tooltip theme that controls the configurations for /// [Tooltip]. - TooltipTheme({ + /// + /// The data argument must not be null. + const TooltipTheme({ Key key, - double height, - EdgeInsetsGeometry padding, - EdgeInsetsGeometry margin, - double verticalOffset, - bool preferBelow, - bool excludeFromSemantics, - Decoration decoration, - TextStyle textStyle, - Duration waitDuration, - Duration showDuration, + @required this.data, Widget child, - }) : data = TooltipThemeData( - height: height, - padding: padding, - margin: margin, - verticalOffset: verticalOffset, - preferBelow: preferBelow, - excludeFromSemantics: excludeFromSemantics, - decoration: decoration, - textStyle: textStyle, - waitDuration: waitDuration, - showDuration: showDuration, - ), - super(key: key, child: child); + }) : assert(data != null), super(key: key, child: child); /// The properties for descendant [Tooltip] widgets. final TooltipThemeData data; diff --git a/packages/flutter/test/material/popup_menu_theme_test.dart b/packages/flutter/test/material/popup_menu_theme_test.dart index 79fd151d7e..eb7fd70605 100644 --- a/packages/flutter/test/material/popup_menu_theme_test.dart +++ b/packages/flutter/test/material/popup_menu_theme_test.dart @@ -261,10 +261,12 @@ void main() { child: Column( children: [ PopupMenuTheme( - color: Colors.pink, - shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(10)), - elevation: 6.0, - textStyle: const TextStyle(color: Color(0xfffff000), textBaseline: TextBaseline.alphabetic), + data: PopupMenuThemeData( + color: Colors.pink, + shape: BeveledRectangleBorder(borderRadius: BorderRadius.circular(10)), + elevation: 6.0, + textStyle: const TextStyle(color: Color(0xfffff000), textBaseline: TextBaseline.alphabetic), + ), child: PopupMenuButton( key: popupButtonKey, itemBuilder: (BuildContext context) { diff --git a/packages/flutter/test/material/toggle_buttons_theme_test.dart b/packages/flutter/test/material/toggle_buttons_theme_test.dart index 107cfde2c1..1b15806cf3 100644 --- a/packages/flutter/test/material/toggle_buttons_theme_test.dart +++ b/packages/flutter/test/material/toggle_buttons_theme_test.dart @@ -22,7 +22,7 @@ void main() { expect(const ToggleButtonsThemeData().hashCode, const ToggleButtonsThemeData().copyWith().hashCode); }); - test('ToggleButtonsThemeData defaults', () { + test('ToggleButtonsThemeData defaults', () { const ToggleButtonsThemeData themeData = ToggleButtonsThemeData(); expect(themeData.color, null); expect(themeData.selectedColor, null); @@ -38,7 +38,7 @@ void main() { expect(themeData.borderRadius, null); expect(themeData.borderWidth, null); - final ToggleButtonsTheme theme = ToggleButtonsTheme(); + const ToggleButtonsTheme theme = ToggleButtonsTheme(data: ToggleButtonsThemeData()); expect(theme.data.color, null); expect(theme.data.selectedColor, null); expect(theme.data.disabledColor, null); @@ -118,6 +118,7 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( + data: const ToggleButtonsThemeData(), child: ToggleButtons( color: enabledColor, isSelected: const [false], @@ -154,7 +155,9 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - selectedColor: selectedColor, + data: const ToggleButtonsThemeData( + selectedColor: selectedColor, + ), child: ToggleButtons( color: enabledColor, isSelected: const [true], @@ -186,7 +189,9 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - disabledColor: disabledColor, + data: const ToggleButtonsThemeData( + disabledColor: disabledColor, + ), child: ToggleButtons( color: enabledColor, isSelected: const [false], @@ -221,7 +226,7 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - fillColor: customFillColor, + data: const ToggleButtonsThemeData(fillColor: customFillColor), child: ToggleButtons( isSelected: const [true], onPressed: (int index) {}, @@ -257,10 +262,12 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - splashColor: splashColor, - highlightColor: highlightColor, - hoverColor: hoverColor, - focusColor: focusColor, + data: const ToggleButtonsThemeData( + splashColor: splashColor, + highlightColor: highlightColor, + hoverColor: hoverColor, + focusColor: focusColor, + ), child: ToggleButtons( isSelected: const [true], onPressed: (int index) {}, @@ -332,8 +339,10 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - borderColor: borderColor, - borderWidth: customWidth, + data: const ToggleButtonsThemeData( + borderColor: borderColor, + borderWidth: customWidth, + ), child: ToggleButtons( isSelected: const [false], onPressed: (int index) {}, @@ -371,8 +380,10 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - selectedBorderColor: selectedBorderColor, - borderWidth: customWidth, + data: const ToggleButtonsThemeData( + selectedBorderColor: selectedBorderColor, + borderWidth: customWidth, + ), child: ToggleButtons( isSelected: const [true], onPressed: (int index) {}, @@ -409,8 +420,10 @@ void main() { Material( child: boilerplate( child: ToggleButtonsTheme( - disabledBorderColor: disabledBorderColor, - borderWidth: customWidth, + data: const ToggleButtonsThemeData( + disabledBorderColor: disabledBorderColor, + borderWidth: customWidth, + ), child: ToggleButtons( isSelected: const [false], children: const [ @@ -443,4 +456,4 @@ void main() { ); }, ); -} \ No newline at end of file +} diff --git a/packages/flutter/test/material/tooltip_theme_test.dart b/packages/flutter/test/material/tooltip_theme_test.dart index 3625ef63ed..b52447f5d7 100644 --- a/packages/flutter/test/material/tooltip_theme_test.dart +++ b/packages/flutter/test/material/tooltip_theme_test.dart @@ -159,10 +159,12 @@ void main() { Directionality( textDirection: TextDirection.ltr, child: TooltipTheme( - height: 100.0, - padding: const EdgeInsets.all(0.0), - verticalOffset: 100.0, - preferBelow: false, + data: const TooltipThemeData( + height: 100.0, + padding: EdgeInsets.all(0.0), + verticalOffset: 100.0, + preferBelow: false, + ), child: Overlay( initialEntries: [ OverlayEntry( @@ -286,10 +288,12 @@ void main() { Directionality( textDirection: TextDirection.ltr, child: TooltipTheme( - height: 190.0, - padding: const EdgeInsets.all(0.0), - verticalOffset: 100.0, - preferBelow: false, + data: const TooltipThemeData( + height: 190.0, + padding: EdgeInsets.all(0.0), + verticalOffset: 100.0, + preferBelow: false, + ), child: Overlay( initialEntries: [ OverlayEntry( @@ -412,10 +416,12 @@ void main() { Directionality( textDirection: TextDirection.ltr, child: TooltipTheme( - height: 190.0, - padding: const EdgeInsets.all(0.0), - verticalOffset: 100.0, - preferBelow: true, + data: const TooltipThemeData( + height: 190.0, + padding: EdgeInsets.all(0.0), + verticalOffset: 100.0, + preferBelow: true, + ), child: Overlay( initialEntries: [ OverlayEntry( @@ -529,8 +535,10 @@ void main() { OverlayEntry( builder: (BuildContext context) { return TooltipTheme( - padding: const EdgeInsets.all(0.0), - margin: const EdgeInsets.all(_customPaddingValue), + data: const TooltipThemeData( + padding: EdgeInsets.all(0.0), + margin: EdgeInsets.all(_customPaddingValue), + ), child: Tooltip( key: key, message: tooltipText, @@ -607,6 +615,7 @@ void main() { final GlobalKey key = GlobalKey(); await tester.pumpWidget(MaterialApp( home: TooltipTheme( + data: const TooltipThemeData(), child: Tooltip( textStyle: const TextStyle( color: Colors.orange, @@ -687,7 +696,7 @@ void main() { Directionality( textDirection: TextDirection.ltr, child: TooltipTheme( - decoration: customDecoration, + data: const TooltipThemeData(decoration: customDecoration), child: Overlay( initialEntries: [ OverlayEntry( @@ -769,14 +778,16 @@ void main() { testWidgets('Tooltip height and padding - TooltipTheme', (WidgetTester tester) async { final GlobalKey key = GlobalKey(); const double customTooltipHeight = 100.0; - const double customPaddingVal = 20.0; + const double customPaddingValue = 20.0; await tester.pumpWidget( Directionality( textDirection: TextDirection.ltr, child: TooltipTheme( - height: customTooltipHeight, - padding: const EdgeInsets.all(customPaddingVal), + data: const TooltipThemeData( + height: customTooltipHeight, + padding: EdgeInsets.all(customPaddingValue), + ), child: Overlay( initialEntries: [ OverlayEntry( @@ -805,8 +816,8 @@ void main() { )); expect(tip.size.height, equals(customTooltipHeight)); - expect(content.size.height, equals(customTooltipHeight - 2 * customPaddingVal)); - expect(content.size.width, equals(tip.size.width - 2 * customPaddingVal)); + expect(content.size.height, equals(customTooltipHeight - 2 * customPaddingValue)); + expect(content.size.width, equals(tip.size.width - 2 * customPaddingValue)); }, skip: isBrowser); testWidgets('Tooltip waitDuration - ThemeData.tooltipTheme', (WidgetTester tester) async { @@ -868,7 +879,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: TooltipTheme( - waitDuration: customWaitDuration, + data: const TooltipThemeData(waitDuration: customWaitDuration), child: Center( child: Tooltip( message: tooltipText, @@ -943,7 +954,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: TooltipTheme( - showDuration: customShowDuration, + data: const TooltipThemeData(showDuration: customShowDuration), child: Center( child: Tooltip( message: tooltipText, @@ -1011,9 +1022,10 @@ void main() { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget( - MaterialApp( + const MaterialApp( home: TooltipTheme( - child: const Center( + data: TooltipThemeData(), + child: Center( child: Tooltip( message: 'Foo', child: Text('Bar'), @@ -1088,10 +1100,10 @@ void main() { final SemanticsTester semantics = SemanticsTester(tester); await tester.pumpWidget( - MaterialApp( + const MaterialApp( home: TooltipTheme( - excludeFromSemantics: true, - child: const Center( + data: TooltipThemeData(excludeFromSemantics: true), + child: Center( child: Tooltip( message: 'Foo', child: Text('Bar'), @@ -1175,6 +1187,7 @@ void main() { await tester.pumpWidget( MaterialApp( home: TooltipTheme( + data: const TooltipThemeData(), child: Center( child: Tooltip( message: 'Foo',