@@ -292,6 +292,10 @@ TextStyle? getIconStyle(WidgetTester tester, IconData icon) {
292
292
return iconRichText.text.style;
293
293
}
294
294
295
+ RenderObject getOverlayColor (WidgetTester tester) {
296
+ return tester.allRenderObjects.firstWhere ((RenderObject object) => object.runtimeType.toString () == '_RenderInkFeatures' );
297
+ }
298
+
295
299
void main () {
296
300
// TODO(bleroux): migrate all M2 tests to M3.
297
301
// See https://github.com/flutter/flutter/issues/139076
@@ -5078,18 +5082,23 @@ void main() {
5078
5082
expect (merged.constraints, overrideTheme.constraints);
5079
5083
});
5080
5084
5081
- testWidgets ('Prefix and suffix IconButtons inherit IconButtonTheme' , (WidgetTester tester) async {
5085
+ testWidgets ('Prefix IconButton inherits IconButtonTheme' , (WidgetTester tester) async {
5082
5086
const IconData prefixIcon = Icons .person;
5083
- const IconData suffixIcon = Icons .search;
5084
5087
const Color backgroundColor = Color (0xffff0000 );
5085
5088
const Color foregroundColor = Color (0xff00ff00 );
5086
- final OutlinedBorder shape = RoundedRectangleBorder (
5089
+ const Color overlayColor = Color (0xff0000ff );
5090
+ const Color shadowColor = Color (0xff0ff0ff );
5091
+ const double elevation = 4.0 ;
5092
+ final RoundedRectangleBorder shape = RoundedRectangleBorder (
5087
5093
borderRadius: BorderRadius .circular (10.0 ),
5088
5094
);
5089
- final ButtonStyle iconButtonStyle = IconButton .styleFrom (
5090
- backgroundColor: backgroundColor,
5091
- foregroundColor: foregroundColor,
5092
- shape: shape,
5095
+ final ButtonStyle iconButtonStyle = ButtonStyle (
5096
+ backgroundColor: const MaterialStatePropertyAll <Color >(backgroundColor),
5097
+ foregroundColor: const MaterialStatePropertyAll <Color >(foregroundColor),
5098
+ overlayColor: const MaterialStatePropertyAll <Color >(overlayColor),
5099
+ shadowColor: const MaterialStatePropertyAll <Color >(shadowColor),
5100
+ elevation: const MaterialStatePropertyAll <double >(elevation),
5101
+ shape: MaterialStatePropertyAll <OutlinedBorder >(shape),
5093
5102
);
5094
5103
5095
5104
await tester.pumpWidget (
@@ -5101,32 +5110,86 @@ void main() {
5101
5110
onPressed: () {},
5102
5111
icon: const Icon (prefixIcon),
5103
5112
),
5104
- suffixIcon: IconButton (
5105
- onPressed: () {},
5106
- icon: const Icon (suffixIcon),
5107
- ),
5108
5113
),
5109
5114
),
5110
5115
),
5111
5116
);
5112
5117
5113
- final Finder prefixIconMaterial = find.descendant (
5118
+ final Finder iconMaterial = find.descendant (
5114
5119
of: find.widgetWithIcon (IconButton , prefixIcon),
5115
5120
matching: find.byType (Material ),
5116
5121
);
5117
- Material material = tester.widget <Material >(prefixIconMaterial );
5122
+ final Material material = tester.widget <Material >(iconMaterial );
5118
5123
expect (material.color, backgroundColor);
5119
- expect (material.shape, iconButtonStyle.shape? .resolve (< WidgetState > {}));
5120
- final Finder suffixIconMaterial = find.descendant (
5124
+ expect (material.shadowColor, shadowColor);
5125
+ expect (material.elevation, elevation);
5126
+ expect (material.shape, shape);
5127
+
5128
+ expect (getIconStyle (tester, prefixIcon)? .color, foregroundColor);
5129
+
5130
+ final Offset center = tester.getCenter (find.byIcon (prefixIcon));
5131
+ final TestGesture gesture = await tester.createGesture (
5132
+ kind: PointerDeviceKind .mouse,
5133
+ );
5134
+ await gesture.addPointer ();
5135
+ await gesture.moveTo (center);
5136
+ await tester.pumpAndSettle ();
5137
+ expect (getOverlayColor (tester), paints..rect (color: overlayColor));
5138
+ });
5139
+
5140
+ testWidgets ('Suffix IconButton inherits IconButtonTheme' , (WidgetTester tester) async {
5141
+ const IconData suffixIcon = Icons .delete;
5142
+ const Color backgroundColor = Color (0xffff0000 );
5143
+ const Color foregroundColor = Color (0xff00ff00 );
5144
+ const Color overlayColor = Color (0xff0000ff );
5145
+ const Color shadowColor = Color (0xff0ff0ff );
5146
+ const double elevation = 4.0 ;
5147
+ final RoundedRectangleBorder shape = RoundedRectangleBorder (
5148
+ borderRadius: BorderRadius .circular (10.0 ),
5149
+ );
5150
+ final ButtonStyle iconButtonStyle = ButtonStyle (
5151
+ backgroundColor: const MaterialStatePropertyAll <Color >(backgroundColor),
5152
+ foregroundColor: const MaterialStatePropertyAll <Color >(foregroundColor),
5153
+ overlayColor: const MaterialStatePropertyAll <Color >(overlayColor),
5154
+ shadowColor: const MaterialStatePropertyAll <Color >(shadowColor),
5155
+ elevation: const MaterialStatePropertyAll <double >(elevation),
5156
+ shape: MaterialStatePropertyAll <OutlinedBorder >(shape),
5157
+ );
5158
+
5159
+ await tester.pumpWidget (
5160
+ IconButtonTheme (
5161
+ data: IconButtonThemeData (style: iconButtonStyle),
5162
+ child: buildInputDecorator (
5163
+ decoration: InputDecoration (
5164
+ suffixIcon: IconButton (
5165
+ onPressed: () {},
5166
+ icon: const Icon (suffixIcon),
5167
+ ),
5168
+ ),
5169
+ ),
5170
+ ),
5171
+ );
5172
+
5173
+ final Finder iconMaterial = find.descendant (
5121
5174
of: find.widgetWithIcon (IconButton , suffixIcon),
5122
5175
matching: find.byType (Material ),
5123
5176
);
5124
- material = tester.widget <Material >(suffixIconMaterial );
5177
+ final Material material = tester.widget <Material >(iconMaterial );
5125
5178
expect (material.color, backgroundColor);
5179
+ expect (material.shadowColor, shadowColor);
5180
+ expect (material.elevation, elevation);
5126
5181
expect (material.shape, shape);
5127
5182
5128
- expect (getIconStyle (tester, prefixIcon)? .color, foregroundColor);
5129
5183
expect (getIconStyle (tester, suffixIcon)? .color, foregroundColor);
5184
+
5185
+ final Offset center = tester.getCenter (find.byIcon (suffixIcon));
5186
+ final TestGesture gesture = await tester.createGesture (
5187
+ kind: PointerDeviceKind .mouse,
5188
+ );
5189
+ await gesture.addPointer ();
5190
+ await gesture.moveTo (center);
5191
+ await tester.pumpAndSettle ();
5192
+ expect (getOverlayColor (tester), paints..rect (color: overlayColor));
5130
5193
});
5131
5194
5132
5195
testWidgets ('Prefix IconButton color respects IconButtonTheme foreground color states' , (WidgetTester tester) async {
0 commit comments