chip_test.dart 87.3 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 6
import 'dart:ui' show window;

7 8
import 'package:flutter/gestures.dart';
import 'package:flutter/rendering.dart';
9
import 'package:flutter/semantics.dart';
10
import 'package:flutter_test/flutter_test.dart';
11 12
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
13

14
import '../rendering/mock_canvas.dart';
15
import '../widgets/semantics_tester.dart';
16 17
import 'feedback_tester.dart';

18 19 20
Finder findRenderChipElement() {
  return find.byElementPredicate((Element e) => '${e.runtimeType}' == '_RenderChipElement');
}
21

22 23 24 25 26 27 28 29 30
RenderBox getMaterialBox(WidgetTester tester) {
  return tester.firstRenderObject<RenderBox>(
    find.descendant(
      of: find.byType(RawChip),
      matching: find.byType(CustomPaint),
    ),
  );
}

31 32 33 34 35 36 37 38 39
Material getMaterial(WidgetTester tester) {
  return tester.widget<Material>(
    find.descendant(
      of: find.byType(RawChip),
      matching: find.byType(Material),
    ),
  );
}

40 41 42 43 44 45 46 47 48 49 50 51
IconThemeData getIconData(WidgetTester tester) {
  final IconTheme iconTheme = tester.firstWidget(
    find.descendant(
      of: find.byType(RawChip),
      matching: find.byType(IconTheme),
    ),
  );
  return iconTheme.data;
}

DefaultTextStyle getLabelStyle(WidgetTester tester) {
  return tester.widget(
52
    find.descendant(
53 54
      of: find.byType(RawChip),
      matching: find.byType(DefaultTextStyle),
55
    ).last,
56 57 58
  );
}

59 60 61 62 63 64 65 66
dynamic getRenderChip(WidgetTester tester) {
  if (!tester.any(findRenderChipElement())) {
    return null;
  }
  final Element element = tester.element(findRenderChipElement());
  return element.renderObject;
}

67 68 69 70
double getSelectProgress(WidgetTester tester) => getRenderChip(tester)?.checkmarkAnimation?.value as double;
double getAvatarDrawerProgress(WidgetTester tester) => getRenderChip(tester)?.avatarDrawerAnimation?.value as double;
double getDeleteDrawerProgress(WidgetTester tester) => getRenderChip(tester)?.deleteDrawerAnimation?.value as double;
double getEnableProgress(WidgetTester tester) => getRenderChip(tester)?.enableAnimation?.value as double;
71

72 73 74
/// Adds the basic requirements for a Chip.
Widget _wrapForChip({
  Widget child,
75 76
  TextDirection textDirection = TextDirection.ltr,
  double textScaleFactor = 1.0,
77
  Brightness brightness = Brightness.light,
78
}) {
79
  return MaterialApp(
80
    theme: ThemeData(brightness: brightness),
81
    home: Directionality(
82
      textDirection: textDirection,
83 84 85
      child: MediaQuery(
        data: MediaQueryData.fromWindow(window).copyWith(textScaleFactor: textScaleFactor),
        child: Material(child: child),
86 87 88 89 90
      ),
    ),
  );
}

91 92 93 94
/// Tests that a [Chip] that has its size constrained by its parent is
/// further constraining the size of its child, the label widget.
/// Optionally, adding an avatar or delete icon to the chip should not
/// cause the chip or label to exceed its constrained height.
95
Future<void> _testConstrainedLabel(
96 97 98 99 100 101 102 103
  WidgetTester tester, {
  CircleAvatar avatar,
  VoidCallback onDeleted,
}) async {
  const double labelWidth = 100.0;
  const double labelHeight = 50.0;
  const double chipParentWidth = 75.0;
  const double chipParentHeight = 25.0;
104
  final Key labelKey = UniqueKey();
105 106

  await tester.pumpWidget(
107
    _wrapForChip(
108 109
      child: Center(
        child: Container(
110 111
          width: chipParentWidth,
          height: chipParentHeight,
112
          child: Chip(
113
            avatar: avatar,
114
            label: Container(
115 116 117
              key: labelKey,
              width: labelWidth,
              height: labelHeight,
118
            ),
119
            onDeleted: onDeleted,
120 121 122
          ),
        ),
      ),
123 124
    ),
  );
125

126 127 128
  final Size labelSize = tester.getSize(find.byKey(labelKey));
  expect(labelSize.width, lessThan(chipParentWidth));
  expect(labelSize.height, lessThanOrEqualTo(chipParentHeight));
129

130 131 132 133
  final Size chipSize = tester.getSize(find.byType(Chip));
  expect(chipSize.width, chipParentWidth);
  expect(chipSize.height, chipParentHeight);
}
134

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
Widget _selectedInputChip({ Color checkmarkColor }) {
  return InputChip(
    label: const Text('InputChip'),
    selected: true,
    showCheckmark: true,
    checkmarkColor: checkmarkColor,
  );
}

Widget _selectedFilterChip({ Color checkmarkColor }) {
  return FilterChip(
    label: const Text('InputChip'),
    selected: true,
    showCheckmark: true,
    checkmarkColor: checkmarkColor,
    onSelected: (bool _) { },
  );
}

Future<void> _pumpCheckmarkChip(
  WidgetTester tester, {
  @required Widget chip,
  Color themeColor,
  Brightness brightness = Brightness.light,
}) async {
  await tester.pumpWidget(
    _wrapForChip(
      brightness: brightness,
      child: Builder(
        builder: (BuildContext context) {
          final ChipThemeData chipTheme = ChipTheme.of(context);
          return ChipTheme(
            data: themeColor == null ? chipTheme : chipTheme.copyWith(
              checkmarkColor: themeColor,
            ),
            child: chip,
          );
        },
173
      ),
174
    ),
175 176 177 178 179 180
  );
}

void _expectCheckmarkColor(Finder finder, Color color) {
  expect(
    finder,
181 182 183 184 185 186 187
    paints
      // The first path that is painted is the selection overlay. We do not care
      // how it is painted but it has to be added it to this pattern so that the
      // check mark can be checked next.
      ..path()
      // The second path that is painted is the check mark.
      ..path(color: color),
188 189 190
  );
}

191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
Widget _chipWithOptionalDeleteButton({
  UniqueKey deleteButtonKey,
  UniqueKey labelKey,
  bool deletable,
  TextDirection textDirection = TextDirection.ltr,
}){
  return _wrapForChip(
    textDirection: textDirection,
    child: Wrap(
      children: <Widget>[
        RawChip(
          onPressed: () {},
          onDeleted: deletable ? () {} : null,
          deleteIcon: Icon(Icons.close, key: deleteButtonKey),
          label: Text(
            deletable
              ? 'Chip with Delete Button'
              : 'Chip without Delete Button',
            key: labelKey,
          ),
        ),
      ],
    ),
  );
}

bool offsetsAreClose(Offset a, Offset b) => (a - b).distance < 1.0;
bool radiiAreClose(double a, double b) => (a - b).abs() < 1.0;

// Ripple pattern matches if there exists at least one ripple
// with the [expectedCenter] and [expectedRadius].
// This ensures the existence of a ripple.
PaintPattern ripplePattern(Offset expectedCenter, double expectedRadius) {
  return paints
    ..something((Symbol method, List<dynamic> arguments) {
        if (method != #drawCircle)
          return false;
228 229
        final Offset center = arguments[0] as Offset;
        final double radius = arguments[1] as double;
230 231 232 233 234 235 236 237 238 239 240 241 242
        return offsetsAreClose(center, expectedCenter) && radiiAreClose(radius, expectedRadius);
      }
    );
}

// Unique ripple pattern matches if there does not exist ripples
// other than ones with the [expectedCenter] and [expectedRadius].
// This ensures the nonexistence of two different ripples.
PaintPattern uniqueRipplePattern(Offset expectedCenter, double expectedRadius) {
  return paints
    ..everything((Symbol method, List<dynamic> arguments) {
        if (method != #drawCircle)
          return true;
243 244
        final Offset center = arguments[0] as Offset;
        final double radius = arguments[1] as double;
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261
        if (offsetsAreClose(center, expectedCenter) && radiiAreClose(radius, expectedRadius))
          return true;
        throw '''
              Expected: center == $expectedCenter, radius == $expectedRadius
              Found: center == $center radius == $radius''';
      }
    );
}

// Finds any container of a tooltip.
Finder findTooltipContainer(String tooltipText) {
  return find.ancestor(
    of: find.text(tooltipText),
    matching: find.byType(Container),
  );
}

262
void main() {
263
  testWidgets('Chip control test', (WidgetTester tester) async {
264
    final FeedbackTester feedback = FeedbackTester();
265
    final List<String> deletedChipLabels = <String>[];
266 267
    await tester.pumpWidget(
      _wrapForChip(
268
        child: Column(
269
          children: <Widget>[
270
            Chip(
271
              avatar: const CircleAvatar(child: Text('A')),
272 273 274 275 276 277
              label: const Text('Chip A'),
              onDeleted: () {
                deletedChipLabels.add('A');
              },
              deleteButtonTooltipMessage: 'Delete chip A',
            ),
278
            Chip(
279
              avatar: const CircleAvatar(child: Text('B')),
280 281 282 283 284 285 286 287
              label: const Text('Chip B'),
              onDeleted: () {
                deletedChipLabels.add('B');
              },
              deleteButtonTooltipMessage: 'Delete chip B',
            ),
          ],
        ),
288
      ),
289
    );
290

291 292 293
    expect(tester.widget(find.byTooltip('Delete chip A')), isNotNull);
    expect(tester.widget(find.byTooltip('Delete chip B')), isNotNull);

294 295
    expect(feedback.clickSoundCount, 0);

296 297 298
    expect(deletedChipLabels, isEmpty);
    await tester.tap(find.byTooltip('Delete chip A'));
    expect(deletedChipLabels, equals(<String>['A']));
299 300 301 302

    await tester.pumpAndSettle(const Duration(seconds: 1));
    expect(feedback.clickSoundCount, 1);

303 304 305 306 307 308
    await tester.tap(find.byTooltip('Delete chip B'));
    expect(deletedChipLabels, equals(<String>['A', 'B']));

    await tester.pumpAndSettle(const Duration(seconds: 1));
    expect(feedback.clickSoundCount, 2);

309
    feedback.dispose();
310
  });
311

312
  testWidgets(
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
    'Chip does not constrain size of label widget if it does not exceed '
    'the available space',
    (WidgetTester tester) async {
      const double labelWidth = 50.0;
      const double labelHeight = 30.0;
      final Key labelKey = UniqueKey();

      await tester.pumpWidget(
        _wrapForChip(
          child: Center(
            child: Container(
              width: 500.0,
              height: 500.0,
              child: Column(
                children: <Widget>[
                  Chip(
                    label: Container(
                      key: labelKey,
                      width: labelWidth,
                      height: labelHeight,
                    ),
334
                  ),
335 336
                ],
              ),
337 338 339
            ),
          ),
        ),
340
      );
341

342 343 344 345 346
      final Size labelSize = tester.getSize(find.byKey(labelKey));
      expect(labelSize.width, labelWidth);
      expect(labelSize.height, labelHeight);
    },
  );
347

348
  testWidgets(
349 350 351 352 353 354
    'Chip constrains the size of the label widget when it exceeds the '
    'available space',
    (WidgetTester tester) async {
      await _testConstrainedLabel(tester);
    },
  );
355

356
  testWidgets(
357 358 359 360 361 362 363 364 365
    'Chip constrains the size of the label widget when it exceeds the '
    'available space and the avatar is present',
    (WidgetTester tester) async {
      await _testConstrainedLabel(
        tester,
        avatar: const CircleAvatar(child: Text('A')),
      );
    },
  );
366

367
  testWidgets(
368 369 370 371 372 373 374 375 376
    'Chip constrains the size of the label widget when it exceeds the '
    'available space and the delete icon is present',
    (WidgetTester tester) async {
      await _testConstrainedLabel(
        tester,
        onDeleted: () { },
      );
    },
  );
377

378
  testWidgets(
379 380 381 382 383 384 385 386 387 388
    'Chip constrains the size of the label widget when it exceeds the '
    'available space and both avatar and delete icons are present',
    (WidgetTester tester) async {
      await _testConstrainedLabel(
        tester,
        avatar: const CircleAvatar(child: Text('A')),
        onDeleted: () { },
      );
    },
  );
389

390
  testWidgets(
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406
    'Chip constrains the avatar, label, and delete icons to the bounds of '
    'the chip when it exceeds the available space',
    (WidgetTester tester) async {
      // Regression test for https://github.com/flutter/flutter/issues/11523
      Widget chipBuilder (String text, {Widget avatar, VoidCallback onDeleted}) {
        return MaterialApp(
          home: Scaffold(
            body: Container(
              width: 150,
              child: Column(
                children: <Widget>[
                  Chip(
                    avatar: avatar,
                    label: Text(text),
                    onDeleted: onDeleted,
                  ),
407
                ],
408
              ),
409 410
            ),
          ),
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
        );
      }

      void chipRectContains(Rect chipRect, Rect rect) {
        expect(chipRect.contains(rect.topLeft), true);
        expect(chipRect.contains(rect.topRight), true);
        expect(chipRect.contains(rect.bottomLeft), true);
        expect(chipRect.contains(rect.bottomRight), true);
      }

      Rect chipRect;
      Rect avatarRect;
      Rect labelRect;
      Rect deleteIconRect;
      const String text = 'Very long text that will be clipped';

      await tester.pumpWidget(chipBuilder(text));

      chipRect = tester.getRect(find.byType(Chip));
      labelRect = tester.getRect(find.text(text));
      chipRectContains(chipRect, labelRect);

      await tester.pumpWidget(chipBuilder(
        text,
        avatar: const CircleAvatar(child: Text('A')),
      ));
      await tester.pumpAndSettle();

      chipRect = tester.getRect(find.byType(Chip));
      avatarRect = tester.getRect(find.byType(CircleAvatar));
      chipRectContains(chipRect, avatarRect);

      labelRect = tester.getRect(find.text(text));
      chipRectContains(chipRect, labelRect);

      await tester.pumpWidget(chipBuilder(
        text,
        avatar: const CircleAvatar(child: Text('A')),
        onDeleted: () {},
      ));
      await tester.pumpAndSettle();

      chipRect = tester.getRect(find.byType(Chip));
      avatarRect = tester.getRect(find.byType(CircleAvatar));
      chipRectContains(chipRect, avatarRect);

      labelRect = tester.getRect(find.text(text));
      chipRectContains(chipRect, labelRect);

      deleteIconRect = tester.getRect(find.byIcon(Icons.cancel));
      chipRectContains(chipRect, deleteIconRect);
    },
  );
464

465
  testWidgets('Chip in row works ok', (WidgetTester tester) async {
466
    const TextStyle style = TextStyle(fontFamily: 'Ahem', fontSize: 10.0);
467
    await tester.pumpWidget(
468
      _wrapForChip(
469
        child: Row(
470
          children: const <Widget>[
471
            Chip(label: Text('Test'), labelStyle: style),
472
          ],
473 474 475
        ),
      ),
    );
476
    expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0));
477
    expect(tester.getSize(find.byType(Chip)), const Size(64.0, 48.0));
478
    await tester.pumpWidget(
479
      _wrapForChip(
480
        child: Row(
481
          children: const <Widget>[
482
            Flexible(child: Chip(label: Text('Test'), labelStyle: style)),
483
          ],
484 485 486 487
        ),
      ),
    );
    expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0));
488
    expect(tester.getSize(find.byType(Chip)), const Size(64.0, 48.0));
489
    await tester.pumpWidget(
490
      _wrapForChip(
491
        child: Row(
492
          children: const <Widget>[
493
            Expanded(child: Chip(label: Text('Test'), labelStyle: style)),
494
          ],
495 496 497 498
        ),
      ),
    );
    expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0));
499
    expect(tester.getSize(find.byType(Chip)), const Size(800.0, 48.0));
500
  }, skip: isBrowser);
501

502
  testWidgets('Chip elements are ordered horizontally for locale', (WidgetTester tester) async {
503 504
    final UniqueKey iconKey = UniqueKey();
    final Widget test = Overlay(
505
      initialEntries: <OverlayEntry>[
506
        OverlayEntry(
507
          builder: (BuildContext context) {
508 509 510
            return Material(
              child: Chip(
                deleteIcon: Icon(Icons.delete, key: iconKey),
511
                onDeleted: () { },
512
                label: const Text('ABC'),
513 514 515 516 517 518 519 520
              ),
            );
          },
        ),
      ],
    );

    await tester.pumpWidget(
521 522 523
      _wrapForChip(
        child: test,
        textDirection: TextDirection.rtl,
524 525
      ),
    );
526 527
    await tester.pumpAndSettle(const Duration(milliseconds: 500));
    expect(tester.getCenter(find.text('ABC')).dx, greaterThan(tester.getCenter(find.byKey(iconKey)).dx));
528
    await tester.pumpWidget(
529 530 531
      _wrapForChip(
        textDirection: TextDirection.ltr,
        child: test,
532 533
      ),
    );
534 535
    await tester.pumpAndSettle(const Duration(milliseconds: 500));
    expect(tester.getCenter(find.text('ABC')).dx, lessThan(tester.getCenter(find.byKey(iconKey)).dx));
536 537
  });

538 539
  testWidgets('Chip responds to textScaleFactor', (WidgetTester tester) async {
    await tester.pumpWidget(
540
      _wrapForChip(
541
        child: Column(
542
          children: const <Widget>[
543 544 545
            Chip(
              avatar: CircleAvatar(child: Text('A')),
              label: Text('Chip A'),
546
            ),
547 548 549
            Chip(
              avatar: CircleAvatar(child: Text('B')),
              label: Text('Chip B'),
550 551
            ),
          ],
552 553 554 555 556 557 558 559
        ),
      ),
    );

    // TODO(gspencer): Update this test when the font metric bug is fixed to remove the anyOfs.
    // https://github.com/flutter/flutter/issues/12357
    expect(
      tester.getSize(find.text('Chip A')),
560
      anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)),
561 562 563
    );
    expect(
      tester.getSize(find.text('Chip B')),
564
      anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)),
565
    );
566 567
    expect(tester.getSize(find.byType(Chip).first), anyOf(const Size(132.0, 48.0), const Size(131.0, 48.0)));
    expect(tester.getSize(find.byType(Chip).last), anyOf(const Size(132.0, 48.0), const Size(131.0, 48.0)));
568 569

    await tester.pumpWidget(
570 571
      _wrapForChip(
        textScaleFactor: 3.0,
572
        child: Column(
573
          children: const <Widget>[
574 575 576
            Chip(
              avatar: CircleAvatar(child: Text('A')),
              label: Text('Chip A'),
577
            ),
578 579 580
            Chip(
              avatar: CircleAvatar(child: Text('B')),
              label: Text('Chip B'),
581 582
            ),
          ],
583 584 585 586 587 588
        ),
      ),
    );

    // TODO(gspencer): Update this test when the font metric bug is fixed to remove the anyOfs.
    // https://github.com/flutter/flutter/issues/12357
589 590
    expect(tester.getSize(find.text('Chip A')), anyOf(const Size(252.0, 42.0), const Size(251.0, 42.0)));
    expect(tester.getSize(find.text('Chip B')), anyOf(const Size(252.0, 42.0), const Size(251.0, 42.0)));
591 592 593 594
    expect(tester.getSize(find.byType(Chip).first).width, anyOf(318.0, 319.0));
    expect(tester.getSize(find.byType(Chip).first).height, equals(50.0));
    expect(tester.getSize(find.byType(Chip).last).width, anyOf(318.0, 319.0));
    expect(tester.getSize(find.byType(Chip).last).height, equals(50.0));
595 596 597

    // Check that individual text scales are taken into account.
    await tester.pumpWidget(
598
      _wrapForChip(
599
        child: Column(
600
          children: const <Widget>[
601 602 603
            Chip(
              avatar: CircleAvatar(child: Text('A')),
              label: Text('Chip A', textScaleFactor: 3.0),
604
            ),
605 606 607
            Chip(
              avatar: CircleAvatar(child: Text('B')),
              label: Text('Chip B'),
608 609
            ),
          ],
610 611 612 613 614 615
        ),
      ),
    );

    // TODO(gspencer): Update this test when the font metric bug is fixed to remove the anyOfs.
    // https://github.com/flutter/flutter/issues/12357
616 617
    expect(tester.getSize(find.text('Chip A')), anyOf(const Size(252.0, 42.0), const Size(251.0, 42.0)));
    expect(tester.getSize(find.text('Chip B')), anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)));
618 619
    expect(tester.getSize(find.byType(Chip).first).width, anyOf(318.0, 319.0));
    expect(tester.getSize(find.byType(Chip).first).height, equals(50.0));
620
    expect(tester.getSize(find.byType(Chip).last), anyOf(const Size(132.0, 48.0), const Size(131.0, 48.0)));
621
  }, skip: isBrowser);
622 623

  testWidgets('Labels can be non-text widgets', (WidgetTester tester) async {
624 625
    final Key keyA = GlobalKey();
    final Key keyB = GlobalKey();
626
    await tester.pumpWidget(
627
      _wrapForChip(
628
        child: Column(
629
          children: <Widget>[
630
            Chip(
631
              avatar: const CircleAvatar(child: Text('A')),
632
              label: Text('Chip A', key: keyA),
633
            ),
634
            Chip(
635
              avatar: const CircleAvatar(child: Text('B')),
636
              label: Container(key: keyB, width: 10.0, height: 10.0),
637 638
            ),
          ],
639 640 641 642 643 644 645 646
        ),
      ),
    );

    // TODO(gspencer): Update this test when the font metric bug is fixed to remove the anyOfs.
    // https://github.com/flutter/flutter/issues/12357
    expect(
      tester.getSize(find.byKey(keyA)),
647
      anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)),
648 649 650 651
    );
    expect(tester.getSize(find.byKey(keyB)), const Size(10.0, 10.0));
    expect(
      tester.getSize(find.byType(Chip).first),
652
      anyOf(const Size(132.0, 48.0), const Size(131.0, 48.0)),
653
    );
654
    expect(tester.getSize(find.byType(Chip).last), const Size(58.0, 48.0));
655
  }, skip: isBrowser);
656

657
  testWidgets('Avatars can be non-circle avatar widgets', (WidgetTester tester) async {
658
    final Key keyA = GlobalKey();
659
    await tester.pumpWidget(
660
      _wrapForChip(
661
        child: Column(
662
          children: <Widget>[
663 664
            Chip(
              avatar: Container(key: keyA, width: 20.0, height: 20.0),
665 666 667
              label: const Text('Chip A'),
            ),
          ],
668 669 670 671 672 673 674 675
        ),
      ),
    );

    expect(tester.getSize(find.byKey(keyA)), equals(const Size(20.0, 20.0)));
  });

  testWidgets('Delete icons can be non-icon widgets', (WidgetTester tester) async {
676
    final Key keyA = GlobalKey();
677
    await tester.pumpWidget(
678
      _wrapForChip(
679
        child: Column(
680
          children: <Widget>[
681 682
            Chip(
              deleteIcon: Container(key: keyA, width: 20.0, height: 20.0),
683
              label: const Text('Chip A'),
684
              onDeleted: () { },
685 686
            ),
          ],
687 688 689 690 691 692 693
        ),
      ),
    );

    expect(tester.getSize(find.byKey(keyA)), equals(const Size(20.0, 20.0)));
  });

694
  testWidgets('Chip padding - LTR', (WidgetTester tester) async {
695 696
    final GlobalKey keyA = GlobalKey();
    final GlobalKey keyB = GlobalKey();
697
    await tester.pumpWidget(
698 699
      _wrapForChip(
        textDirection: TextDirection.ltr,
700
        child: Overlay(
701
          initialEntries: <OverlayEntry>[
702
            OverlayEntry(
703
              builder: (BuildContext context) {
704 705 706 707 708
                return Material(
                  child: Center(
                    child: Chip(
                      avatar: Placeholder(key: keyA),
                      label: Container(
709 710 711
                        key: keyB,
                        width: 40.0,
                        height: 40.0,
712
                      ),
713
                      onDeleted: () { },
714
                    ),
715 716 717 718 719
                  ),
                );
              },
            ),
          ],
720 721 722
        ),
      ),
    );
723 724
    expect(tester.getTopLeft(find.byKey(keyA)), const Offset(332.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyA)), const Offset(372.0, 320.0));
725 726
    expect(tester.getTopLeft(find.byKey(keyB)), const Offset(380.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyB)), const Offset(420.0, 320.0));
727 728
    expect(tester.getTopLeft(find.byType(Icon)), const Offset(439.0, 291.0));
    expect(tester.getBottomRight(find.byType(Icon)), const Offset(457.0, 309.0));
729 730 731
  });

  testWidgets('Chip padding - RTL', (WidgetTester tester) async {
732 733
    final GlobalKey keyA = GlobalKey();
    final GlobalKey keyB = GlobalKey();
734
    await tester.pumpWidget(
735 736
      _wrapForChip(
        textDirection: TextDirection.rtl,
737
        child: Overlay(
738
          initialEntries: <OverlayEntry>[
739
            OverlayEntry(
740
              builder: (BuildContext context) {
741 742 743 744 745
                return Material(
                  child: Center(
                    child: Chip(
                      avatar: Placeholder(key: keyA),
                      label: Container(
746 747 748
                        key: keyB,
                        width: 40.0,
                        height: 40.0,
749
                      ),
750
                      onDeleted: () { },
751
                    ),
752 753 754 755 756
                  ),
                );
              },
            ),
          ],
757 758 759
        ),
      ),
    );
760

761 762
    expect(tester.getTopLeft(find.byKey(keyA)), const Offset(428.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyA)), const Offset(468.0, 320.0));
763 764
    expect(tester.getTopLeft(find.byKey(keyB)), const Offset(380.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyB)), const Offset(420.0, 320.0));
765 766 767 768 769
    expect(tester.getTopLeft(find.byType(Icon)), const Offset(343.0, 291.0));
    expect(tester.getBottomRight(find.byType(Icon)), const Offset(361.0, 309.0));
  });

  testWidgets('Avatar drawer works as expected on RawChip', (WidgetTester tester) async {
770
    final GlobalKey labelKey = GlobalKey();
771
    Future<void> pushChip({ Widget avatar }) async {
772
      return tester.pumpWidget(
773
        _wrapForChip(
774
          child: Wrap(
775
            children: <Widget>[
776
              RawChip(
777
                avatar: avatar,
778
                label: Text('Chip', key: labelKey),
779 780 781
                shape: const StadiumBorder(),
              ),
            ],
782 783 784 785 786 787 788
          ),
        ),
      );
    }

    // No avatar
    await pushChip();
789
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
790
    final GlobalKey avatarKey = GlobalKey();
791 792 793

    // Add an avatar
    await pushChip(
794
      avatar: Container(
795 796 797 798 799 800 801
        key: avatarKey,
        color: const Color(0xff000000),
        width: 40.0,
        height: 40.0,
      ),
    );
    // Avatar drawer should start out closed.
802
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
803
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
804 805
    expect(tester.getTopLeft(find.byKey(avatarKey)), equals(const Offset(-20.0, 12.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834

    await tester.pump(const Duration(milliseconds: 20));
    // Avatar drawer should start expanding.
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(81.2, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-18.8, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(13.2, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(86.7, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-13.3, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(18.6, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(94.7, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-5.3, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(26.7, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(99.5, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-0.5, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(31.5, 0.1));

    // Wait for being done with animation, and make sure it didn't change
    // height.
    await tester.pumpAndSettle(const Duration(milliseconds: 200));
835
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
836
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
837 838
    expect(tester.getTopLeft(find.byKey(avatarKey)), equals(const Offset(4.0, 12.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(36.0, 17.0)));
839 840 841 842

    // Remove the avatar again
    await pushChip();
    // Avatar drawer should start out open.
843
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
844
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
845 846
    expect(tester.getTopLeft(find.byKey(avatarKey)), equals(const Offset(4.0, 12.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(36.0, 17.0)));
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

    await tester.pump(const Duration(milliseconds: 20));
    // Avatar drawer should start contracting.
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(102.9, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(2.9, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(34.9, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(98.0, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-2.0, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(30.0, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(84.1, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-15.9, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(16.1, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(80.0, 0.1));
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, closeTo(-20.0, 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, closeTo(12.0, 0.1));

    // Wait for being done with animation, make sure it didn't change
    // height, and make sure that the avatar is no longer drawn.
    await tester.pumpAndSettle(const Duration(milliseconds: 200));
876 877
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
878
    expect(find.byKey(avatarKey), findsNothing);
879
  }, skip: isBrowser);
880 881

  testWidgets('Delete button drawer works as expected on RawChip', (WidgetTester tester) async {
882 883
    final UniqueKey labelKey = UniqueKey();
    final UniqueKey deleteButtonKey = UniqueKey();
884
    bool wasDeleted = false;
885
    Future<void> pushChip({ bool deletable = false }) async {
886
      return tester.pumpWidget(
887
        _wrapForChip(
888
          child: Wrap(
889
            children: <Widget>[
890 891
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
892
                  onDeleted: deletable
893 894 895 896 897 898
                    ? () {
                        setState(() {
                          wasDeleted = true;
                        });
                      }
                    : null,
899 900
                  deleteIcon: Container(width: 40.0, height: 40.0, key: deleteButtonKey),
                  label: Text('Chip', key: labelKey),
901 902 903 904
                  shape: const StadiumBorder(),
                );
              }),
            ],
905 906 907 908 909 910 911
          ),
        ),
      );
    }

    // No delete button
    await pushChip();
912
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
913 914 915 916

    // Add a delete button
    await pushChip(deletable: true);
    // Delete button drawer should start out closed.
917
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
918
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
919 920
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)), equals(const Offset(52.0, 12.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
921 922 923 924 925 926

    await tester.pump(const Duration(milliseconds: 20));
    // Delete button drawer should start expanding.
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(81.2, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(53.2, 0.1));
927
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(86.7, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(58.7, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(94.7, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(66.7, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(99.5, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(71.5, 0.1));

    // Wait for being done with animation, and make sure it didn't change
    // height.
    await tester.pumpAndSettle(const Duration(milliseconds: 200));
947
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
948
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
949 950
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)), equals(const Offset(76.0, 12.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
951 952 953 954 955 956 957 958 959 960 961

    // Test the tap work for the delete button, but not the rest of the chip.
    expect(wasDeleted, isFalse);
    await tester.tap(find.byKey(labelKey));
    expect(wasDeleted, isFalse);
    await tester.tap(find.byKey(deleteButtonKey));
    expect(wasDeleted, isTrue);

    // Remove the delete button again
    await pushChip();
    // Delete button drawer should start out open.
962
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
963
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
964 965
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)), equals(const Offset(76.0, 12.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
966 967 968 969 970 971

    await tester.pump(const Duration(milliseconds: 20));
    // Delete button drawer should start contracting.
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(103.8, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(75.8, 0.1));
972
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(102.9, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(74.9, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(101.0, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(73.0, 0.1));

    await tester.pump(const Duration(milliseconds: 20));
    expect(tester.getSize(find.byType(RawChip)).width, closeTo(97.5, 0.1));
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, closeTo(69.5, 0.1));

    // Wait for being done with animation, make sure it didn't change
    // height, and make sure that the delete button is no longer drawn.
    await tester.pumpAndSettle(const Duration(milliseconds: 200));
992 993
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
994
    expect(find.byKey(deleteButtonKey), findsNothing);
995
  }, skip: isBrowser);
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191

  testWidgets('Chip creates centered, unique ripple when label is tapped', (WidgetTester tester) async {
    // Creates a chip with a delete button.
    final UniqueKey labelKey = UniqueKey();
    final UniqueKey deleteButtonKey = UniqueKey();

    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        labelKey: labelKey,
        deleteButtonKey: deleteButtonKey,
        deletable: true,
      ),
    );

    final RenderBox box = getMaterialBox(tester);

    // Taps at a location close to the center of the label.
    final Offset centerOfLabel = tester.getCenter(find.byKey(labelKey));
    final Offset tapLocationOfLabel = centerOfLabel + const Offset(-10, -10);
    final TestGesture gesture = await tester.startGesture(tapLocationOfLabel);
    await tester.pump();

    // Waits for 100 ms.
    await tester.pump(const Duration(milliseconds: 100));

    // There should be exactly one ink-creating widget.
    expect(find.byType(InkWell), findsOneWidget);
    expect(find.byType(InkResponse), findsNothing);

    // There should be one unique, centered ink ripple.
    expect(box, ripplePattern(const Offset(163.0, 6.0), 20.9));
    expect(box, uniqueRipplePattern(const Offset(163.0, 6.0), 20.9));

    // There should be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    // Waits for 100 ms again.
    await tester.pump(const Duration(milliseconds: 100));

    // The ripple should grow, with the same center.
    expect(box, ripplePattern(const Offset(163.0, 6.0), 41.8));
    expect(box, uniqueRipplePattern(const Offset(163.0, 6.0), 41.8));

    // There should be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    // Waits for a very long time.
    await tester.pumpAndSettle();

    // There should still be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    await gesture.up();
  }, skip: isBrowser);

  testWidgets('Delete button creates non-centered, unique ripple when tapped', (WidgetTester tester) async {
    // Creates a chip with a delete button.
    final UniqueKey labelKey = UniqueKey();
    final UniqueKey deleteButtonKey = UniqueKey();

    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        labelKey: labelKey,
        deleteButtonKey: deleteButtonKey,
        deletable: true,
      ),
    );

    final RenderBox box = getMaterialBox(tester);

    // Taps at a location close to the center of the delete icon.
    final Offset centerOfDeleteButton = tester.getCenter(find.byKey(deleteButtonKey));
    final Offset tapLocationOfDeleteButton = centerOfDeleteButton + const Offset(-10, -10);
    final TestGesture gesture = await tester.startGesture(tapLocationOfDeleteButton);
    await tester.pump();

    // Waits for 200 ms.
    await tester.pump(const Duration(milliseconds: 100));
    await tester.pump(const Duration(milliseconds: 100));

    // There should be exactly one ink-creating widget.
    expect(find.byType(InkWell), findsOneWidget);
    expect(find.byType(InkResponse), findsNothing);

    // There should be one unique ink ripple.
    expect(box, ripplePattern(const Offset(3.0, 3.0), 3.5));
    expect(box, uniqueRipplePattern(const Offset(3.0, 3.0), 3.5));

    // There should be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    // Waits for 200 ms again.
    await tester.pump(const Duration(milliseconds: 100));
    await tester.pump(const Duration(milliseconds: 100));

    // The ripple should grow, but the center should move,
    // Towards the center of the delete icon.
    expect(box, ripplePattern(const Offset(5.0, 5.0), 10.5));
    expect(box, uniqueRipplePattern(const Offset(5.0, 5.0), 10.5));

    // There should be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    // Waits for a very long time.
    // This is pressing and holding the delete button.
    await tester.pumpAndSettle();

    // There should be a tooltip.
    expect(findTooltipContainer('Delete'), findsOneWidget);

    await gesture.up();
  }, skip: isBrowser);

  testWidgets('RTL delete button responds to tap on the left of the chip', (WidgetTester tester) async {
    // Creates an RTL chip with a delete button.
    final UniqueKey labelKey = UniqueKey();
    final UniqueKey deleteButtonKey = UniqueKey();

    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        labelKey: labelKey,
        deleteButtonKey: deleteButtonKey,
        deletable: true,
        textDirection: TextDirection.rtl,
      ),
    );

    // Taps at a location close to the center of the delete icon,
    // Which is on the left side of the chip.
    final Offset topLeftOfInkWell = tester.getTopLeft(find.byType(InkWell));
    final Offset tapLocation = topLeftOfInkWell + const Offset(8, 8);
    final TestGesture gesture = await tester.startGesture(tapLocation);
    await tester.pump();

    await tester.pumpAndSettle();

    // The existence of a 'Delete' tooltip indicates the delete icon is tapped,
    // Instead of the label.
    expect(findTooltipContainer('Delete'), findsOneWidget);

    await gesture.up();
  }, skip: isBrowser);

  testWidgets('Chip without delete button creates correct ripple', (WidgetTester tester) async {
    // Creates a chip with a delete button.
    final UniqueKey labelKey = UniqueKey();

    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        labelKey: labelKey,
        deletable: false,
      ),
    );

    final RenderBox box = getMaterialBox(tester);

    // Taps at a location close to the bottom-right corner of the chip.
    final Offset bottomRightOfInkWell = tester.getBottomRight(find.byType(InkWell));
    final Offset tapLocation = bottomRightOfInkWell + const Offset(-10, -10);
    final TestGesture gesture = await tester.startGesture(tapLocation);
    await tester.pump();

    // Waits for 100 ms.
    await tester.pump(const Duration(milliseconds: 100));

    // There should be exactly one ink-creating widget.
    expect(find.byType(InkWell), findsOneWidget);
    expect(find.byType(InkResponse), findsNothing);

    // There should be one unique, centered ink ripple.
    expect(box, ripplePattern(const Offset(378.0, 22.0), 37.9));
    expect(box, uniqueRipplePattern(const Offset(378.0, 22.0), 37.9));

    // There should be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    // Waits for 100 ms again.
    await tester.pump(const Duration(milliseconds: 100));

    // The ripple should grow, with the same center.
    // This indicates that the tap is not on a delete icon.
    expect(box, ripplePattern(const Offset(378.0, 22.0), 75.8));
    expect(box, uniqueRipplePattern(const Offset(378.0, 22.0), 75.8));

    // There should be no tooltip.
    expect(findTooltipContainer('Delete'), findsNothing);

    // Waits for a very long time.
    await tester.pumpAndSettle();

    // There should still be no tooltip.
    // This indicates that the tap is not on a delete icon.
    expect(findTooltipContainer('Delete'), findsNothing);

    await gesture.up();
  }, skip: isBrowser);
1192 1193 1194

  testWidgets('Selection with avatar works as expected on RawChip', (WidgetTester tester) async {
    bool selected = false;
1195
    final UniqueKey labelKey = UniqueKey();
1196
    Future<void> pushChip({ Widget avatar, bool selectable = false }) async {
1197
      return tester.pumpWidget(
1198
        _wrapForChip(
1199
          child: Wrap(
1200
            children: <Widget>[
1201 1202
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1203 1204
                  avatar: avatar,
                  onSelected: selectable != null
1205 1206 1207 1208 1209 1210
                    ? (bool value) {
                        setState(() {
                          selected = value;
                        });
                      }
                    : null,
1211
                  selected: selected,
1212
                  label: Text('Chip', key: labelKey),
1213 1214 1215 1216 1217 1218 1219
                  shape: const StadiumBorder(),
                  showCheckmark: true,
                  tapEnabled: true,
                  isEnabled: true,
                );
              }),
            ],
1220 1221 1222 1223 1224 1225
          ),
        ),
      );
    }

    // With avatar, but not selectable.
1226
    final UniqueKey avatarKey = UniqueKey();
1227
    await pushChip(
1228
      avatar: Container(width: 40.0, height: 40.0, key: avatarKey),
1229
    );
1230
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
1231 1232 1233

    // Turn on selection.
    await pushChip(
1234
      avatar: Container(width: 40.0, height: 40.0, key: avatarKey),
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 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273
      selectable: true,
    );
    await tester.pumpAndSettle();

    // Simulate a tap on the label to select the chip.
    await tester.tap(find.byKey(labelKey));
    expect(selected, equals(true));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(getSelectProgress(tester), closeTo(0.002, 0.01));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 50));
    expect(getSelectProgress(tester), closeTo(0.54, 0.01));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 100));
    expect(getSelectProgress(tester), equals(1.0));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pumpAndSettle();
    // Simulate another tap on the label to deselect the chip.
    await tester.tap(find.byKey(labelKey));
    expect(selected, equals(false));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 20));
    expect(getSelectProgress(tester), closeTo(0.875, 0.01));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 20));
    expect(getSelectProgress(tester), closeTo(0.13, 0.01));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 100));
    expect(getSelectProgress(tester), equals(0.0));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
1274
  }, skip: isBrowser);
1275 1276 1277

  testWidgets('Selection without avatar works as expected on RawChip', (WidgetTester tester) async {
    bool selected = false;
1278
    final UniqueKey labelKey = UniqueKey();
1279
    Future<void> pushChip({ bool selectable = false }) async {
1280
      return tester.pumpWidget(
1281
        _wrapForChip(
1282
          child: Wrap(
1283
            children: <Widget>[
1284 1285
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1286
                  onSelected: selectable != null
1287 1288 1289 1290 1291 1292
                    ? (bool value) {
                        setState(() {
                          selected = value;
                        });
                      }
                    : null,
1293
                  selected: selected,
1294
                  label: Text('Chip', key: labelKey),
1295 1296 1297 1298 1299 1300 1301
                  shape: const StadiumBorder(),
                  showCheckmark: true,
                  tapEnabled: true,
                  isEnabled: true,
                );
              }),
            ],
1302 1303 1304 1305 1306 1307 1308
          ),
        ),
      );
    }

    // Without avatar, but not selectable.
    await pushChip();
1309
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349

    // Turn on selection.
    await pushChip(selectable: true);
    await tester.pumpAndSettle();

    // Simulate a tap on the label to select the chip.
    await tester.tap(find.byKey(labelKey));
    expect(selected, equals(true));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(getSelectProgress(tester), closeTo(0.002, 0.01));
    expect(getAvatarDrawerProgress(tester), closeTo(0.459, 0.01));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 50));
    expect(getSelectProgress(tester), closeTo(0.54, 0.01));
    expect(getAvatarDrawerProgress(tester), closeTo(0.92, 0.01));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 100));
    expect(getSelectProgress(tester), equals(1.0));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pumpAndSettle();
    // Simulate another tap on the label to deselect the chip.
    await tester.tap(find.byKey(labelKey));
    expect(selected, equals(false));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 20));
    expect(getSelectProgress(tester), closeTo(0.875, 0.01));
    expect(getAvatarDrawerProgress(tester), closeTo(0.96, 0.01));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 20));
    expect(getSelectProgress(tester), closeTo(0.13, 0.01));
    expect(getAvatarDrawerProgress(tester), closeTo(0.75, 0.01));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 100));
    expect(getSelectProgress(tester), equals(0.0));
    expect(getAvatarDrawerProgress(tester), equals(0.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
1350
  }, skip: isBrowser);
1351 1352 1353

  testWidgets('Activation works as expected on RawChip', (WidgetTester tester) async {
    bool selected = false;
1354
    final UniqueKey labelKey = UniqueKey();
1355
    Future<void> pushChip({ Widget avatar, bool selectable = false }) async {
1356
      return tester.pumpWidget(
1357
        _wrapForChip(
1358
          child: Wrap(
1359
            children: <Widget>[
1360 1361
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1362 1363
                  avatar: avatar,
                  onSelected: selectable != null
1364 1365 1366 1367 1368 1369
                    ? (bool value) {
                        setState(() {
                          selected = value;
                        });
                      }
                    : null,
1370
                  selected: selected,
1371
                  label: Text('Chip', key: labelKey),
1372 1373 1374 1375 1376 1377 1378
                  shape: const StadiumBorder(),
                  showCheckmark: false,
                  tapEnabled: true,
                  isEnabled: true,
                );
              }),
            ],
1379 1380 1381 1382 1383
          ),
        ),
      );
    }

1384
    final UniqueKey avatarKey = UniqueKey();
1385
    await pushChip(
1386
      avatar: Container(width: 40.0, height: 40.0, key: avatarKey),
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407
      selectable: true,
    );
    await tester.pumpAndSettle();

    await tester.tap(find.byKey(labelKey));
    expect(selected, equals(true));
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
    expect(getSelectProgress(tester), closeTo(0.002, 0.01));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 50));
    expect(getSelectProgress(tester), closeTo(0.54, 0.01));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 100));
    expect(getSelectProgress(tester), equals(1.0));
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pumpAndSettle();
1408
  });
1409 1410

  testWidgets('Chip uses ThemeData chip theme if present', (WidgetTester tester) async {
1411
    final ThemeData theme = ThemeData(
1412 1413 1414 1415 1416 1417 1418 1419
      platform: TargetPlatform.android,
      primarySwatch: Colors.red,
    );
    final ChipThemeData chipTheme = theme.chipTheme;

    Widget buildChip(ChipThemeData data) {
      return _wrapForChip(
        textDirection: TextDirection.ltr,
1420
        child: Theme(
1421 1422
          data: theme,
          child: const InputChip(
1423
            label: Text('Label'),
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
          ),
        ),
      );
    }

    await tester.pumpWidget(buildChip(chipTheme));

    final RenderBox materialBox = tester.firstRenderObject<RenderBox>(
      find.descendant(
        of: find.byType(RawChip),
        matching: find.byType(CustomPaint),
      ),
    );

1438
    expect(materialBox, paints..path(color: chipTheme.disabledColor));
1439 1440
  });

1441
  testWidgets('Chip size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
1442
    final Key key1 = UniqueKey();
1443 1444
    await tester.pumpWidget(
      _wrapForChip(
1445 1446 1447 1448
        child: Theme(
          data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded),
          child: Center(
            child: RawChip(
1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
              key: key1,
              label: const Text('test'),
            ),
          ),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(key1)), const Size(80.0, 48.0));

1459
    final Key key2 = UniqueKey();
1460 1461
    await tester.pumpWidget(
      _wrapForChip(
1462 1463 1464 1465
        child: Theme(
          data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap),
          child: Center(
            child: RawChip(
1466 1467 1468 1469 1470 1471 1472 1473 1474
              key: key2,
              label: const Text('test'),
            ),
          ),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(key2)), const Size(80.0, 32.0));
1475
  }, skip: isBrowser);
1476

1477
  testWidgets('Chip uses the right theme colors for the right components', (WidgetTester tester) async {
1478
    final ThemeData themeData = ThemeData(
1479 1480 1481
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
1482
    final ChipThemeData defaultChipTheme = themeData.chipTheme;
1483 1484
    bool value = false;
    Widget buildApp({
1485
      ChipThemeData chipTheme,
1486 1487
      Widget avatar,
      Widget deleteIcon,
1488 1489 1490 1491
      bool isSelectable = true,
      bool isPressable = false,
      bool isDeletable = true,
      bool showCheckmark = true,
1492
    }) {
1493
      chipTheme ??= defaultChipTheme;
1494
      return _wrapForChip(
1495
        child: Theme(
1496
          data: themeData,
1497
          child: ChipTheme(
1498
            data: chipTheme,
1499 1500
            child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
              return RawChip(
1501
                showCheckmark: showCheckmark,
1502
                onDeleted: isDeletable ? () { } : null,
1503 1504 1505 1506
                tapEnabled: true,
                avatar: avatar,
                deleteIcon: deleteIcon,
                isEnabled: isSelectable || isPressable,
1507
                shape: chipTheme.shape,
1508
                selected: isSelectable && value,
1509
                label: Text('$value'),
1510
                onSelected: isSelectable
1511 1512 1513 1514 1515 1516
                  ? (bool newValue) {
                      setState(() {
                        value = newValue;
                      });
                    }
                  : null,
1517
                onPressed: isPressable
1518 1519 1520 1521 1522 1523
                  ? () {
                      setState(() {
                        value = true;
                      });
                    }
                  : null,
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537
              );
            }),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildApp());

    RenderBox materialBox = getMaterialBox(tester);
    IconThemeData iconData = getIconData(tester);
    DefaultTextStyle labelStyle = getLabelStyle(tester);

    // Check default theme for enabled widget.
1538
    expect(materialBox, paints..path(color: defaultChipTheme.backgroundColor));
1539 1540 1541 1542 1543
    expect(iconData.color, equals(const Color(0xde000000)));
    expect(labelStyle.style.color, equals(Colors.black.withAlpha(0xde)));
    await tester.tap(find.byType(RawChip));
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
1544
    expect(materialBox, paints..path(color: defaultChipTheme.selectedColor));
1545 1546 1547 1548 1549 1550 1551 1552
    await tester.tap(find.byType(RawChip));
    await tester.pumpAndSettle();

    // Check default theme with disabled widget.
    await tester.pumpWidget(buildApp(isSelectable: false, isPressable: false, isDeletable: true));
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
    labelStyle = getLabelStyle(tester);
1553
    expect(materialBox, paints..path(color: defaultChipTheme.disabledColor));
1554 1555 1556
    expect(labelStyle.style.color, equals(Colors.black.withAlpha(0xde)));

    // Apply a custom theme.
1557 1558 1559 1560
    const Color customColor1 = Color(0xcafefeed);
    const Color customColor2 = Color(0xdeadbeef);
    const Color customColor3 = Color(0xbeefcafe);
    const Color customColor4 = Color(0xaddedabe);
1561
    final ChipThemeData customTheme = defaultChipTheme.copyWith(
1562 1563 1564 1565 1566 1567
      brightness: Brightness.dark,
      backgroundColor: customColor1,
      disabledColor: customColor2,
      selectedColor: customColor3,
      deleteIconColor: customColor4,
    );
1568
    await tester.pumpWidget(buildApp(chipTheme: customTheme));
1569 1570 1571 1572 1573 1574
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
    iconData = getIconData(tester);
    labelStyle = getLabelStyle(tester);

    // Check custom theme for enabled widget.
1575
    expect(materialBox, paints..path(color: customTheme.backgroundColor));
1576 1577 1578 1579 1580
    expect(iconData.color, equals(customTheme.deleteIconColor));
    expect(labelStyle.style.color, equals(Colors.black.withAlpha(0xde)));
    await tester.tap(find.byType(RawChip));
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
1581
    expect(materialBox, paints..path(color: customTheme.selectedColor));
1582 1583 1584 1585 1586
    await tester.tap(find.byType(RawChip));
    await tester.pumpAndSettle();

    // Check custom theme with disabled widget.
    await tester.pumpWidget(buildApp(
1587
      chipTheme: customTheme,
1588 1589 1590 1591 1592 1593 1594
      isSelectable: false,
      isPressable: false,
      isDeletable: true,
    ));
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
    labelStyle = getLabelStyle(tester);
1595
    expect(materialBox, paints..path(color: customTheme.disabledColor));
1596 1597
    expect(labelStyle.style.color, equals(Colors.black.withAlpha(0xde)));
  });
1598 1599 1600

  group('Chip semantics', () {
    testWidgets('label only', (WidgetTester tester) async {
1601
      final SemanticsTester semanticsTester = SemanticsTester(tester);
1602

1603 1604
      await tester.pumpWidget(const MaterialApp(
        home: Material(
1605 1606
          child: RawChip(
            label: Text('test'),
1607 1608 1609 1610 1611
          ),
        ),
      ));

      expect(semanticsTester, hasSemantics(
1612
          TestSemantics.root(
1613
            children: <TestSemantics>[
1614
              TestSemantics(
1615 1616
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
1617
                  TestSemantics(
1618 1619
                    flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                    children: <TestSemantics>[
1620
                      TestSemantics(
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632
                        label: 'test',
                        textDirection: TextDirection.ltr,
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ), ignoreTransform: true, ignoreId: true, ignoreRect: true));
      semanticsTester.dispose();
    });

1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676
    testWidgets('delete', (WidgetTester tester) async {
      final SemanticsTester semanticsTester = SemanticsTester(tester);

      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
            label: const Text('test'),
            onDeleted: () { },
          ),
        ),
      ));

      expect(semanticsTester, hasSemantics(
          TestSemantics.root(
            children: <TestSemantics>[
              TestSemantics(
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
                  TestSemantics(
                    flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                    children: <TestSemantics>[
                      TestSemantics(
                        label: 'test',
                        textDirection: TextDirection.ltr,
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'Delete',
                            actions: <SemanticsAction>[SemanticsAction.tap],
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[
                              SemanticsFlag.isButton,
                            ],
                          ),
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ), ignoreTransform: true, ignoreId: true, ignoreRect: true));
      semanticsTester.dispose();
    });

1677
    testWidgets('with onPressed', (WidgetTester tester) async {
1678
      final SemanticsTester semanticsTester = SemanticsTester(tester);
1679

1680 1681 1682
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
1683
            label: const Text('test'),
1684
            onPressed: () { },
1685 1686 1687 1688 1689
          ),
        ),
      ));

      expect(semanticsTester, hasSemantics(
1690
          TestSemantics.root(
1691
            children: <TestSemantics>[
1692
              TestSemantics(
1693 1694
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
1695
                  TestSemantics(
1696 1697
                    flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                    children: <TestSemantics>[
1698
                      TestSemantics(
1699 1700 1701 1702 1703
                        label: 'test',
                        textDirection: TextDirection.ltr,
                        flags: <SemanticsFlag>[
                          SemanticsFlag.hasEnabledState,
                          SemanticsFlag.isEnabled,
1704
                          SemanticsFlag.isFocusable,
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719
                        ],
                        actions: <SemanticsAction>[SemanticsAction.tap],
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

      semanticsTester.dispose();
    });


    testWidgets('with onSelected', (WidgetTester tester) async {
1720
      final SemanticsTester semanticsTester = SemanticsTester(tester);
1721 1722
      bool selected = false;

1723 1724 1725
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736
            isEnabled: true,
            label: const Text('test'),
            selected: selected,
            onSelected: (bool value) {
              selected = value;
            },
          ),
        ),
      ));

      expect(semanticsTester, hasSemantics(
1737
          TestSemantics.root(
1738
            children: <TestSemantics>[
1739
              TestSemantics(
1740 1741
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
1742
                  TestSemantics(
1743 1744
                    flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                    children: <TestSemantics>[
1745
                      TestSemantics(
1746 1747 1748 1749 1750
                        label: 'test',
                        textDirection: TextDirection.ltr,
                        flags: <SemanticsFlag>[
                          SemanticsFlag.hasEnabledState,
                          SemanticsFlag.isEnabled,
1751
                          SemanticsFlag.isFocusable,
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762
                        ],
                        actions: <SemanticsAction>[SemanticsAction.tap],
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

      await tester.tap(find.byType(RawChip));
1763 1764 1765
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777
            isEnabled: true,
            label: const Text('test'),
            selected: selected,
            onSelected: (bool value) {
              selected = value;
            },
          ),
        ),
      ));

      expect(selected, true);
      expect(semanticsTester, hasSemantics(
1778
          TestSemantics.root(
1779
            children: <TestSemantics>[
1780
              TestSemantics(
1781 1782
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
1783
                  TestSemantics(
1784 1785
                    flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                    children: <TestSemantics>[
1786
                      TestSemantics(
1787 1788 1789 1790 1791
                        label: 'test',
                        textDirection: TextDirection.ltr,
                        flags: <SemanticsFlag>[
                          SemanticsFlag.hasEnabledState,
                          SemanticsFlag.isEnabled,
1792 1793
                          SemanticsFlag.isFocusable,
                          SemanticsFlag.isSelected,
1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807
                        ],
                        actions: <SemanticsAction>[SemanticsAction.tap],
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

      semanticsTester.dispose();
    });

    testWidgets('disabled', (WidgetTester tester) async {
1808
      final SemanticsTester semanticsTester = SemanticsTester(tester);
1809

1810 1811 1812
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
1813
            isEnabled: false,
1814
            onPressed: () { },
1815 1816 1817 1818 1819 1820
            label: const Text('test'),
          ),
        ),
      ));

      expect(semanticsTester, hasSemantics(
1821
          TestSemantics.root(
1822
            children: <TestSemantics>[
1823
              TestSemantics(
1824 1825
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
1826
                  TestSemantics(
1827 1828
                    flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                    children: <TestSemantics>[
1829
                      TestSemantics(
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849
                        label: 'test',
                        textDirection: TextDirection.ltr,
                        flags: <SemanticsFlag>[],
                        actions: <SemanticsAction>[],
                      ),
                    ],
                  ),
                ],
              ),
            ],
          ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

      semanticsTester.dispose();
    });
  });

  testWidgets('can be tapped outside of chip delete icon', (WidgetTester tester) async {
    bool deleted = false;
    await tester.pumpWidget(
      _wrapForChip(
1850
        child: Row(
1851
          children: <Widget>[
1852
            Chip(
1853
              materialTapTargetSize: MaterialTapTargetSize.padded,
1854 1855
              shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))),
              avatar: const CircleAvatar(child: Text('A')),
1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871
              label: const Text('Chip A'),
              onDeleted: () {
                deleted = true;
              },
              deleteIcon: const Icon(Icons.delete),
            ),
          ],
        ),
      ),
    );

    await tester.tapAt(tester.getTopRight(find.byType(Chip)) - const Offset(2.0, -2.0));
    await tester.pumpAndSettle();
    expect(deleted, true);
  });

jslavitz's avatar
jslavitz committed
1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904
  testWidgets('Chips can be tapped', (WidgetTester tester) async {
    await tester.pumpWidget(
      const MaterialApp(
        home: Material(
          child: ChoiceChip(
            selected: false,
            label: Text('choice chip'),
          ),
        ),
      ),
    );

    await tester.tap(find.byType(ChoiceChip));
    expect(tester.takeException(), null);

    await tester.pumpWidget(
      const MaterialApp(
        home: Material(
          child: RawChip(
            selected: false,
            label: Text('raw chip'),
          ),
        ),
      ),
    );

    await tester.tap(find.byType(RawChip));
    expect(tester.takeException(), null);

    await tester.pumpWidget(
      MaterialApp(
        home: Material(
          child: ActionChip(
1905
            onPressed: () { },
jslavitz's avatar
jslavitz committed
1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918
            label: const Text('action chip'),
          ),
        ),
      ),
    );

    await tester.tap(find.byType(ActionChip));
    expect(tester.takeException(), null);

    await tester.pumpWidget(
      MaterialApp(
        home: Material(
          child: FilterChip(
1919
            onSelected: (bool valueChanged) { },
jslavitz's avatar
jslavitz committed
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
            selected: false,
            label: const Text('filter chip'),
          ),
        ),
      ),
    );

    await tester.tap(find.byType(FilterChip));
    expect(tester.takeException(), null);

    await tester.pumpWidget(
      const MaterialApp(
        home: Material(
          child: InputChip(
            selected: false,
            label: Text('input chip'),
          ),
        ),
      ),
    );

    await tester.tap(find.byType(InputChip));
    expect(tester.takeException(), null);
  });

1945
  testWidgets('Chip elevation and shadow color work correctly', (WidgetTester tester) async {
1946 1947 1948 1949 1950 1951 1952
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.red,
    );

    final ChipThemeData chipTheme = theme.chipTheme;

1953
    InputChip inputChip = const InputChip(label: Text('Label'));
1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965

    Widget buildChip(ChipThemeData data) {
      return _wrapForChip(
        textDirection: TextDirection.ltr,
        child: Theme(
          data: theme,
          child: inputChip,
        ),
      );
    }

    await tester.pumpWidget(buildChip(chipTheme));
1966 1967
    Material material = getMaterial(tester);
    expect(material.elevation, 0.0);
1968
    expect(material.shadowColor, Colors.black);
1969

1970 1971 1972
    inputChip = const InputChip(
      label: Text('Label'),
      elevation: 4.0,
1973 1974
      shadowColor: Colors.green,
      selectedShadowColor: Colors.blue,
1975
    );
1976 1977 1978

    await tester.pumpWidget(buildChip(chipTheme));
    await tester.pumpAndSettle();
1979 1980
    material = getMaterial(tester);
    expect(material.elevation, 4.0);
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993
    expect(material.shadowColor, Colors.green);

    inputChip = const InputChip(
      label: Text('Label'),
      selected: true,
      shadowColor: Colors.green,
      selectedShadowColor: Colors.blue,
    );

    await tester.pumpWidget(buildChip(chipTheme));
    await tester.pumpAndSettle();
    material = getMaterial(tester);
    expect(material.shadowColor, Colors.blue);
1994 1995
  });

1996 1997 1998 1999
  testWidgets('can be tapped outside of chip body', (WidgetTester tester) async {
    bool pressed = false;
    await tester.pumpWidget(
      _wrapForChip(
2000
        child: Row(
2001
          children: <Widget>[
2002
            InputChip(
2003
              materialTapTargetSize: MaterialTapTargetSize.padded,
2004 2005
              shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))),
              avatar: const CircleAvatar(child: Text('A')),
2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023
              label: const Text('Chip A'),
              onPressed: () {
                pressed = true;
              },
            ),
          ],
        ),
      ),
    );

    await tester.tapAt(tester.getRect(find.byType(InputChip)).topCenter);
    await tester.pumpAndSettle();
    expect(pressed, true);
  });

  testWidgets('is hitTestable', (WidgetTester tester) async {
    await tester.pumpWidget(
      _wrapForChip(
2024
        child: InputChip(
2025 2026
          shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))),
          avatar: const CircleAvatar(child: Text('A')),
2027
          label: const Text('Chip A'),
2028
          onPressed: () { },
2029 2030 2031 2032 2033 2034
        ),
      ),
    );

    expect(find.byType(InputChip).hitTestable(at: Alignment.center), findsOneWidget);
  });
2035 2036 2037 2038 2039 2040 2041 2042

  void checkChipMaterialClipBehavior(WidgetTester tester, Clip clipBehavior) {
    final Iterable<Material> materials = tester.widgetList<Material>(find.byType(Material));
    expect(materials.length, 2);
    expect(materials.last.clipBehavior, clipBehavior);
  }

  testWidgets('Chip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
2043 2044 2045
    const Text label = Text('label');
    await tester.pumpWidget(_wrapForChip(child: const Chip(label: label)));
    checkChipMaterialClipBehavior(tester, Clip.none);
2046

2047 2048
    await tester.pumpWidget(_wrapForChip(child: const Chip(label: label, clipBehavior: Clip.antiAlias)));
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061
  });

  testWidgets('ChoiceChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
    const Text label = Text('label');
    await tester.pumpWidget(_wrapForChip(child: const ChoiceChip(label: label, selected: false)));
    checkChipMaterialClipBehavior(tester, Clip.none);

    await tester.pumpWidget(_wrapForChip(child: const ChoiceChip(label: label, selected: false, clipBehavior: Clip.antiAlias)));
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
  });

  testWidgets('FilterChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
    const Text label = Text('label');
2062
    await tester.pumpWidget(_wrapForChip(child: FilterChip(label: label, onSelected: (bool b) { },)));
2063 2064
    checkChipMaterialClipBehavior(tester, Clip.none);

2065
    await tester.pumpWidget(_wrapForChip(child: FilterChip(label: label, onSelected: (bool b) { }, clipBehavior: Clip.antiAlias)));
2066 2067 2068 2069 2070
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
  });

  testWidgets('ActionChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
    const Text label = Text('label');
2071
    await tester.pumpWidget(_wrapForChip(child: ActionChip(label: label, onPressed: () { },)));
2072 2073
    checkChipMaterialClipBehavior(tester, Clip.none);

2074
    await tester.pumpWidget(_wrapForChip(child: ActionChip(label: label, clipBehavior: Clip.antiAlias, onPressed: () { })));
2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
  });

  testWidgets('InputChip clipBehavior properly passes through to the Material', (WidgetTester tester) async {
    const Text label = Text('label');
    await tester.pumpWidget(_wrapForChip(child: const InputChip(label: label)));
    checkChipMaterialClipBehavior(tester, Clip.none);

    await tester.pumpWidget(_wrapForChip(child: const InputChip(label: label, clipBehavior: Clip.antiAlias)));
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
  });
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098

  testWidgets('selected chip and avatar draw darkened layer within avatar circle', (WidgetTester tester) async {
    await tester.pumpWidget(_wrapForChip(child: const FilterChip(
      avatar: CircleAvatar(child: Text('t')),
      label: Text('test'),
      selected: true,
      onSelected: null,
    )));
    final RenderBox rawChip = tester.firstRenderObject<RenderBox>(
      find.descendant(
        of: find.byType(RawChip),
        matching: find.byWidgetPredicate((Widget widget) {
          return widget.runtimeType.toString() == '_ChipRenderWidget';
2099
        }),
2100
      ),
2101 2102 2103 2104 2105 2106 2107
    );
    const Color selectScrimColor = Color(0x60191919);
    expect(rawChip, paints..path(color: selectScrimColor, includes: <Offset>[
      const Offset(10, 10),
    ], excludes: <Offset>[
      const Offset(4, 4),
    ]));
2108
  }, skip: isBrowser);
2109 2110 2111 2112 2113 2114 2115

  testWidgets('Chips should use InkWell instead of InkResponse.', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/28646
    await tester.pumpWidget(
      MaterialApp(
        home: Material(
          child: ActionChip(
2116
            onPressed: () { },
2117 2118 2119 2120 2121 2122 2123
            label: const Text('action chip'),
          ),
        ),
      ),
    );
    expect(find.byType(InkWell), findsOneWidget);
  });
2124

2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138
  testWidgets('RawChip.selected can not be null', (WidgetTester tester) async {
    expect(() async {
      MaterialApp(
        home: Material(
          child: RawChip(
            onPressed: () { },
            selected: null,
            label: const Text('Chip'),
          ),
        ),
      );
    }, throwsAssertionError);
  });

2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 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 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223
  testWidgets('Chip uses stateful color for text color in different states', (WidgetTester tester) async {
    final FocusNode focusNode = FocusNode();

    const Color pressedColor = Color(0x00000001);
    const Color hoverColor = Color(0x00000002);
    const Color focusedColor = Color(0x00000003);
    const Color defaultColor = Color(0x00000004);
    const Color selectedColor = Color(0x00000005);
    const Color disabledColor = Color(0x00000006);

    Color getTextColor(Set<MaterialState> states) {
      if (states.contains(MaterialState.disabled))
        return disabledColor;

      if (states.contains(MaterialState.pressed))
        return pressedColor;

      if (states.contains(MaterialState.hovered))
        return hoverColor;

      if (states.contains(MaterialState.focused))
        return focusedColor;

      if (states.contains(MaterialState.selected))
        return selectedColor;

      return defaultColor;
    }

    Widget chipWidget({ bool enabled = true, bool selected = false }) {
      return MaterialApp(
        home: Scaffold(
          body: Focus(
            focusNode: focusNode,
            child: ChoiceChip(
              label: const Text('Chip'),
              selected: selected,
              onSelected: enabled ? (_) {} : null,
              labelStyle: TextStyle(color: MaterialStateColor.resolveWith(getTextColor)),
            ),
          ),
        ),
      );
    }
    Color textColor() {
      return tester.renderObject<RenderParagraph>(find.text('Chip')).text.style.color;
    }

    // Default, not disabled.
    await tester.pumpWidget(chipWidget());
    expect(textColor(), equals(defaultColor));

    // Selected.
    await tester.pumpWidget(chipWidget(selected: true));
    expect(textColor(), selectedColor);

    // Focused.
    final FocusNode chipFocusNode = focusNode.children.first;
    chipFocusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(textColor(), focusedColor);

    // Hovered.
    final Offset center = tester.getCenter(find.byType(ChoiceChip));
    final TestGesture gesture = await tester.createGesture(
      kind: PointerDeviceKind.mouse,
    );
    await gesture.addPointer();
    await gesture.moveTo(center);
    await tester.pumpAndSettle();
    expect(textColor(), hoverColor);

    // Pressed.
    await gesture.down(center);
    await tester.pumpAndSettle();
    expect(textColor(), pressedColor);

    // Disabled.
    await tester.pumpWidget(chipWidget(enabled: false));
    await tester.pumpAndSettle();
    expect(textColor(), disabledColor);

    // Teardown.
    await gesture.removePointer();
  });
2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290

  testWidgets('loses focus when disabled', (WidgetTester tester) async {
    final FocusNode focusNode = FocusNode(debugLabel: 'InputChip');
    await tester.pumpWidget(
      _wrapForChip(
        child: InputChip(
          focusNode: focusNode,
          autofocus: true,
          shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))),
          avatar: const CircleAvatar(child: Text('A')),
          label: const Text('Chip A'),
          onPressed: () { },
        ),
      ),
    );
    await tester.pump();
    expect(focusNode.hasPrimaryFocus, isTrue);

    await tester.pumpWidget(
      _wrapForChip(
        child: InputChip(
          focusNode: focusNode,
          autofocus: true,
          shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0.0))),
          avatar: const CircleAvatar(child: Text('A')),
          label: const Text('Chip A'),
          onPressed: null,
        ),
      ),
    );
    await tester.pump();
    expect(focusNode.hasPrimaryFocus, isFalse);
  });

  testWidgets('cannot be traversed to when disabled', (WidgetTester tester) async {
    final FocusNode focusNode1 = FocusNode(debugLabel: 'InputChip 1');
    final FocusNode focusNode2 = FocusNode(debugLabel: 'InputChip 2');
    await tester.pumpWidget(
      _wrapForChip(
        child: Column(
          children: <Widget>[
            InputChip(
              focusNode: focusNode1,
              autofocus: true,
              label: const Text('Chip A'),
              onPressed: () { },
            ),
            InputChip(
              focusNode: focusNode2,
              autofocus: true,
              label: const Text('Chip B'),
              onPressed: null,
            ),
          ],
        ),
      ),
    );
    await tester.pump();
    expect(focusNode1.hasPrimaryFocus, isTrue);
    expect(focusNode2.hasPrimaryFocus, isFalse);

    expect(focusNode1.nextFocus(), isTrue);

    await tester.pump();
    expect(focusNode1.hasPrimaryFocus, isTrue);
    expect(focusNode2.hasPrimaryFocus, isFalse);
  });
2291

2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396
  testWidgets('Chip responds to density changes.', (WidgetTester tester) async {
    const Key key = Key('test');
    const Key textKey = Key('test text');
    const Key iconKey = Key('test icon');
    const Key avatarKey = Key('test avatar');
    Future<void> buildTest(VisualDensity visualDensity) async {
      return await tester.pumpWidget(
        MaterialApp(
          home: Material(
            child: Center(
              child: Column(
                children: <Widget>[
                  InputChip(
                    visualDensity: visualDensity,
                    key: key,
                    onPressed: () {},
                    onDeleted: () {},
                    label: const Text('Test', key: textKey),
                    deleteIcon: const Icon(Icons.delete, key: iconKey),
                    avatar: const Icon(Icons.play_arrow, key: avatarKey),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
    }

    // The Chips only change in size vertically in response to density, so
    // horizontal changes aren't expected.
    await buildTest(VisualDensity.standard);
    Rect box = tester.getRect(find.byKey(key));
    Rect textBox = tester.getRect(find.byKey(textKey));
    Rect iconBox = tester.getRect(find.byKey(iconKey));
    Rect avatarBox = tester.getRect(find.byKey(avatarKey));
    expect(box.size, equals(const Size(128, 32.0 + 16.0)));
    expect(textBox.size, equals(const Size(56, 14)));
    expect(iconBox.size, equals(const Size(24, 24)));
    expect(avatarBox.size, equals(const Size(24, 24)));
    expect(textBox.top, equals(17));
    expect(box.bottom - textBox.bottom, equals(17));
    expect(textBox.left, equals(372));
    expect(box.right - textBox.right, equals(36));

    // Try decreasing density (with higher density numbers).
    await buildTest(const VisualDensity(horizontal: 3.0, vertical: 3.0));
    box = tester.getRect(find.byKey(key));
    textBox = tester.getRect(find.byKey(textKey));
    iconBox = tester.getRect(find.byKey(iconKey));
    avatarBox = tester.getRect(find.byKey(avatarKey));
    expect(box.size, equals(const Size(128, 60)));
    expect(textBox.size, equals(const Size(56, 14)));
    expect(iconBox.size, equals(const Size(24, 24)));
    expect(avatarBox.size, equals(const Size(24, 24)));
    expect(textBox.top, equals(23));
    expect(box.bottom - textBox.bottom, equals(23));
    expect(textBox.left, equals(372));
    expect(box.right - textBox.right, equals(36));

    // Try increasing density (with lower density numbers).
    await buildTest(const VisualDensity(horizontal: -3.0, vertical: -3.0));
    box = tester.getRect(find.byKey(key));
    textBox = tester.getRect(find.byKey(textKey));
    iconBox = tester.getRect(find.byKey(iconKey));
    avatarBox = tester.getRect(find.byKey(avatarKey));
    expect(box.size, equals(const Size(128, 36)));
    expect(textBox.size, equals(const Size(56, 14)));
    expect(iconBox.size, equals(const Size(24, 24)));
    expect(avatarBox.size, equals(const Size(24, 24)));
    expect(textBox.top, equals(11));
    expect(box.bottom - textBox.bottom, equals(11));
    expect(textBox.left, equals(372));
    expect(box.right - textBox.right, equals(36));

    // Now test that horizontal and vertical are wired correctly. Negating the
    // horizontal should have no change over what's above.
    await buildTest(const VisualDensity(horizontal: 3.0, vertical: -3.0));
    await tester.pumpAndSettle();
    box = tester.getRect(find.byKey(key));
    textBox = tester.getRect(find.byKey(textKey));
    iconBox = tester.getRect(find.byKey(iconKey));
    avatarBox = tester.getRect(find.byKey(avatarKey));
    expect(box.size, equals(const Size(128, 36)));
    expect(textBox.size, equals(const Size(56, 14)));
    expect(iconBox.size, equals(const Size(24, 24)));
    expect(avatarBox.size, equals(const Size(24, 24)));
    expect(textBox.top, equals(11));
    expect(box.bottom - textBox.bottom, equals(11));
    expect(textBox.left, equals(372));
    expect(box.right - textBox.right, equals(36));

    // Make sure the "Comfortable" setting is the spec'd size
    await buildTest(VisualDensity.comfortable);
    await tester.pumpAndSettle();
    box = tester.getRect(find.byKey(key));
    expect(box.size, equals(const Size(128, 28.0 + 16.0)));

    // Make sure the "Compact" setting is the spec'd size
    await buildTest(VisualDensity.compact);
    await tester.pumpAndSettle();
    box = tester.getRect(find.byKey(key));
    expect(box.size, equals(const Size(128, 24.0 + 16.0)));
  });

2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523
  testWidgets('Input chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedInputChip(),
      brightness: Brightness.light,
    );

    _expectCheckmarkColor(
      find.byType(InputChip),
      Colors.black.withAlpha(0xde),
    );
  });

  testWidgets('Filter chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedFilterChip(),
      brightness: Brightness.light,
    );

    _expectCheckmarkColor(
      find.byType(FilterChip),
      Colors.black.withAlpha(0xde),
    );
  });

  testWidgets('Input chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedInputChip(),
      brightness: Brightness.dark,
    );

    _expectCheckmarkColor(
      find.byType(InputChip),
      Colors.white.withAlpha(0xde),
    );
  });

  testWidgets('Filter chip check mark color is determined by platform brightness when dark', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedFilterChip(),
      brightness: Brightness.dark,
    );

    _expectCheckmarkColor(
      find.byType(FilterChip),
      Colors.white.withAlpha(0xde),
    );
  });

  testWidgets('Input chip check mark color can be set by the chip theme', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedInputChip(),
      themeColor: const Color(0xff00ff00),
    );

    _expectCheckmarkColor(
      find.byType(InputChip),
      const Color(0xff00ff00),
    );
  });

  testWidgets('Filter chip check mark color can be set by the chip theme', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedFilterChip(),
      themeColor: const Color(0xff00ff00),
    );

    _expectCheckmarkColor(
      find.byType(FilterChip),
      const Color(0xff00ff00),
    );
  });

  testWidgets('Input chip check mark color can be set by the chip constructor', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedInputChip(checkmarkColor: const Color(0xff00ff00)),
    );

    _expectCheckmarkColor(
      find.byType(InputChip),
      const Color(0xff00ff00),
    );
  });

  testWidgets('Filter chip check mark color can be set by the chip constructor', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedFilterChip(checkmarkColor: const Color(0xff00ff00)),
    );

    _expectCheckmarkColor(
      find.byType(FilterChip),
      const Color(0xff00ff00),
    );
  });

  testWidgets('Input chip check mark color is set by chip constructor even when a theme color is specified', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedInputChip(checkmarkColor: const Color(0xffff0000)),
      themeColor: const Color(0xff00ff00),
    );

    _expectCheckmarkColor(
      find.byType(InputChip),
      const Color(0xffff0000),
    );
  });

  testWidgets('Filter chip check mark color is set by chip constructor even when a theme color is specified', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedFilterChip(checkmarkColor: const Color(0xffff0000)),
      themeColor: const Color(0xff00ff00),
    );

    _expectCheckmarkColor(
      find.byType(FilterChip),
      const Color(0xffff0000),
    );
  });
2524
}