@@ -120,6 +120,43 @@ void main() {
120
120
expect (inkFeatures, paints..rect (rect: const Rect .fromLTRB (350.0 , 250.0 , 450.0 , 350.0 ), color: const Color (0xff00ff00 )));
121
121
});
122
122
123
+ testWidgets ('ink well changes color on hover with overlayColor' , (WidgetTester tester) async {
124
+ // Same test as 'ink well changes color on hover' except that the
125
+ // hover color is specified with the overlayColor parameter.
126
+ await tester.pumpWidget (Material (
127
+ child: Directionality (
128
+ textDirection: TextDirection .ltr,
129
+ child: Center (
130
+ child: Container (
131
+ width: 100 ,
132
+ height: 100 ,
133
+ child: InkWell (
134
+ overlayColor: MaterialStateProperty .resolveWith <Color >((Set <MaterialState > states) {
135
+ if (states.contains (MaterialState .hovered))
136
+ return const Color (0xff00ff00 );
137
+ if (states.contains (MaterialState .focused))
138
+ return const Color (0xff0000ff );
139
+ if (states.contains (MaterialState .pressed))
140
+ return const Color (0xf00fffff );
141
+ return const Color (0xffbadbad ); // Shouldn't happen.
142
+ }),
143
+ onTap: () { },
144
+ onLongPress: () { },
145
+ onHover: (bool hover) { },
146
+ ),
147
+ ),
148
+ ),
149
+ ),
150
+ ));
151
+ final TestGesture gesture = await tester.createGesture (kind: PointerDeviceKind .mouse);
152
+ await gesture.addPointer ();
153
+ addTearDown (gesture.removePointer);
154
+ await gesture.moveTo (tester.getCenter (find.byType (Container )));
155
+ await tester.pumpAndSettle ();
156
+ final RenderObject inkFeatures = tester.allRenderObjects.firstWhere ((RenderObject object) => object.runtimeType.toString () == '_RenderInkFeatures' );
157
+ expect (inkFeatures, paints..rect (rect: const Rect .fromLTRB (350.0 , 250.0 , 450.0 , 350.0 ), color: const Color (0xff00ff00 )));
158
+ });
159
+
123
160
testWidgets ('ink response changes color on focus' , (WidgetTester tester) async {
124
161
FocusManager .instance.highlightStrategy = FocusHighlightStrategy .alwaysTraditional;
125
162
final FocusNode focusNode = FocusNode (debugLabel: 'Ink Focus' );
@@ -155,6 +192,127 @@ void main() {
155
192
..rect (rect: const Rect .fromLTRB (350.0 , 250.0 , 450.0 , 350.0 ), color: const Color (0xff0000ff )));
156
193
});
157
194
195
+ testWidgets ('ink response changes color on focus with overlayColor' , (WidgetTester tester) async {
196
+ // Same test as 'ink well changes color on focus' except that the
197
+ // hover color is specified with the overlayColor parameter.
198
+ FocusManager .instance.highlightStrategy = FocusHighlightStrategy .alwaysTraditional;
199
+ final FocusNode focusNode = FocusNode (debugLabel: 'Ink Focus' );
200
+ await tester.pumpWidget (
201
+ Material (
202
+ child: Directionality (
203
+ textDirection: TextDirection .ltr,
204
+ child: Center (
205
+ child: Container (
206
+ width: 100 ,
207
+ height: 100 ,
208
+ child: InkWell (
209
+ focusNode: focusNode,
210
+ overlayColor: MaterialStateProperty .resolveWith <Color >((Set <MaterialState > states) {
211
+ if (states.contains (MaterialState .hovered))
212
+ return const Color (0xff00ff00 );
213
+ if (states.contains (MaterialState .focused))
214
+ return const Color (0xff0000ff );
215
+ if (states.contains (MaterialState .pressed))
216
+ return const Color (0xf00fffff );
217
+ return const Color (0xffbadbad ); // Shouldn't happen.
218
+ }),
219
+ highlightColor: const Color (0xf00fffff ),
220
+ onTap: () { },
221
+ onLongPress: () { },
222
+ onHover: (bool hover) { },
223
+ ),
224
+ ),
225
+ ),
226
+ ),
227
+ ),
228
+ );
229
+ await tester.pumpAndSettle ();
230
+ final RenderObject inkFeatures = tester.allRenderObjects.firstWhere ((RenderObject object) => object.runtimeType.toString () == '_RenderInkFeatures' );
231
+ expect (inkFeatures, paintsExactlyCountTimes (#rect, 0 ));
232
+ focusNode.requestFocus ();
233
+ await tester.pumpAndSettle ();
234
+ expect (inkFeatures, paints
235
+ ..rect (rect: const Rect .fromLTRB (350.0 , 250.0 , 450.0 , 350.0 ), color: const Color (0xff0000ff )));
236
+ });
237
+
238
+ testWidgets ('ink response splashColor matches splashColor parameter' , (WidgetTester tester) async {
239
+ FocusManager .instance.highlightStrategy = FocusHighlightStrategy .alwaysTouch;
240
+ final FocusNode focusNode = FocusNode (debugLabel: 'Ink Focus' );
241
+ const Color splashColor = Color (0xffff0000 );
242
+ await tester.pumpWidget (Material (
243
+ child: Directionality (
244
+ textDirection: TextDirection .ltr,
245
+ child: Center (
246
+ child: Focus (
247
+ focusNode: focusNode,
248
+ child: Container (
249
+ width: 100 ,
250
+ height: 100 ,
251
+ child: InkWell (
252
+ hoverColor: const Color (0xff00ff00 ),
253
+ splashColor: splashColor,
254
+ focusColor: const Color (0xff0000ff ),
255
+ highlightColor: const Color (0xf00fffff ),
256
+ onTap: () { },
257
+ onLongPress: () { },
258
+ onHover: (bool hover) { },
259
+ ),
260
+ ),
261
+ ),
262
+ ),
263
+ ),
264
+ ));
265
+ await tester.pumpAndSettle ();
266
+ final TestGesture gesture = await tester.startGesture (tester.getRect (find.byType (InkWell )).center);
267
+ await tester.pump (const Duration (milliseconds: 200 )); // unconfirmed splash is well underway
268
+ final RenderObject inkFeatures = tester.allRenderObjects.firstWhere ((RenderObject object) => object.runtimeType.toString () == '_RenderInkFeatures' );
269
+ expect (inkFeatures, paints..circle (x: 50 , y: 50 , color: splashColor));
270
+ await gesture.up ();
271
+ });
272
+
273
+ testWidgets ('ink response splashColor matches resolved overlayColor for MaterialState.pressed' , (WidgetTester tester) async {
274
+ // Same test as 'ink response splashColor matches splashColor
275
+ // parameter' except that the splash color is specified with the
276
+ // overlayColor parameter.
277
+ FocusManager .instance.highlightStrategy = FocusHighlightStrategy .alwaysTouch;
278
+ final FocusNode focusNode = FocusNode (debugLabel: 'Ink Focus' );
279
+ const Color splashColor = Color (0xffff0000 );
280
+ await tester.pumpWidget (Material (
281
+ child: Directionality (
282
+ textDirection: TextDirection .ltr,
283
+ child: Center (
284
+ child: Focus (
285
+ focusNode: focusNode,
286
+ child: Container (
287
+ width: 100 ,
288
+ height: 100 ,
289
+ child: InkWell (
290
+ overlayColor: MaterialStateProperty .resolveWith <Color >((Set <MaterialState > states) {
291
+ if (states.contains (MaterialState .hovered))
292
+ return const Color (0xff00ff00 );
293
+ if (states.contains (MaterialState .focused))
294
+ return const Color (0xff0000ff );
295
+ if (states.contains (MaterialState .pressed))
296
+ return splashColor;
297
+ return const Color (0xffbadbad ); // Shouldn't happen.
298
+ }),
299
+ onTap: () { },
300
+ onLongPress: () { },
301
+ onHover: (bool hover) { },
302
+ ),
303
+ ),
304
+ ),
305
+ ),
306
+ ),
307
+ ));
308
+ await tester.pumpAndSettle ();
309
+ final TestGesture gesture = await tester.startGesture (tester.getRect (find.byType (InkWell )).center);
310
+ await tester.pump (const Duration (milliseconds: 200 )); // unconfirmed splash is well underway
311
+ final RenderObject inkFeatures = tester.allRenderObjects.firstWhere ((RenderObject object) => object.runtimeType.toString () == '_RenderInkFeatures' );
312
+ expect (inkFeatures, paints..circle (x: 50 , y: 50 , color: splashColor));
313
+ await gesture.up ();
314
+ });
315
+
158
316
testWidgets ("ink response doesn't change color on focus when on touch device" , (WidgetTester tester) async {
159
317
FocusManager .instance.highlightStrategy = FocusHighlightStrategy .alwaysTouch;
160
318
final FocusNode focusNode = FocusNode (debugLabel: 'Ink Focus' );
0 commit comments