Unverified Commit 873de562 authored by Hans Muller's avatar Hans Muller Committed by GitHub

Update constructor APIs TooltipTheme, ToggleButtonsTheme, PopupMenuTheme (#37338)

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