ink_well_test.dart 74.6 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/gestures.dart';
6
import 'package:flutter/material.dart';
7
import 'package:flutter/rendering.dart';
8
import 'package:flutter/src/services/keyboard_key.g.dart';
9 10
import 'package:flutter_test/flutter_test.dart';

11
import '../rendering/mock_canvas.dart';
12
import '../widgets/semantics_tester.dart';
13 14
import 'feedback_tester.dart';

15 16
void main() {
  testWidgets('InkWell gestures control test', (WidgetTester tester) async {
17
    final List<String> log = <String>[];
18

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onTap: () {
              log.add('tap');
            },
            onDoubleTap: () {
              log.add('double-tap');
            },
            onLongPress: () {
              log.add('long-press');
            },
            onTapDown: (TapDownDetails details) {
              log.add('tap-down');
            },
36 37 38
            onTapUp: (TapUpDetails details) {
              log.add('tap-up');
            },
39 40 41
            onTapCancel: () {
              log.add('tap-cancel');
            },
42
          ),
43
        ),
44 45
      ),
    ));
46 47 48 49 50 51 52

    await tester.tap(find.byType(InkWell), pointer: 1);

    expect(log, isEmpty);

    await tester.pump(const Duration(seconds: 1));

53
    expect(log, equals(<String>['tap-down', 'tap-up', 'tap']));
54 55 56
    log.clear();

    await tester.tap(find.byType(InkWell), pointer: 2);
57
    await tester.pump(const Duration(milliseconds: 100));
58 59
    await tester.tap(find.byType(InkWell), pointer: 3);

60
    expect(log, equals(<String>['double-tap']));
61 62 63 64
    log.clear();

    await tester.longPress(find.byType(InkWell), pointer: 4);

65 66 67 68 69 70 71 72
    expect(log, equals(<String>['tap-down', 'tap-cancel', 'long-press']));

    log.clear();
    TestGesture gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
    await tester.pump(const Duration(milliseconds: 100));
    expect(log, equals(<String>['tap-down']));
    await gesture.up();
    await tester.pump(const Duration(seconds: 1));
73
    expect(log, equals(<String>['tap-down', 'tap-up', 'tap']));
74 75 76 77 78 79 80

    log.clear();
    gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
    await tester.pump(const Duration(milliseconds: 100));
    await gesture.moveBy(const Offset(0.0, 200.0));
    await gesture.cancel();
    expect(log, equals(<String>['tap-down', 'tap-cancel']));
81
  });
82

83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
  testWidgets('InkWell only onTapDown enables gestures', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/96030
    bool downTapped = false;
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onTapDown: (TapDownDetails details) {
              downTapped = true;
            },
          ),
        ),
      ),
    ));

    await tester.tap(find.byType(InkWell));
    expect(downTapped, true);
  });

103 104 105 106 107 108
  testWidgets('InkWell invokes activation actions when expected', (WidgetTester tester) async {
    final List<String> log = <String>[];

    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Shortcuts(
109 110 111
        shortcuts: const <ShortcutActivator, Intent>{
          SingleActivator(LogicalKeyboardKey.space): ActivateIntent(),
          SingleActivator(LogicalKeyboardKey.enter): ButtonActivateIntent(),
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
        },
        child: Material(
          child: Center(
            child: InkWell(
              autofocus: true,
              onTap: () {
                log.add('tap');
              },
            ),
          ),
        ),
      ),
    ));

    await tester.sendKeyEvent(LogicalKeyboardKey.space);
    await tester.pump();
    expect(log, equals(<String>['tap']));
    log.clear();
    await tester.sendKeyEvent(LogicalKeyboardKey.enter);
    await tester.pump();
    expect(log, equals(<String>['tap']));
  });

135 136
  testWidgets('long-press and tap on disabled should not throw', (WidgetTester tester) async {
    await tester.pumpWidget(const Material(
137 138 139 140 141
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
          child: InkWell(),
        ),
142
      ),
143 144 145 146 147 148 149
    ));
    await tester.tap(find.byType(InkWell), pointer: 1);
    await tester.pump(const Duration(seconds: 1));
    await tester.longPress(find.byType(InkWell), pointer: 1);
    await tester.pump(const Duration(seconds: 1));
  });

150 151 152 153 154
  testWidgets('ink well changes color on hover', (WidgetTester tester) async {
    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
155
          child: SizedBox(
156 157 158 159 160 161 162
            width: 100,
            height: 100,
            child: InkWell(
              hoverColor: const Color(0xff00ff00),
              splashColor: const Color(0xffff0000),
              focusColor: const Color(0xff0000ff),
              highlightColor: const Color(0xf00fffff),
163 164 165
              onTap: () { },
              onLongPress: () { },
              onHover: (bool hover) { },
166 167 168 169 170 171 172
            ),
          ),
        ),
      ),
    ));
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
173
    await gesture.moveTo(tester.getCenter(find.byType(SizedBox)));
174 175 176 177 178
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paints..rect(rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), color: const Color(0xff00ff00)));
  });

179 180 181 182 183 184 185
  testWidgets('ink well changes color on hover with overlayColor', (WidgetTester tester) async {
    // Same test as 'ink well changes color on hover' except that the
    // hover color is specified with the overlayColor parameter.
    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
186
          child: SizedBox(
187 188 189 190
            width: 100,
            height: 100,
            child: InkWell(
              overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
191
                if (states.contains(MaterialState.hovered)) {
192
                  return const Color(0xff00ff00);
193 194
                }
                if (states.contains(MaterialState.focused)) {
195
                  return const Color(0xff0000ff);
196 197
                }
                if (states.contains(MaterialState.pressed)) {
198
                  return const Color(0xf00fffff);
199
                }
200 201 202 203 204 205 206 207 208 209 210 211
                return const Color(0xffbadbad); // Shouldn't happen.
              }),
              onTap: () { },
              onLongPress: () { },
              onHover: (bool hover) { },
            ),
          ),
        ),
      ),
    ));
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
212
    await gesture.moveTo(tester.getCenter(find.byType(SizedBox)));
213 214 215 216 217
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paints..rect(rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), color: const Color(0xff00ff00)));
  });

218
  testWidgets('ink response changes color on focus', (WidgetTester tester) async {
219
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
220
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
221 222 223 224 225
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
226
            child: SizedBox(
227 228 229
              width: 100,
              height: 100,
              child: InkWell(
230
                focusNode: focusNode,
231 232 233 234
                hoverColor: const Color(0xff00ff00),
                splashColor: const Color(0xffff0000),
                focusColor: const Color(0xff0000ff),
                highlightColor: const Color(0xf00fffff),
235 236 237
                onTap: () { },
                onLongPress: () { },
                onHover: (bool hover) { },
238 239 240 241 242
              ),
            ),
          ),
        ),
      ),
243
    );
244 245
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
246
    expect(inkFeatures, paintsExactlyCountTimes(#drawRect, 0));
247 248
    focusNode.requestFocus();
    await tester.pumpAndSettle();
249 250 251 252
    expect(
      inkFeatures,
      paints ..rect(rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), color: const Color(0xff0000ff)),
    );
253 254
  });

255 256 257 258 259 260 261 262 263 264
  testWidgets('ink response changes color on focus with overlayColor', (WidgetTester tester) async {
    // Same test as 'ink well changes color on focus' except that the
    // hover color is specified with the overlayColor parameter.
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
265
            child: SizedBox(
266 267 268 269 270
              width: 100,
              height: 100,
              child: InkWell(
                focusNode: focusNode,
                overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
271
                  if (states.contains(MaterialState.hovered)) {
272
                    return const Color(0xff00ff00);
273 274
                  }
                  if (states.contains(MaterialState.focused)) {
275
                    return const Color(0xff0000ff);
276 277
                  }
                  if (states.contains(MaterialState.pressed)) {
278
                    return const Color(0xf00fffff);
279
                  }
280 281 282 283 284 285 286 287 288 289 290 291 292 293
                  return const Color(0xffbadbad); // Shouldn't happen.
                }),
                highlightColor: const Color(0xf00fffff),
                onTap: () { },
                onLongPress: () { },
                onHover: (bool hover) { },
              ),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
294
    expect(inkFeatures, paintsExactlyCountTimes(#drawRect, 0));
295 296
    focusNode.requestFocus();
    await tester.pumpAndSettle();
297 298 299 300
    expect(
      inkFeatures,
      paints..rect(rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), color: const Color(0xff0000ff)),
    );
301 302
  });

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
  testWidgets('ink well changes color on pressed with overlayColor', (WidgetTester tester) async {
    const Color pressedColor = Color(0xffdd00ff);

    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Container(
          alignment: Alignment.topLeft,
          child: SizedBox(
            width: 100,
            height: 100,
            child: InkWell(
              splashFactory: NoSplash.splashFactory,
              overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
                if (states.contains(MaterialState.pressed)) {
                  return pressedColor;
                }
                return const Color(0xffbadbad); // Shouldn't happen.
              }),
              onTap: () { },
            ),
          ),
        ),
      ),
    ));
    await tester.pumpAndSettle();
    final TestGesture gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paints..rect(rect: const Rect.fromLTRB(0, 0, 100, 100), color: pressedColor.withAlpha(0)));
    await tester.pumpAndSettle(); // Let the press highlight animation finish.
    expect(inkFeatures, paints..rect(rect: const Rect.fromLTRB(0, 0, 100, 100), color: pressedColor));
    await gesture.up();
  });

337 338 339 340 341 342 343 344 345 346
  testWidgets('ink response splashColor matches splashColor parameter', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    const Color splashColor = Color(0xffff0000);
    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
          child: Focus(
            focusNode: focusNode,
347
            child: SizedBox(
348 349 350
              width: 100,
              height: 100,
              child: InkWell(
351 352 353 354 355 356 357
                hoverColor: const Color(0xff00ff00),
                splashColor: splashColor,
                focusColor: const Color(0xff0000ff),
                highlightColor: const Color(0xf00fffff),
                onTap: () { },
                onLongPress: () { },
                onHover: (bool hover) { },
358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
              ),
            ),
          ),
        ),
      ),
    ));
    await tester.pumpAndSettle();
    final TestGesture gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
    await tester.pump(const Duration(milliseconds: 200)); // unconfirmed splash is well underway
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paints..circle(x: 50, y: 50, color: splashColor));
    await gesture.up();
  });

  testWidgets('ink response splashColor matches resolved overlayColor for MaterialState.pressed', (WidgetTester tester) async {
    // Same test as 'ink response splashColor matches splashColor
    // parameter' except that the splash color is specified with the
    // overlayColor parameter.
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    const Color splashColor = Color(0xffff0000);
    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
          child: Focus(
            focusNode: focusNode,
385
            child: SizedBox(
386 387 388
              width: 100,
              height: 100,
              child: InkWell(
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
                overlayColor: MaterialStateProperty.resolveWith<Color>((Set<MaterialState> states) {
                  if (states.contains(MaterialState.hovered)) {
                    return const Color(0xff00ff00);
                  }
                  if (states.contains(MaterialState.focused)) {
                    return const Color(0xff0000ff);
                  }
                  if (states.contains(MaterialState.pressed)) {
                    return splashColor;
                  }
                  return const Color(0xffbadbad); // Shouldn't happen.
                }),
                onTap: () { },
                onLongPress: () { },
                onHover: (bool hover) { },
404 405 406 407 408 409 410 411 412 413 414 415 416 417
              ),
            ),
          ),
        ),
      ),
    ));
    await tester.pumpAndSettle();
    final TestGesture gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
    await tester.pump(const Duration(milliseconds: 200)); // unconfirmed splash is well underway
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paints..circle(x: 50, y: 50, color: splashColor));
    await gesture.up();
  });

418 419 420 421 422 423 424 425
  testWidgets('ink response uses radius for focus highlight', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
426
            child: SizedBox(
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
              width: 100,
              height: 100,
              child: InkResponse(
                focusNode: focusNode,
                radius: 20,
                focusColor: const Color(0xff0000ff),
                onTap: () { },
              ),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));
    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paints..circle(radius: 20, color: const Color(0xff0000ff)));
  });

448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
  testWidgets('InkWell uses borderRadius for focus highlight', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: InkWell(
                focusNode: focusNode,
                borderRadius: BorderRadius.circular(10),
                focusColor: const Color(0xff0000ff),
                onTap: () { },
              ),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));

    expect(inkFeatures, paints..rrect(
      rrect: RRect.fromLTRBR(350.0, 250.0, 450.0, 350.0, const Radius.circular(10)),
      color: const Color(0xff0000ff),
    ));
  });

  testWidgets('InkWell uses borderRadius for hover highlight', (WidgetTester tester) async {
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: MouseRegion(
                child: InkWell(
                  borderRadius: BorderRadius.circular(10),
                  hoverColor: const Color(0xff00ff00),
                  onTap: () { },
                ),
              ),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    // Hover the ink well.
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
    await gesture.addPointer(location: tester.getRect(find.byType(InkWell)).center);
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));

    expect(inkFeatures, paints..rrect(
      rrect: RRect.fromLTRBR(350.0, 250.0, 450.0, 350.0, const Radius.circular(10)),
      color: const Color(0xff00ff00),
    ));
  });

  testWidgets('InkWell customBorder clips for focus highlight', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
            child: SizedBox(
              width: 100,
              height: 100,
              child: MouseRegion(
                child: InkWell(
                  focusNode: focusNode,
                  borderRadius: BorderRadius.circular(10),
                  customBorder: const CircleBorder(),
                  hoverColor: const Color(0xff00ff00),
                  onTap: () { },
                ),
              ),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 0));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 1));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));

    // Create a rounded rectangle path with a radius that makes it similar to the custom border circle.
    const Rect expectedClipRect = Rect.fromLTRB(0, 0, 100, 100);
    final Path expectedClipPath = Path()
      ..addRRect(RRect.fromRectAndRadius(
          expectedClipRect,
          const Radius.circular(50.0),
      ));
    // The ink well custom border path should match the rounded rectangle path.
    expect(
      inkFeatures,
      paints..clipPath(pathMatcher: coversSameAreaAs(
        expectedClipPath,
        areaToCompare: expectedClipRect.inflate(20.0),
        sampleSize: 100,
      )),
    );
  });

  testWidgets('InkWell customBorder clips for hover highlight', (WidgetTester tester) async {
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
            child: SizedBox(
              width: 100,
              height: 100,
              child: MouseRegion(
                child: InkWell(
                  borderRadius: BorderRadius.circular(10),
                  customBorder: const CircleBorder(),
                  hoverColor: const Color(0xff00ff00),
                  onTap: () { },
                ),
              ),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 0));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    // Hover the ink well.
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
    await gesture.addPointer(location: tester.getRect(find.byType(InkWell)).center);
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 1));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));

    // Create a rounded rectangle path with a radius that makes it similar to the custom border circle.
    const Rect expectedClipRect = Rect.fromLTRB(0, 0, 100, 100);
    final Path expectedClipPath = Path()
      ..addRRect(RRect.fromRectAndRadius(
          expectedClipRect,
          const Radius.circular(50.0),
      ));
    // The ink well custom border path should match the rounded rectangle path.
    expect(
      inkFeatures,
      paints..clipPath(pathMatcher: coversSameAreaAs(
        expectedClipPath,
        areaToCompare: expectedClipRect.inflate(20.0),
        sampleSize: 100,
      )),
    );
  });

testWidgets('InkResponse radius can be updated', (WidgetTester tester) async {
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    Widget boilerplate(double radius) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: InkResponse(
                focusNode: focusNode,
                radius: radius,
                focusColor: const Color(0xff0000ff),
                onTap: () { },
              ),
            ),
          ),
        ),
      );
    }
    await tester.pumpWidget(boilerplate(10));
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));

    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 1));
    expect(inkFeatures, paints..circle(radius: 10, color: const Color(0xff0000ff)));

    await tester.pumpWidget(boilerplate(20));
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 1));
    expect(inkFeatures, paints..circle(radius: 20, color: const Color(0xff0000ff)));
  });

  testWidgets('InkResponse highlightShape can be updated', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    Widget boilerplate(BoxShape shape) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: InkResponse(
                focusNode: focusNode,
                highlightShape: shape,
                borderRadius: BorderRadius.circular(10),
                focusColor: const Color(0xff0000ff),
                onTap: () { },
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(boilerplate(BoxShape.circle));
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 1));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    await tester.pumpWidget(boilerplate(BoxShape.rectangle));
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));
  });

  testWidgets('InkWell borderRadius can be updated', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    Widget boilerplate(BorderRadius borderRadius) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: InkWell(
                focusNode: focusNode,
                borderRadius: borderRadius,
                focusColor: const Color(0xff0000ff),
                onTap: () { },
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(boilerplate(BorderRadius.circular(10)));
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 0));

    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));
    expect(inkFeatures, paints..rrect(
      rrect: RRect.fromLTRBR(350.0, 250.0, 450.0, 350.0, const Radius.circular(10)),
      color: const Color(0xff0000ff),
    ));

    await tester.pumpWidget(boilerplate(BorderRadius.circular(30)));
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#drawRRect, 1));
    expect(inkFeatures, paints..rrect(
      rrect: RRect.fromLTRBR(350.0, 250.0, 450.0, 350.0, const Radius.circular(30)),
      color: const Color(0xff0000ff),
    ));
  });

  testWidgets('InkWell customBorder can be updated', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTraditional;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    Widget boilerplate(BorderRadius borderRadius) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
            child: SizedBox(
              width: 100,
              height: 100,
              child: MouseRegion(
                child: InkWell(
                  focusNode: focusNode,
                  customBorder: RoundedRectangleBorder(borderRadius: borderRadius),
                  hoverColor: const Color(0xff00ff00),
                  onTap: () { },
                ),
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(boilerplate(BorderRadius.circular(20)));
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 0));

    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 1));

    const Rect expectedClipRect = Rect.fromLTRB(0, 0, 100, 100);
    Path expectedClipPath = Path()
      ..addRRect(RRect.fromRectAndRadius(
          expectedClipRect,
          const Radius.circular(20),
      ));
    expect(
      inkFeatures,
      paints..clipPath(pathMatcher: coversSameAreaAs(
        expectedClipPath,
        areaToCompare: expectedClipRect.inflate(20.0),
        sampleSize: 100,
      )),
    );

    await tester.pumpWidget(boilerplate(BorderRadius.circular(40)));
    await tester.pumpAndSettle();
    expectedClipPath = Path()
      ..addRRect(RRect.fromRectAndRadius(
          expectedClipRect,
          const Radius.circular(40),
      ));
    expect(
      inkFeatures,
      paints..clipPath(pathMatcher: coversSameAreaAs(
        expectedClipPath,
        areaToCompare: expectedClipRect.inflate(20.0),
        sampleSize: 100,
      )),
    );
  });

819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
  testWidgets('InkWell splash customBorder can be updated', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/121626.
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    Widget boilerplate(BorderRadius borderRadius) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
            child: SizedBox(
              width: 100,
              height: 100,
              child: MouseRegion(
                child: InkWell(
                  focusNode: focusNode,
                  customBorder: RoundedRectangleBorder(borderRadius: borderRadius),
                  onTap: () { },
                ),
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(boilerplate(BorderRadius.circular(20)));
    await tester.pumpAndSettle();

    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 0));

    final TestGesture gesture = await tester.startGesture(tester.getRect(find.byType(InkWell)).center);
    await tester.pump(const Duration(milliseconds: 200)); // Unconfirmed splash is well underway.
    expect(inkFeatures, paintsExactlyCountTimes(#clipPath, 2)); // Splash and highlight.

    const Rect expectedClipRect = Rect.fromLTRB(0, 0, 100, 100);
    Path expectedClipPath = Path()
      ..addRRect(RRect.fromRectAndRadius(
          expectedClipRect,
          const Radius.circular(20),
      ));

    // Check that the splash and the highlight are correctly clipped.
    expect(
      inkFeatures,
      paints
        ..clipPath(pathMatcher: coversSameAreaAs(
          expectedClipPath,
          areaToCompare: expectedClipRect.inflate(20.0),
          sampleSize: 100,
        ))
        ..clipPath(pathMatcher: coversSameAreaAs(
          expectedClipPath,
          areaToCompare: expectedClipRect.inflate(20.0),
          sampleSize: 100,
        )),
    );

    await tester.pumpWidget(boilerplate(BorderRadius.circular(40)));
    await tester.pumpAndSettle();
    expectedClipPath = Path()
      ..addRRect(RRect.fromRectAndRadius(
          expectedClipRect,
          const Radius.circular(40),
      ));

    // Check that the splash and the highlight are correctly clipped.
    expect(
      inkFeatures,
      paints
        ..clipPath(pathMatcher: coversSameAreaAs(
          expectedClipPath,
          areaToCompare: expectedClipRect.inflate(20.0),
          sampleSize: 100,
        ))
        ..clipPath(pathMatcher: coversSameAreaAs(
          expectedClipPath,
          areaToCompare: expectedClipRect.inflate(20.0),
          sampleSize: 100,
        )),
    );

    await gesture.up();
  });

904
  testWidgets("ink response doesn't change color on focus when on touch device", (WidgetTester tester) async {
905
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
906 907 908 909 910
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
911
          child: SizedBox(
912 913 914 915 916 917 918 919 920 921 922
            width: 100,
            height: 100,
            child: InkWell(
              focusNode: focusNode,
              hoverColor: const Color(0xff00ff00),
              splashColor: const Color(0xffff0000),
              focusColor: const Color(0xff0000ff),
              highlightColor: const Color(0xf00fffff),
              onTap: () { },
              onLongPress: () { },
              onHover: (bool hover) { },
923 924 925 926 927 928 929
            ),
          ),
        ),
      ),
    ));
    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
930
    expect(inkFeatures, paintsExactlyCountTimes(#drawRect, 0));
931 932
    focusNode.requestFocus();
    await tester.pumpAndSettle();
933
    expect(inkFeatures, paintsExactlyCountTimes(#drawRect, 0));
934 935
  });

936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955
  testWidgets('InkWell.mouseCursor changes cursor on hover', (WidgetTester tester) async {
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
    await gesture.addPointer(location: const Offset(1, 1));

    // Test argument works
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: MouseRegion(
            cursor: SystemMouseCursors.forbidden,
            child: InkWell(
              mouseCursor: SystemMouseCursors.click,
              onTap: () {},
            ),
          ),
        ),
      ),
    );

956
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972

    // Test default of InkWell()
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: MouseRegion(
            cursor: SystemMouseCursors.forbidden,
            child: InkWell(
              onTap: () {},
            ),
          ),
        ),
      ),
    );

973
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
974 975 976 977 978 979 980 981 982 983 984 985 986 987

    // Test disabled
    await tester.pumpWidget(
      const Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: MouseRegion(
            cursor: SystemMouseCursors.forbidden,
            child: InkWell(),
          ),
        ),
      ),
    );

988
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004

    // Test default of InkResponse()
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: MouseRegion(
            cursor: SystemMouseCursors.forbidden,
            child: InkResponse(
              onTap: () {},
            ),
          ),
        ),
      ),
    );

1005
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019

    // Test disabled
    await tester.pumpWidget(
      const Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: MouseRegion(
            cursor: SystemMouseCursors.forbidden,
            child: InkResponse(),
          ),
        ),
      ),
    );

1020
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
1021 1022
  });

1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
  testWidgets('InkResponse containing selectable text changes mouse cursor when hovered', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/104595.
    await tester.pumpWidget(MaterialApp(
      home: SelectionArea(
        child: Material(
          child: InkResponse(
            onTap: () {},
            child: const Text('button'),
          ),
        ),
      ),
    ));

    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
    await gesture.addPointer(location: tester.getCenter(find.byType(Text)));

    await tester.pump();

    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
  });

1044
  group('feedback', () {
1045
    late FeedbackTester feedback;
1046 1047

    setUp(() {
1048
      feedback = FeedbackTester();
1049 1050 1051
    });

    tearDown(() {
1052
      feedback.dispose();
1053 1054 1055
    });

    testWidgets('enabled (default)', (WidgetTester tester) async {
1056 1057
      await tester.pumpWidget(Material(
        child: Directionality(
1058
          textDirection: TextDirection.ltr,
1059 1060
          child: Center(
            child: InkWell(
1061 1062
              onTap: () { },
              onLongPress: () { },
1063
            ),
1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083
          ),
        ),
      ));
      await tester.tap(find.byType(InkWell), pointer: 1);
      await tester.pump(const Duration(seconds: 1));
      expect(feedback.clickSoundCount, 1);
      expect(feedback.hapticCount, 0);

      await tester.tap(find.byType(InkWell), pointer: 1);
      await tester.pump(const Duration(seconds: 1));
      expect(feedback.clickSoundCount, 2);
      expect(feedback.hapticCount, 0);

      await tester.longPress(find.byType(InkWell), pointer: 1);
      await tester.pump(const Duration(seconds: 1));
      expect(feedback.clickSoundCount, 2);
      expect(feedback.hapticCount, 1);
    });

    testWidgets('disabled', (WidgetTester tester) async {
1084 1085
      await tester.pumpWidget(Material(
        child: Directionality(
1086
          textDirection: TextDirection.ltr,
1087 1088
          child: Center(
            child: InkWell(
1089 1090
              onTap: () { },
              onLongPress: () { },
1091 1092
              enableFeedback: false,
            ),
1093
          ),
1094
        ),
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
      ));
      await tester.tap(find.byType(InkWell), pointer: 1);
      await tester.pump(const Duration(seconds: 1));
      expect(feedback.clickSoundCount, 0);
      expect(feedback.hapticCount, 0);

      await tester.longPress(find.byType(InkWell), pointer: 1);
      await tester.pump(const Duration(seconds: 1));
      expect(feedback.clickSoundCount, 0);
      expect(feedback.hapticCount, 0);
    });
  });
1107 1108

  testWidgets('splashing survives scrolling when keep-alive is enabled', (WidgetTester tester) async {
1109
    Future<void> runTest(bool keepAlive) async {
1110
      await tester.pumpWidget(
1111
        Directionality(
1112
          textDirection: TextDirection.ltr,
1113
          child: Material(
1114 1115
            child: CompositedTransformFollower(
              // forces a layer, which makes the paints easier to separate out
1116 1117
              link: LayerLink(),
              child: ListView(
1118
                addAutomaticKeepAlives: keepAlive,
1119
                dragStartBehavior: DragStartBehavior.down,
1120
                children: <Widget>[
1121 1122 1123
                  SizedBox(height: 500.0, child: InkWell(onTap: () {}, child: const Placeholder())),
                  const SizedBox(height: 500.0),
                  const SizedBox(height: 500.0),
1124 1125 1126
                ],
              ),
            ),
1127 1128
          ),
        ),
1129
      );
1130
      expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child, isNot(paints..circle()));
1131 1132 1133
      await tester.tap(find.byType(InkWell));
      await tester.pump();
      await tester.pump(const Duration(milliseconds: 10));
1134
      expect(tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child, paints..circle());
1135 1136 1137 1138 1139
      await tester.drag(find.byType(ListView), const Offset(0.0, -1000.0));
      await tester.pump(const Duration(milliseconds: 10));
      await tester.drag(find.byType(ListView), const Offset(0.0, 1000.0));
      await tester.pump(const Duration(milliseconds: 10));
      expect(
1140
        tester.renderObject<RenderProxyBox>(find.byType(PhysicalModel)).child,
1141
        keepAlive ? (paints..circle()) : isNot(paints..circle()),
1142 1143
      );
    }
1144

1145 1146 1147
    await runTest(true);
    await runTest(false);
  });
1148 1149

  testWidgets('excludeFromSemantics', (WidgetTester tester) async {
1150
    final SemanticsTester semantics = SemanticsTester(tester);
1151

1152
    await tester.pumpWidget(Directionality(
1153
      textDirection: TextDirection.ltr,
1154 1155
      child: Material(
        child: InkWell(
1156
          onTap: () { },
1157 1158 1159 1160 1161 1162
          child: const Text('Button'),
        ),
      ),
    ));
    expect(semantics, includesNodeWith(label: 'Button', actions: <SemanticsAction>[SemanticsAction.tap]));

1163
    await tester.pumpWidget(Directionality(
1164
      textDirection: TextDirection.ltr,
1165 1166
      child: Material(
        child: InkWell(
1167
          onTap: () { },
1168
          excludeFromSemantics: true,
1169
          child: const Text('Button'),
1170 1171 1172 1173 1174 1175 1176
        ),
      ),
    ));
    expect(semantics, isNot(includesNodeWith(label: 'Button', actions: <SemanticsAction>[SemanticsAction.tap])));

    semantics.dispose();
  });
1177

1178
  testWidgets("ink response doesn't focus when disabled", (WidgetTester tester) async {
1179
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    final GlobalKey childKey = GlobalKey();
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: InkWell(
            autofocus: true,
            onTap: () {},
            onLongPress: () {},
            onHover: (bool hover) {},
            focusNode: focusNode,
            child: Container(key: childKey),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    expect(focusNode.hasPrimaryFocus, isTrue);
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: InkWell(
            focusNode: focusNode,
            child: Container(key: childKey),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    expect(focusNode.hasPrimaryFocus, isFalse);
  });

1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
  testWidgets('ink response accepts focus when disabled in directional navigation mode', (WidgetTester tester) async {
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    final GlobalKey childKey = GlobalKey();
    await tester.pumpWidget(
      Material(
        child: MediaQuery(
          data: const MediaQueryData(
            navigationMode: NavigationMode.directional,
          ),
          child: Directionality(
            textDirection: TextDirection.ltr,
            child: InkWell(
              autofocus: true,
              onTap: () {},
              onLongPress: () {},
              onHover: (bool hover) {},
              focusNode: focusNode,
              child: Container(key: childKey),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    expect(focusNode.hasPrimaryFocus, isTrue);
    await tester.pumpWidget(
      Material(
        child: MediaQuery(
          data: const MediaQueryData(
            navigationMode: NavigationMode.directional,
          ),
          child: Directionality(
            textDirection: TextDirection.ltr,
            child: InkWell(
              focusNode: focusNode,
              child: Container(key: childKey),
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    expect(focusNode.hasPrimaryFocus, isTrue);
  });

1260
  testWidgets("ink response doesn't hover when disabled", (WidgetTester tester) async {
1261
    FocusManager.instance.highlightStrategy = FocusHighlightStrategy.alwaysTouch;
1262 1263 1264 1265 1266 1267 1268
    final FocusNode focusNode = FocusNode(debugLabel: 'Ink Focus');
    final GlobalKey childKey = GlobalKey();
    bool hovering = false;
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
1269
          child: SizedBox(
1270 1271 1272 1273 1274 1275 1276 1277
            width: 100,
            height: 100,
            child: InkWell(
              autofocus: true,
              onTap: () {},
              onLongPress: () {},
              onHover: (bool value) { hovering = value; },
              focusNode: focusNode,
1278
              child: SizedBox(key: childKey),
1279 1280 1281 1282 1283 1284 1285 1286
            ),
          ),
        ),
      ),
    );
    await tester.pumpAndSettle();
    expect(focusNode.hasPrimaryFocus, isTrue);
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
1287
    await gesture.addPointer();
1288 1289 1290 1291 1292 1293 1294 1295
    await gesture.moveTo(tester.getCenter(find.byKey(childKey)));
    await tester.pumpAndSettle();
    expect(hovering, isTrue);

    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
1296
          child: SizedBox(
1297 1298 1299 1300 1301
            width: 100,
            height: 100,
            child: InkWell(
              focusNode: focusNode,
              onHover: (bool value) { hovering = value; },
1302
              child: SizedBox(key: childKey),
1303 1304 1305 1306 1307 1308 1309 1310 1311
            ),
          ),
        ),
      ),
    );

    await tester.pumpAndSettle();
    expect(focusNode.hasPrimaryFocus, isFalse);
  });
1312 1313 1314 1315

  testWidgets('When ink wells are nested, only the inner one is triggered by tap splash', (WidgetTester tester) async {
    final GlobalKey middleKey = GlobalKey();
    final GlobalKey innerKey = GlobalKey();
1316
    Widget paddedInkWell({Key? key, Widget? child}) {
1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
      return InkWell(
        key: key,
        onTap: () {},
        child: Padding(
          padding: const EdgeInsets.all(50),
          child: child,
        ),
      );
    }

    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: paddedInkWell(
              child: paddedInkWell(
                key: middleKey,
                child: paddedInkWell(
                  key: innerKey,
1337
                  child: const SizedBox(width: 50, height: 50),
1338 1339 1340 1341 1342 1343 1344
                ),
              ),
            ),
          ),
        ),
      ),
    );
1345
    final MaterialInkController material = Material.of(tester.element(find.byKey(innerKey)));
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381

    // Press
    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(innerKey)), pointer: 1);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Up
    await gesture.up();
    await tester.pumpAndSettle();
    expect(material, paintsNothing);

    // Press again
    await gesture.down(tester.getCenter(find.byKey(innerKey)));
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Cancel
    await gesture.cancel();
    await tester.pumpAndSettle();
    expect(material, paintsNothing);

    // Press again
    await gesture.down(tester.getCenter(find.byKey(innerKey)));
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Use a second pointer to press
    final TestGesture gesture2 = await tester.startGesture(tester.getCenter(find.byKey(innerKey)), pointer: 2);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));
    await gesture2.up();
  });

  testWidgets('Reparenting parent should allow both inkwells to show splash afterwards', (WidgetTester tester) async {
    final GlobalKey middleKey = GlobalKey();
    final GlobalKey innerKey = GlobalKey();
1382
    Widget paddedInkWell({Key? key, Widget? child}) {
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
      return InkWell(
        key: key,
        onTap: () {},
        child: Padding(
          padding: const EdgeInsets.all(50),
          child: child,
        ),
      );
    }

    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
1399
            child: SizedBox(
1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
              width: 200,
              height: 100,
              child: Row(
                children: <Widget>[
                  paddedInkWell(
                    key: middleKey,
                    child: paddedInkWell(
                      key: innerKey,
                    ),
                  ),
1410
                  const SizedBox(),
1411 1412 1413 1414 1415 1416 1417
                ],
              ),
            ),
          ),
        ),
      ),
    );
1418
    final MaterialInkController material = Material.of(tester.element(find.byKey(innerKey)));
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431

    // Press
    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(innerKey)), pointer: 1);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Reparent parent
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
1432
            child: SizedBox(
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469
              width: 200,
              height: 100,
              child: Row(
                children: <Widget>[
                  paddedInkWell(
                    key: innerKey,
                  ),
                  paddedInkWell(
                    key: middleKey,
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );

    // Up
    await gesture.up();
    await tester.pumpAndSettle();
    expect(material, paintsNothing);

    // Press the previous parent
    await gesture.down(tester.getCenter(find.byKey(middleKey)));
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Use a second pointer to press the previous child
    await tester.startGesture(tester.getCenter(find.byKey(innerKey)), pointer: 2);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 2));
  });

  testWidgets('Parent inkwell does not block child inkwells from splashes', (WidgetTester tester) async {
    final GlobalKey middleKey = GlobalKey();
    final GlobalKey innerKey = GlobalKey();
1470
    Widget paddedInkWell({Key? key, Widget? child}) {
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
      return InkWell(
        key: key,
        onTap: () {},
        child: Padding(
          padding: const EdgeInsets.all(50),
          child: child,
        ),
      );
    }

    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: paddedInkWell(
              child: paddedInkWell(
                key: middleKey,
                child: paddedInkWell(
                  key: innerKey,
1491
                  child: const SizedBox(width: 50, height: 50),
1492 1493 1494 1495 1496 1497 1498
                ),
              ),
            ),
          ),
        ),
      ),
    );
1499
    final MaterialInkController material = Material.of(tester.element(find.byKey(innerKey)));
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520

    // Press middle
    await tester.startGesture(tester.getTopLeft(find.byKey(middleKey)) + const Offset(1, 1), pointer: 1);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Press inner
    await tester.startGesture(tester.getCenter(find.byKey(innerKey)), pointer: 2);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 2));
  });

  testWidgets('Parent inkwell can count the number of pressed children to prevent splash', (WidgetTester tester) async {
    final GlobalKey parentKey = GlobalKey();
    final GlobalKey leftKey = GlobalKey();
    final GlobalKey rightKey = GlobalKey();
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
1521
            child: SizedBox(
1522 1523 1524 1525 1526 1527
              width: 100,
              height: 100,
              child: InkWell(
                key: parentKey,
                onTap: () {},
                child: Center(
1528
                  child: SizedBox(
1529 1530 1531 1532
                    width: 100,
                    height: 50,
                    child: Row(
                      children: <Widget>[
1533
                        SizedBox(
1534 1535 1536 1537 1538 1539 1540
                          width: 50,
                          height: 50,
                          child: InkWell(
                            key: leftKey,
                            onTap: () {},
                          ),
                        ),
1541
                        SizedBox(
1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
                          width: 50,
                          height: 50,
                          child: InkWell(
                            key: rightKey,
                            onTap: () {},
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
1559
    final MaterialInkController material = Material.of(tester.element(find.byKey(leftKey)));
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601

    final Offset parentPosition = tester.getTopLeft(find.byKey(parentKey)) + const Offset(1, 1);

    // Press left child
    final TestGesture gesture1 = await tester.startGesture(tester.getCenter(find.byKey(leftKey)), pointer: 1);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Press right child
    final TestGesture gesture2 = await tester.startGesture(tester.getCenter(find.byKey(rightKey)), pointer: 2);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 2));

    // Press parent
    final TestGesture gesture3 = await tester.startGesture(parentPosition, pointer: 3);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 2));
    await gesture3.up();

    // Release left child
    await gesture1.up();
    await tester.pumpAndSettle();
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Press parent
    await gesture3.down(parentPosition);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));
    await gesture3.up();

    // Release right child
    await gesture2.up();
    await tester.pumpAndSettle();
    expect(material, paintsExactlyCountTimes(#drawCircle, 0));

    // Press parent
    await gesture3.down(parentPosition);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));
    await gesture3.up();
  });

1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650
  testWidgets('When ink wells are reparented, the old parent can display splash while the new parent can not', (WidgetTester tester) async {
    final GlobalKey innerKey = GlobalKey();
    final GlobalKey leftKey = GlobalKey();
    final GlobalKey rightKey = GlobalKey();

    Widget doubleInkWellRow({
      required double leftWidth,
      required double rightWidth,
      Widget? leftChild,
      Widget? rightChild,
    }) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Align(
            alignment: Alignment.topLeft,
            child: SizedBox(
              width: leftWidth+rightWidth,
              height: 100,
              child: Row(
                children: <Widget>[
                  SizedBox(
                    width: leftWidth,
                    height: 100,
                    child: InkWell(
                      key: leftKey,
                      onTap: () {},
                      child: Center(
                        child: SizedBox(
                          width: leftWidth,
                          height: 50,
                          child: leftChild,
                        ),
                      ),
                    ),
                  ),
                  SizedBox(
                    width: rightWidth,
                    height: 100,
                    child: InkWell(
                      key: rightKey,
                      onTap: () {},
                      child: Center(
                        child: SizedBox(
                          width: leftWidth,
                          height: 50,
                          child: rightChild,
                        ),
                      ),
1651
                    ),
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
                  ),
                ],
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(
      doubleInkWellRow(
        leftWidth: 110,
        rightWidth: 90,
        leftChild: InkWell(
          key: innerKey,
          onTap: () {},
        ),
      ),
    );
1671
    final MaterialInkController material = Material.of(tester.element(find.byKey(innerKey)));
1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713

    // Press inner
    final TestGesture gesture = await tester.startGesture(const Offset(100, 50), pointer: 1);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Switch side
    await tester.pumpWidget(
      doubleInkWellRow(
        leftWidth: 90,
        rightWidth: 110,
        rightChild: InkWell(
          key: innerKey,
          onTap: () {},
        ),
      ),
    );
    expect(material, paintsExactlyCountTimes(#drawCircle, 0));

    // A second pointer presses inner
    final TestGesture gesture2 = await tester.startGesture(const Offset(100, 50), pointer: 2);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    await gesture.up();
    await gesture2.up();
    await tester.pumpAndSettle();

    // Press inner
    await gesture.down(const Offset(100, 50));
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Press left
    await gesture2.down(const Offset(50, 50));
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 2));

    await gesture.up();
    await gesture2.up();
  });

1714 1715 1716 1717 1718 1719 1720 1721 1722
  testWidgets("Ink wells's splash starts before tap is confirmed and disappear after tap is canceled", (WidgetTester tester) async {
    final GlobalKey innerKey = GlobalKey();
    await tester.pumpWidget(
      Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: GestureDetector(
            onHorizontalDragStart: (_) {},
            child: Center(
1723
              child: SizedBox(
1724 1725 1726 1727 1728
                width: 100,
                height: 100,
                child: InkWell(
                  onTap: () {},
                  child: Center(
1729
                    child: SizedBox(
1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744
                      width: 50,
                      height: 50,
                      child: InkWell(
                        key: innerKey,
                        onTap: () {},
                      ),
                    ),
                  ),
                ),
              ),
            ),
          ),
        ),
      ),
    );
1745
    final MaterialInkController material = Material.of(tester.element(find.byKey(innerKey)));
1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766

    // Press
    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byKey(innerKey)), pointer: 1);
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));

    // Scroll upward
    await gesture.moveBy(const Offset(0, -100));
    await tester.pumpAndSettle();
    expect(material, paintsNothing);

    // Up
    await gesture.up();
    await tester.pumpAndSettle();
    expect(material, paintsNothing);

    // Press again
    await gesture.down(tester.getCenter(find.byKey(innerKey)));
    await tester.pump(const Duration(milliseconds: 200));
    expect(material, paintsExactlyCountTimes(#drawCircle, 1));
  });
1767 1768 1769

  testWidgets('disabled and hovered inkwell responds to mouse-exit', (WidgetTester tester) async {
    int onHoverCount = 0;
1770
    late bool hover;
1771

1772
    Widget buildFrame({ required bool enabled }) {
1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: InkWell(
                onTap: enabled ? () { } : null,
                onHover: (bool value) {
                  onHoverCount += 1;
                  hover = value;
                },
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildFrame(enabled: true));
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();

    await gesture.moveTo(tester.getCenter(find.byType(InkWell)));
    await tester.pumpAndSettle();
    expect(onHoverCount, 1);
    expect(hover, true);

    await tester.pumpWidget(buildFrame(enabled: false));
    await tester.pumpAndSettle();
    await gesture.moveTo(Offset.zero);
    // Even though the InkWell has been disabled, the mouse-exit still
    // causes onHover(false) to be called.
    expect(onHoverCount, 2);
    expect(hover, false);

    await gesture.moveTo(tester.getCenter(find.byType(InkWell)));
    await tester.pumpAndSettle();
    // We no longer see hover events because the InkWell is disabled
    // and it's no longer in the "hovering" state.
    expect(onHoverCount, 2);
    expect(hover, false);

    await tester.pumpWidget(buildFrame(enabled: true));
    await tester.pumpAndSettle();
    // The InkWell was enabled while it contained the mouse, however
    // we do not call onHover() because it may call setState().
    expect(onHoverCount, 2);
    expect(hover, false);

    await gesture.moveTo(tester.getCenter(find.byType(InkWell)) - const Offset(1, 1));
    await tester.pumpAndSettle();
    // Moving the mouse a little within the InkWell doesn't change anything.
    expect(onHoverCount, 2);
    expect(hover, false);
  });

1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
  testWidgets('hovered ink well draws a transparent highlight when disabled', (WidgetTester tester) async {
    Widget buildFrame({ required bool enabled }) {
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: SizedBox(
              width: 100,
              height: 100,
              child: InkWell(
                onTap: enabled ? () { } : null,
                onHover: (bool value) { },
                hoverColor: const Color(0xff00ff00),
              ),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildFrame(enabled: true));
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();

    // Hover the enabled InkWell.
    await gesture.moveTo(tester.getCenter(find.byType(InkWell)));
    await tester.pumpAndSettle();
    expect(
      find.byType(Material),
      paints
        ..rect(
            color: const Color(0xff00ff00),
            rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
          )
    );

    // Disable the hovered InkWell.
    await tester.pumpWidget(buildFrame(enabled: false));
    await tester.pumpAndSettle();
    expect(
      find.byType(Material),
      paints
        ..rect(
            color: const Color(0x0000ff00),
            rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0),
          )
    );
  });


1881
  testWidgets('Changing InkWell.enabled should not trigger TextButton setState()', (WidgetTester tester) async {
1882
    Widget buildFrame({ required bool enabled }) {
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913
      return Material(
        child: Directionality(
          textDirection: TextDirection.ltr,
          child: Center(
            child: TextButton(
              onPressed: enabled ? () { } : null,
              child: const Text('button'),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildFrame(enabled: false));

    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
    await gesture.moveTo(tester.getCenter(find.byType(TextButton)));
    await tester.pumpAndSettle();

    // Rebuilding the button with enabled:true causes InkWell.didUpdateWidget()
    // to be called per the change in its enabled flag. If onHover() was called,
    // this test would crash.
    await tester.pumpWidget(buildFrame(enabled: true));
    await tester.pumpAndSettle();

    // Rebuild again, with enabled:false
    await gesture.moveBy(const Offset(1, 1));
    await tester.pumpWidget(buildFrame(enabled: false));
    await tester.pumpAndSettle();
  });
1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956

  testWidgets('InkWell does not attach semantics handler for onTap if it was not provided an onTap handler', (WidgetTester tester) async {
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onLongPress: () { },
            child: const Text('Foo'),
          ),
        ),
      ),
    ));

    expect(tester.getSemantics(find.bySemanticsLabel('Foo')), matchesSemantics(
      label: 'Foo',
      hasLongPressAction: true,
      isFocusable: true,
      textDirection: TextDirection.ltr,
    ));

    // Add tap handler and confirm addition to semantic actions.
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onLongPress: () { },
            onTap: () { },
            child: const Text('Foo'),
          ),
        ),
      ),
    ));

    expect(tester.getSemantics(find.bySemanticsLabel('Foo')), matchesSemantics(
      label: 'Foo',
      hasTapAction: true,
      hasLongPressAction: true,
      isFocusable: true,
      textDirection: TextDirection.ltr,
    ));
  });
1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042

  testWidgets('InkWell highlight should not survive after [onTapDown, onDoubleTap] sequence', (WidgetTester tester) async {
    final List<String> log = <String>[];

    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onTap: () {
              log.add('tap');
            },
            onDoubleTap: () {
              log.add('double-tap');
            },
            onTapDown: (TapDownDetails details) {
              log.add('tap-down');
            },
            onTapCancel: () {
              log.add('tap-cancel');
            },
          ),
        ),
      ),
    ));

    final Offset taplocation = tester.getRect(find.byType(InkWell)).center;

    final TestGesture gesture = await tester.startGesture(taplocation);
    await tester.pump(const Duration(milliseconds: 100));
    expect(log, equals(<String>['tap-down']));
    await gesture.up();
    await tester.pump(const Duration(milliseconds: 100));
    await tester.tap(find.byType(InkWell));
    await tester.pump(const Duration(milliseconds: 100));
    expect(log, equals(<String>['tap-down', 'double-tap']));

    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawRect, 0));
  });

  testWidgets('InkWell splash should not survive after [onTapDown, onTapDown, onTapCancel, onDoubleTap] sequence', (WidgetTester tester) async {
    final List<String> log = <String>[];

    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onTap: () {
              log.add('tap');
            },
            onDoubleTap: () {
              log.add('double-tap');
            },
            onTapDown: (TapDownDetails details) {
              log.add('tap-down');
            },
            onTapCancel: () {
              log.add('tap-cancel');
            },
          ),
        ),
      ),
    ));

    final Offset tapLocation = tester.getRect(find.byType(InkWell)).center;

    final TestGesture gesture1 = await tester.startGesture(tapLocation);
    await tester.pump(const Duration(milliseconds: 100));
    expect(log, equals(<String>['tap-down']));
    await gesture1.up();
    await tester.pump(const Duration(milliseconds: 100));

    final TestGesture gesture2 = await tester.startGesture(tapLocation);
    await tester.pump(const Duration(milliseconds: 100));
    expect(log, equals(<String>['tap-down', 'tap-down']));
    await gesture2.up();
    await tester.pump(const Duration(milliseconds: 100));
    expect(log, equals(<String>['tap-down', 'tap-down', 'tap-cancel', 'double-tap']));

    await tester.pumpAndSettle();
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));
  });
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085

  testWidgets('InkWell dispose statesController', (WidgetTester tester) async {
    int tapCount = 0;
    Widget buildFrame(MaterialStatesController? statesController) {
      return MaterialApp(
        home: Scaffold(
          body: Center(
            child: InkWell(
              statesController: statesController,
              onTap: () { tapCount += 1; },
              child: const Text('inkwell'),
            ),
          ),
        ),
      );
    }

    final MaterialStatesController controller = MaterialStatesController();
    int pressedCount = 0;
    controller.addListener(() {
      if (controller.value.contains(MaterialState.pressed)) {
        pressedCount += 1;
      }
    });

    await tester.pumpWidget(buildFrame(controller));
    await tester.tap(find.byType(InkWell));
    await tester.pumpAndSettle();
    expect(tapCount, 1);
    expect(pressedCount, 1);

    await tester.pumpWidget(buildFrame(null));
    await tester.tap(find.byType(InkWell));
    await tester.pumpAndSettle();
    expect(tapCount, 2);
    expect(pressedCount, 1);

    await tester.pumpWidget(buildFrame(controller));
    await tester.tap(find.byType(InkWell));
    await tester.pumpAndSettle();
    expect(tapCount, 3);
    expect(pressedCount, 2);
  });
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123

  testWidgets('ink well overlayColor opacity fades from 0xff when hover ends', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/110266
    await tester.pumpWidget(Material(
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: Center(
          child: SizedBox(
            width: 100,
            height: 100,
            child: InkWell(
              overlayColor: MaterialStateProperty.resolveWith<Color?>((Set<MaterialState> states) {
                if (states.contains(MaterialState.hovered)) {
                  return const Color(0xff00ff00);
                }
                return null;
              }),
              onTap: () { },
              onLongPress: () { },
              onHover: (bool hover) { },
            ),
          ),
        ),
      ),
    ));
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
    await gesture.moveTo(tester.getCenter(find.byType(SizedBox)));
    await tester.pumpAndSettle();
    await gesture.moveTo(const Offset(10, 10)); // fade out the overlay
    await tester.pump(); // trigger the fade out animation
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    // Fadeout begins with the MaterialStates.hovered overlay color
    expect(inkFeatures, paints..rect(rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), color: const Color(0xff00ff00)));
    // 50ms fadeout is 50% complete, overlay color alpha goes from 0xff to 0x80
    await tester.pump(const Duration(milliseconds: 25));
    expect(inkFeatures, paints..rect(rect: const Rect.fromLTRB(350.0, 250.0, 450.0, 350.0), color: const Color(0x8000ff00)));
  });
2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160

  testWidgets('InkWell secondary tap test', (WidgetTester tester) async {
    final List<String> log = <String>[];

    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onSecondaryTap: () {
              log.add('secondary-tap');
            },
            onSecondaryTapDown: (TapDownDetails details) {
              log.add('secondary-tap-down');
            },
            onSecondaryTapUp: (TapUpDetails details) {
              log.add('secondary-tap-up');
            },
            onSecondaryTapCancel: () {
              log.add('secondary-tap-cancel');
            },
          ),
        ),
      ),
    ));

    await tester.tap(find.byType(InkWell), pointer: 1, buttons: kSecondaryButton);

    expect(log, equals(<String>['secondary-tap-down', 'secondary-tap-up', 'secondary-tap']));
    log.clear();

    final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(InkWell)), pointer: 2, buttons: kSecondaryButton);
    await gesture.moveTo(const Offset(100, 100));
    await gesture.up();

    expect(log, equals(<String>['secondary-tap-down', 'secondary-tap-cancel']));
  });
2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186

  // Regression test for https://github.com/flutter/flutter/issues/124328.
  testWidgets('InkWell secondary tap should not draw a splash when no secondary callbacks are defined', (WidgetTester tester) async {
    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: Material(
        child: Center(
          child: InkWell(
            onTap: () {},
          ),
        ),
      ),
    ));

    final TestGesture gesture = await tester.startGesture(
      tester.getRect(find.byType(InkWell)).center,
      buttons: kSecondaryButton,
    );
    await tester.pump(const Duration(milliseconds: 200));

    // No splash should be painted.
    final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
    expect(inkFeatures, paintsExactlyCountTimes(#drawCircle, 0));

    await gesture.up();
  });
2187
}