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

5
import 'package:flutter/gestures.dart';
6
import 'package:flutter/material.dart';
7
import 'package:flutter/rendering.dart';
8
import 'package:flutter/scheduler.dart';
9
import 'package:flutter_test/flutter_test.dart';
10

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

15
Finder findRenderChipElement() {
16
  return find.byElementPredicate((Element e) => '${e.renderObject.runtimeType}' == '_RenderChip');
17
}
18

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

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

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

47
DefaultTextStyle getLabelStyle(WidgetTester tester, String labelText) {
48
  return tester.widget(
49 50
    find.ancestor(
      of: find.text(labelText),
51
      matching: find.byType(DefaultTextStyle),
52
    ).first,
53 54 55
  );
}

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

64
// ignore: avoid_dynamic_calls
65
double getSelectProgress(WidgetTester tester) => getRenderChip(tester)?.checkmarkAnimation?.value as double;
66
// ignore: avoid_dynamic_calls
67
double getAvatarDrawerProgress(WidgetTester tester) => getRenderChip(tester)?.avatarDrawerAnimation?.value as double;
68
// ignore: avoid_dynamic_calls
69
double getDeleteDrawerProgress(WidgetTester tester) => getRenderChip(tester)?.deleteDrawerAnimation?.value as double;
70
// ignore: avoid_dynamic_calls
71
double getEnableProgress(WidgetTester tester) => getRenderChip(tester)?.enableAnimation?.value as double;
72

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

92 93 94 95
/// 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.
96
Future<void> _testConstrainedLabel(
97
  WidgetTester tester, {
98 99
  CircleAvatar? avatar,
  VoidCallback? onDeleted,
100 101 102 103 104
}) async {
  const double labelWidth = 100.0;
  const double labelHeight = 50.0;
  const double chipParentWidth = 75.0;
  const double chipParentHeight = 25.0;
105
  final Key labelKey = UniqueKey();
106 107

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

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

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

136
Widget _selectedInputChip({ Color? checkmarkColor }) {
137 138 139 140 141 142 143 144
  return InputChip(
    label: const Text('InputChip'),
    selected: true,
    showCheckmark: true,
    checkmarkColor: checkmarkColor,
  );
}

145
Widget _selectedFilterChip({ Color? checkmarkColor }) {
146 147 148 149 150 151 152 153 154 155 156
  return FilterChip(
    label: const Text('InputChip'),
    selected: true,
    showCheckmark: true,
    checkmarkColor: checkmarkColor,
    onSelected: (bool _) { },
  );
}

Future<void> _pumpCheckmarkChip(
  WidgetTester tester, {
157 158
  required Widget chip,
  Color? themeColor,
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
  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,
          );
        },
174
      ),
175
    ),
176 177 178 179 180 181
  );
}

void _expectCheckmarkColor(Finder finder, Color color) {
  expect(
    finder,
182 183 184 185 186 187 188
    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),
189 190 191
  );
}

192 193
void _doNothing() {}

194
Widget _chipWithOptionalDeleteButton({
195 196
  Key? deleteButtonKey,
  Key? labelKey,
197
  required bool deletable,
198
  TextDirection textDirection = TextDirection.ltr,
199 200
  bool useDeleteButtonTooltip = true,
  String? chipTooltip,
201
  String? deleteButtonTooltipMessage,
202
  VoidCallback? onPressed = _doNothing,
203
}) {
204 205 206 207 208
  return _wrapForChip(
    textDirection: textDirection,
    child: Wrap(
      children: <Widget>[
        RawChip(
209
          tooltip: chipTooltip,
210 211
          onPressed: onPressed,
          onDeleted: deletable ? _doNothing : null,
212
          deleteIcon: Icon(Icons.close, key: deleteButtonKey),
213
          useDeleteButtonTooltip: useDeleteButtonTooltip,
214
          deleteButtonTooltipMessage: deleteButtonTooltipMessage,
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237
          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;
238 239
        final Offset center = arguments[0] as Offset;
        final double radius = arguments[1] as double;
240 241 242 243 244 245 246 247 248 249 250 251 252
        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;
253 254
        final Offset center = arguments[0] as Offset;
        final double radius = arguments[1] as double;
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
        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),
  );
}

272
void main() {
273
  testWidgets('Chip defaults', (WidgetTester tester) async {
274 275
    late TextTheme textTheme;

276 277 278 279 280
    Widget buildFrame(Brightness brightness) {
      return MaterialApp(
        theme: ThemeData(brightness: brightness),
        home: Scaffold(
          body: Center(
281 282 283 284 285 286 287 288 289
            child: Builder(
              builder: (BuildContext context) {
                textTheme = Theme.of(context).textTheme;
                return Chip(
                  avatar: const CircleAvatar(child: Text('A')),
                  label: const Text('Chip A'),
                  onDeleted: () { },
                );
              },
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildFrame(Brightness.light));
    expect(getMaterialBox(tester), paints..path(color: const Color(0x1f000000)));
    expect(tester.getSize(find.byType(Chip)), const Size(156.0, 48.0));
    expect(getMaterial(tester).color, null);
    expect(getMaterial(tester).elevation, 0);
    expect(getMaterial(tester).shape, const StadiumBorder());
    expect(getIconData(tester).color?.value, 0xffffffff);
    expect(getIconData(tester).opacity, null);
    expect(getIconData(tester).size, null);
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320

    TextStyle labelStyle = getLabelStyle(tester, 'Chip A').style;
    expect(labelStyle.color?.value, 0xde000000);
    expect(labelStyle.fontFamily, textTheme.bodyText1?.fontFamily);
    expect(labelStyle.fontFamilyFallback, textTheme.bodyText1?.fontFamilyFallback);
    expect(labelStyle.fontFeatures, textTheme.bodyText1?.fontFeatures);
    expect(labelStyle.fontSize, textTheme.bodyText1?.fontSize);
    expect(labelStyle.fontStyle, textTheme.bodyText1?.fontStyle);
    expect(labelStyle.fontWeight, textTheme.bodyText1?.fontWeight);
    expect(labelStyle.height, textTheme.bodyText1?.height);
    expect(labelStyle.inherit, textTheme.bodyText1?.inherit);
    expect(labelStyle.leadingDistribution, textTheme.bodyText1?.leadingDistribution);
    expect(labelStyle.letterSpacing, textTheme.bodyText1?.letterSpacing);
    expect(labelStyle.overflow, textTheme.bodyText1?.overflow);
    expect(labelStyle.textBaseline, textTheme.bodyText1?.textBaseline);
    expect(labelStyle.wordSpacing, textTheme.bodyText1?.wordSpacing);
321 322 323 324 325 326 327 328 329 330 331

    await tester.pumpWidget(buildFrame(Brightness.dark));
    await tester.pumpAndSettle(); // Theme transition animation
    expect(getMaterialBox(tester), paints..path(color: const Color(0x1fffffff)));
    expect(tester.getSize(find.byType(Chip)), const Size(156.0, 48.0));
    expect(getMaterial(tester).color, null);
    expect(getMaterial(tester).elevation, 0);
    expect(getMaterial(tester).shape, const StadiumBorder());
    expect(getIconData(tester).color?.value, 0xffffffff);
    expect(getIconData(tester).opacity, null);
    expect(getIconData(tester).size, null);
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

    labelStyle = getLabelStyle(tester, 'Chip A').style;
    expect(labelStyle.color?.value, 0xdeffffff);
    expect(labelStyle.fontFamily, textTheme.bodyText1?.fontFamily);
    expect(labelStyle.fontFamilyFallback, textTheme.bodyText1?.fontFamilyFallback);
    expect(labelStyle.fontFeatures, textTheme.bodyText1?.fontFeatures);
    expect(labelStyle.fontSize, textTheme.bodyText1?.fontSize);
    expect(labelStyle.fontStyle, textTheme.bodyText1?.fontStyle);
    expect(labelStyle.fontWeight, textTheme.bodyText1?.fontWeight);
    expect(labelStyle.height, textTheme.bodyText1?.height);
    expect(labelStyle.inherit, textTheme.bodyText1?.inherit);
    expect(labelStyle.leadingDistribution, textTheme.bodyText1?.leadingDistribution);
    expect(labelStyle.letterSpacing, textTheme.bodyText1?.letterSpacing);
    expect(labelStyle.overflow, textTheme.bodyText1?.overflow);
    expect(labelStyle.textBaseline, textTheme.bodyText1?.textBaseline);
    expect(labelStyle.wordSpacing, textTheme.bodyText1?.wordSpacing);
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
  });

  testWidgets('ChoiceChip defaults', (WidgetTester tester) async {
    Widget buildFrame(Brightness brightness) {
      return MaterialApp(
        theme: ThemeData(brightness: brightness),
        home: const Scaffold(
          body: Center(
            child: ChoiceChip(
              label: Text('Chip A'),
              selected: true,
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildFrame(Brightness.light));
    expect(getMaterialBox(tester), paints..path(color: const Color(0x3d000000)));
    expect(tester.getSize(find.byType(ChoiceChip)), const Size(108.0, 48.0));
    expect(getMaterial(tester).color, null);
    expect(getMaterial(tester).elevation, 0);
    expect(getMaterial(tester).shape, const StadiumBorder());
371
    expect(getLabelStyle(tester, 'Chip A').style.color?.value, 0xde000000);
372 373 374 375 376 377 378 379

    await tester.pumpWidget(buildFrame(Brightness.dark));
    await tester.pumpAndSettle(); // Theme transition animation
    expect(getMaterialBox(tester), paints..path(color: const Color(0x3dffffff)));
    expect(tester.getSize(find.byType(ChoiceChip)), const Size(108.0, 48.0));
    expect(getMaterial(tester).color, null);
    expect(getMaterial(tester).elevation, 0);
    expect(getMaterial(tester).shape, const StadiumBorder());
380
    expect(getLabelStyle(tester, 'Chip A').style.color?.value, 0xdeffffff);
381 382
  });

383
  testWidgets('Chip control test', (WidgetTester tester) async {
384
    final FeedbackTester feedback = FeedbackTester();
385
    final List<String> deletedChipLabels = <String>[];
386 387
    await tester.pumpWidget(
      _wrapForChip(
388
        child: Column(
389
          children: <Widget>[
390
            Chip(
391
              avatar: const CircleAvatar(child: Text('A')),
392 393 394 395 396 397
              label: const Text('Chip A'),
              onDeleted: () {
                deletedChipLabels.add('A');
              },
              deleteButtonTooltipMessage: 'Delete chip A',
            ),
398
            Chip(
399
              avatar: const CircleAvatar(child: Text('B')),
400 401 402 403 404 405 406 407
              label: const Text('Chip B'),
              onDeleted: () {
                deletedChipLabels.add('B');
              },
              deleteButtonTooltipMessage: 'Delete chip B',
            ),
          ],
        ),
408
      ),
409
    );
410

411 412 413
    expect(tester.widget(find.byTooltip('Delete chip A')), isNotNull);
    expect(tester.widget(find.byTooltip('Delete chip B')), isNotNull);

414 415
    expect(feedback.clickSoundCount, 0);

416 417 418
    expect(deletedChipLabels, isEmpty);
    await tester.tap(find.byTooltip('Delete chip A'));
    expect(deletedChipLabels, equals(<String>['A']));
419 420 421 422

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

423 424 425 426 427 428
    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);

429
    feedback.dispose();
430
  });
431

432
  testWidgets(
433 434 435 436 437 438 439 440 441 442
    '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(
443
            child: SizedBox(
444 445 446 447 448
              width: 500.0,
              height: 500.0,
              child: Column(
                children: <Widget>[
                  Chip(
449
                    label: SizedBox(
450 451 452 453
                      key: labelKey,
                      width: labelWidth,
                      height: labelHeight,
                    ),
454
                  ),
455 456
                ],
              ),
457 458 459
            ),
          ),
        ),
460
      );
461

462 463 464 465 466
      final Size labelSize = tester.getSize(find.byKey(labelKey));
      expect(labelSize.width, labelWidth);
      expect(labelSize.height, labelHeight);
    },
  );
467

468
  testWidgets(
469 470 471 472 473 474
    'Chip constrains the size of the label widget when it exceeds the '
    'available space',
    (WidgetTester tester) async {
      await _testConstrainedLabel(tester);
    },
  );
475

476
  testWidgets(
477 478 479 480 481 482 483 484 485
    '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')),
      );
    },
  );
486

487
  testWidgets(
488 489 490 491 492 493 494 495 496
    '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: () { },
      );
    },
  );
497

498
  testWidgets(
499 500 501 502 503 504 505 506 507 508
    '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: () { },
      );
    },
  );
509

510
  testWidgets(
511 512 513 514
    '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
515
      Widget chipBuilder (String text, {Widget? avatar, VoidCallback? onDeleted}) {
516 517
        return MaterialApp(
          home: Scaffold(
518
            body: SizedBox(
519 520 521 522 523 524 525 526
              width: 150,
              child: Column(
                children: <Widget>[
                  Chip(
                    avatar: avatar,
                    label: Text(text),
                    onDeleted: onDeleted,
                  ),
527
                ],
528
              ),
529 530
            ),
          ),
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
        );
      }

      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);
    },
  );
584

585
  testWidgets('Chip in row works ok', (WidgetTester tester) async {
586
    const TextStyle style = TextStyle(fontFamily: 'Ahem', fontSize: 10.0);
587
    await tester.pumpWidget(
588
      _wrapForChip(
589
        child: Row(
590
          children: const <Widget>[
591
            Chip(label: Text('Test'), labelStyle: style),
592
          ],
593 594 595
        ),
      ),
    );
596
    expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0));
597
    expect(tester.getSize(find.byType(Chip)), const Size(64.0, 48.0));
598
    await tester.pumpWidget(
599
      _wrapForChip(
600
        child: Row(
601
          children: const <Widget>[
602
            Flexible(child: Chip(label: Text('Test'), labelStyle: style)),
603
          ],
604 605 606 607
        ),
      ),
    );
    expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0));
608
    expect(tester.getSize(find.byType(Chip)), const Size(64.0, 48.0));
609
    await tester.pumpWidget(
610
      _wrapForChip(
611
        child: Row(
612
          children: const <Widget>[
613
            Expanded(child: Chip(label: Text('Test'), labelStyle: style)),
614
          ],
615 616 617 618
        ),
      ),
    );
    expect(tester.getSize(find.byType(Text)), const Size(40.0, 10.0));
619
    expect(tester.getSize(find.byType(Chip)), const Size(800.0, 48.0));
620
  });
621

622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
  testWidgets('Chip responds to materialTapTargetSize', (WidgetTester tester) async {
      await tester.pumpWidget(
        _wrapForChip(
          child: Column(
            children: const <Widget>[
              Chip(
                label: Text('X'),
                materialTapTargetSize: MaterialTapTargetSize.padded,
              ),
              Chip(
                label: Text('X'),
                materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
              ),
            ],
          ),
        ),
      );
      expect(tester.getSize(find.byType(Chip).first), const Size(48.0, 48.0));
      expect(tester.getSize(find.byType(Chip).last), const Size(38.0, 32.0));
    },
  );

644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
  testWidgets('delete button tap target is the right proportion of the chip', (WidgetTester tester) async {
    final UniqueKey deleteKey = UniqueKey();
    bool calledDelete = false;
    await tester.pumpWidget(
      _wrapForChip(
        child: Column(
          children: <Widget>[
            Chip(
              label: const Text('Really Long Label'),
              deleteIcon: Icon(Icons.delete, key: deleteKey),
              onDeleted: () {
                calledDelete = true;
              },
            ),
          ],
        ),
      ),
    );
    await tester.tapAt(tester.getCenter(find.byKey(deleteKey)) - const Offset(24.0, 0.0));
    await tester.pump();
    expect(calledDelete, isTrue);
    calledDelete = false;

    await tester.tapAt(tester.getCenter(find.byKey(deleteKey)) - const Offset(25.0, 0.0));
    await tester.pump();
    expect(calledDelete, isFalse);
    calledDelete = false;

    await tester.pumpWidget(
      _wrapForChip(
        child: Column(
          children: <Widget>[
            Chip(
              label: const SizedBox(), // Short label
678
              deleteIcon: Icon(Icons.cancel, key: deleteKey),
679 680 681 682 683 684 685 686
              onDeleted: () {
                calledDelete = true;
              },
            ),
          ],
        ),
      ),
    );
687 688 689 690 691 692 693

    // Chip width is 48 with padding, 40 without padding, so halfway is at 20. Cancel
    // icon is 24x24, so since 24 > 20 the split location should be halfway across the
    // chip, which is at 12 + 8 = 20 from the right side. Since the split is just
    // slightly less than 50%, 8 from the center of the delete button should hit the
    // chip, not the delete button.
    await tester.tapAt(tester.getCenter(find.byKey(deleteKey)) - const Offset(7.0, 0.0));
694 695 696 697
    await tester.pump();
    expect(calledDelete, isTrue);
    calledDelete = false;

698
    await tester.tapAt(tester.getCenter(find.byKey(deleteKey)) - const Offset(8.0, 0.0));
699 700 701 702
    await tester.pump();
    expect(calledDelete, isFalse);
  });

703
  testWidgets('Chip elements are ordered horizontally for locale', (WidgetTester tester) async {
704 705
    final UniqueKey iconKey = UniqueKey();
    final Widget test = Overlay(
706
      initialEntries: <OverlayEntry>[
707
        OverlayEntry(
708
          builder: (BuildContext context) {
709 710 711
            return Material(
              child: Chip(
                deleteIcon: Icon(Icons.delete, key: iconKey),
712
                onDeleted: () { },
713
                label: const Text('ABC'),
714 715 716 717 718 719 720 721
              ),
            );
          },
        ),
      ],
    );

    await tester.pumpWidget(
722 723 724
      _wrapForChip(
        child: test,
        textDirection: TextDirection.rtl,
725 726
      ),
    );
727 728
    await tester.pumpAndSettle(const Duration(milliseconds: 500));
    expect(tester.getCenter(find.text('ABC')).dx, greaterThan(tester.getCenter(find.byKey(iconKey)).dx));
729
    await tester.pumpWidget(
730 731
      _wrapForChip(
        child: test,
732 733
      ),
    );
734 735
    await tester.pumpAndSettle(const Duration(milliseconds: 500));
    expect(tester.getCenter(find.text('ABC')).dx, lessThan(tester.getCenter(find.byKey(iconKey)).dx));
736 737
  });

738 739
  testWidgets('Chip responds to textScaleFactor', (WidgetTester tester) async {
    await tester.pumpWidget(
740
      _wrapForChip(
741
        child: Column(
742
          children: const <Widget>[
743 744 745
            Chip(
              avatar: CircleAvatar(child: Text('A')),
              label: Text('Chip A'),
746
            ),
747 748 749
            Chip(
              avatar: CircleAvatar(child: Text('B')),
              label: Text('Chip B'),
750 751
            ),
          ],
752 753 754 755 756 757 758 759
        ),
      ),
    );

    // 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')),
760
      anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)),
761 762 763
    );
    expect(
      tester.getSize(find.text('Chip B')),
764
      anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)),
765
    );
766 767
    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)));
768 769

    await tester.pumpWidget(
770 771
      _wrapForChip(
        textScaleFactor: 3.0,
772
        child: Column(
773
          children: const <Widget>[
774 775 776
            Chip(
              avatar: CircleAvatar(child: Text('A')),
              label: Text('Chip A'),
777
            ),
778 779 780
            Chip(
              avatar: CircleAvatar(child: Text('B')),
              label: Text('Chip B'),
781 782
            ),
          ],
783 784 785 786 787 788
        ),
      ),
    );

    // TODO(gspencer): Update this test when the font metric bug is fixed to remove the anyOfs.
    // https://github.com/flutter/flutter/issues/12357
789 790
    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)));
791
    expect(tester.getSize(find.byType(Chip).first).width, anyOf(310.0, 311.0));
792
    expect(tester.getSize(find.byType(Chip).first).height, equals(50.0));
793
    expect(tester.getSize(find.byType(Chip).last).width, anyOf(310.0, 311.0));
794
    expect(tester.getSize(find.byType(Chip).last).height, equals(50.0));
795 796 797

    // Check that individual text scales are taken into account.
    await tester.pumpWidget(
798
      _wrapForChip(
799
        child: Column(
800
          children: const <Widget>[
801 802 803
            Chip(
              avatar: CircleAvatar(child: Text('A')),
              label: Text('Chip A', textScaleFactor: 3.0),
804
            ),
805 806 807
            Chip(
              avatar: CircleAvatar(child: Text('B')),
              label: Text('Chip B'),
808 809
            ),
          ],
810 811 812 813 814 815
        ),
      ),
    );

    // TODO(gspencer): Update this test when the font metric bug is fixed to remove the anyOfs.
    // https://github.com/flutter/flutter/issues/12357
816 817
    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)));
818 819
    expect(tester.getSize(find.byType(Chip).first).width, anyOf(318.0, 319.0));
    expect(tester.getSize(find.byType(Chip).first).height, equals(50.0));
820
    expect(tester.getSize(find.byType(Chip).last), anyOf(const Size(132.0, 48.0), const Size(131.0, 48.0)));
821
  });
822 823

  testWidgets('Labels can be non-text widgets', (WidgetTester tester) async {
824 825
    final Key keyA = GlobalKey();
    final Key keyB = GlobalKey();
826
    await tester.pumpWidget(
827
      _wrapForChip(
828
        child: Column(
829
          children: <Widget>[
830
            Chip(
831
              avatar: const CircleAvatar(child: Text('A')),
832
              label: Text('Chip A', key: keyA),
833
            ),
834
            Chip(
835
              avatar: const CircleAvatar(child: Text('B')),
836
              label: SizedBox(key: keyB, width: 10.0, height: 10.0),
837 838
            ),
          ],
839 840 841 842 843 844 845 846
        ),
      ),
    );

    // 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)),
847
      anyOf(const Size(84.0, 14.0), const Size(83.0, 14.0)),
848 849 850 851
    );
    expect(tester.getSize(find.byKey(keyB)), const Size(10.0, 10.0));
    expect(
      tester.getSize(find.byType(Chip).first),
852
      anyOf(const Size(132.0, 48.0), const Size(131.0, 48.0)),
853
    );
854
    expect(tester.getSize(find.byType(Chip).last), const Size(58.0, 48.0));
855
  });
856

857
  testWidgets('Avatars can be non-circle avatar widgets', (WidgetTester tester) async {
858
    final Key keyA = GlobalKey();
859
    await tester.pumpWidget(
860
      _wrapForChip(
861
        child: Column(
862
          children: <Widget>[
863
            Chip(
864
              avatar: SizedBox(key: keyA, width: 20.0, height: 20.0),
865 866 867
              label: const Text('Chip A'),
            ),
          ],
868 869 870 871 872 873 874 875
        ),
      ),
    );

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

  testWidgets('Delete icons can be non-icon widgets', (WidgetTester tester) async {
876
    final Key keyA = GlobalKey();
877
    await tester.pumpWidget(
878
      _wrapForChip(
879
        child: Column(
880
          children: <Widget>[
881
            Chip(
882
              deleteIcon: SizedBox(key: keyA, width: 20.0, height: 20.0),
883
              label: const Text('Chip A'),
884
              onDeleted: () { },
885 886
            ),
          ],
887 888 889 890 891 892 893
        ),
      ),
    );

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

894
  testWidgets('Chip padding - LTR', (WidgetTester tester) async {
895 896
    final GlobalKey keyA = GlobalKey();
    final GlobalKey keyB = GlobalKey();
897
    await tester.pumpWidget(
898
      _wrapForChip(
899
        child: Overlay(
900
          initialEntries: <OverlayEntry>[
901
            OverlayEntry(
902
              builder: (BuildContext context) {
903 904 905 906
                return Material(
                  child: Center(
                    child: Chip(
                      avatar: Placeholder(key: keyA),
907
                      label: SizedBox(
908 909 910
                        key: keyB,
                        width: 40.0,
                        height: 40.0,
911
                      ),
912
                      onDeleted: () { },
913
                    ),
914 915 916 917 918
                  ),
                );
              },
            ),
          ],
919 920 921
        ),
      ),
    );
922 923
    expect(tester.getTopLeft(find.byKey(keyA)), const Offset(332.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyA)), const Offset(372.0, 320.0));
924 925
    expect(tester.getTopLeft(find.byKey(keyB)), const Offset(380.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyB)), const Offset(420.0, 320.0));
926 927
    expect(tester.getTopLeft(find.byType(Icon)), const Offset(439.0, 291.0));
    expect(tester.getBottomRight(find.byType(Icon)), const Offset(457.0, 309.0));
928 929 930
  });

  testWidgets('Chip padding - RTL', (WidgetTester tester) async {
931 932
    final GlobalKey keyA = GlobalKey();
    final GlobalKey keyB = GlobalKey();
933
    await tester.pumpWidget(
934 935
      _wrapForChip(
        textDirection: TextDirection.rtl,
936
        child: Overlay(
937
          initialEntries: <OverlayEntry>[
938
            OverlayEntry(
939
              builder: (BuildContext context) {
940 941 942 943
                return Material(
                  child: Center(
                    child: Chip(
                      avatar: Placeholder(key: keyA),
944
                      label: SizedBox(
945 946 947
                        key: keyB,
                        width: 40.0,
                        height: 40.0,
948
                      ),
949
                      onDeleted: () { },
950
                    ),
951 952 953 954 955
                  ),
                );
              },
            ),
          ],
956 957 958
        ),
      ),
    );
959

960 961
    expect(tester.getTopLeft(find.byKey(keyA)), const Offset(428.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyA)), const Offset(468.0, 320.0));
962 963
    expect(tester.getTopLeft(find.byKey(keyB)), const Offset(380.0, 280.0));
    expect(tester.getBottomRight(find.byKey(keyB)), const Offset(420.0, 320.0));
964 965 966 967 968
    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 {
969
    final GlobalKey labelKey = GlobalKey();
970
    Future<void> pushChip({ Widget? avatar }) async {
971
      return tester.pumpWidget(
972
        _wrapForChip(
973
          child: Wrap(
974
            children: <Widget>[
975
              RawChip(
976
                avatar: avatar,
977
                label: Text('Chip', key: labelKey),
978 979 980
                shape: const StadiumBorder(),
              ),
            ],
981 982 983 984 985 986 987
          ),
        ),
      );
    }

    // No avatar
    await pushChip();
988
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
989
    final GlobalKey avatarKey = GlobalKey();
990 991 992

    // Add an avatar
    await pushChip(
993
      avatar: Container(
994 995 996 997 998 999 1000
        key: avatarKey,
        color: const Color(0xff000000),
        width: 40.0,
        height: 40.0,
      ),
    );
    // Avatar drawer should start out closed.
1001
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
1002
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1003 1004
    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)));
1005 1006 1007

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

    await tester.pump(const Duration(milliseconds: 20));
1014
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(86.7, epsilon: 0.1));
1015
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1016 1017
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, moreOrLessEquals(-13.3, epsilon: 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, moreOrLessEquals(18.6, epsilon: 0.1));
1018 1019

    await tester.pump(const Duration(milliseconds: 20));
1020
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(94.7, epsilon: 0.1));
1021
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1022 1023
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, moreOrLessEquals(-5.3, epsilon: 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, moreOrLessEquals(26.7, epsilon: 0.1));
1024 1025

    await tester.pump(const Duration(milliseconds: 20));
1026
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(99.5, epsilon: 0.1));
1027
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1028 1029
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, moreOrLessEquals(-0.5, epsilon: 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, moreOrLessEquals(31.5, epsilon: 0.1));
1030 1031 1032 1033

    // Wait for being done with animation, and make sure it didn't change
    // height.
    await tester.pumpAndSettle(const Duration(milliseconds: 200));
1034
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
1035
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1036 1037
    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)));
1038 1039 1040 1041

    // Remove the avatar again
    await pushChip();
    // Avatar drawer should start out open.
1042
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
1043
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1044 1045
    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)));
1046 1047 1048

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

    await tester.pump(const Duration(milliseconds: 20));
1055
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(98.0, epsilon: 0.1));
1056
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1057 1058
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, moreOrLessEquals(-2.0, epsilon: 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, moreOrLessEquals(30.0, epsilon: 0.1));
1059 1060

    await tester.pump(const Duration(milliseconds: 20));
1061
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(84.1, epsilon: 0.1));
1062
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1063 1064
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, moreOrLessEquals(-15.9, epsilon: 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, moreOrLessEquals(16.1, epsilon: 0.1));
1065 1066

    await tester.pump(const Duration(milliseconds: 20));
1067
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(80.0, epsilon: 0.1));
1068
    expect(tester.getSize(find.byKey(avatarKey)), equals(const Size(24.0, 24.0)));
1069 1070
    expect(tester.getTopLeft(find.byKey(avatarKey)).dx, moreOrLessEquals(-20.0, epsilon: 0.1));
    expect(tester.getTopLeft(find.byKey(labelKey)).dx, moreOrLessEquals(12.0, epsilon: 0.1));
1071 1072 1073 1074

    // 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));
1075 1076
    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)));
1077
    expect(find.byKey(avatarKey), findsNothing);
1078
  });
1079 1080

  testWidgets('Delete button drawer works as expected on RawChip', (WidgetTester tester) async {
1081 1082
    const Key labelKey = Key('label');
    const Key deleteButtonKey = Key('delete');
1083
    bool wasDeleted = false;
1084
    Future<void> pushChip({ bool deletable = false }) async {
1085
      return tester.pumpWidget(
1086
        _wrapForChip(
1087
          child: Wrap(
1088
            children: <Widget>[
1089 1090
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1091
                  onDeleted: deletable
1092 1093 1094 1095 1096 1097
                    ? () {
                        setState(() {
                          wasDeleted = true;
                        });
                      }
                    : null,
1098 1099
                  deleteIcon: Container(width: 40.0, height: 40.0, color: Colors.blue, key: deleteButtonKey),
                  label: const Text('Chip', key: labelKey),
1100 1101 1102 1103
                  shape: const StadiumBorder(),
                );
              }),
            ],
1104 1105 1106 1107 1108 1109 1110
          ),
        ),
      );
    }

    // No delete button
    await pushChip();
1111
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
1112 1113 1114 1115

    // Add a delete button
    await pushChip(deletable: true);
    // Delete button drawer should start out closed.
1116
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(80.0, 48.0)));
1117
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1118 1119
    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)));
1120 1121 1122

    await tester.pump(const Duration(milliseconds: 20));
    // Delete button drawer should start expanding.
1123
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(81.2, epsilon: 0.1));
1124
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1125
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(53.2, epsilon: 0.1));
1126
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
1127 1128

    await tester.pump(const Duration(milliseconds: 20));
1129
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(86.7, epsilon: 0.1));
1130
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1131
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(58.7, epsilon: 0.1));
1132 1133

    await tester.pump(const Duration(milliseconds: 20));
1134
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(94.7, epsilon: 0.1));
1135
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1136
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(66.7, epsilon: 0.1));
1137 1138

    await tester.pump(const Duration(milliseconds: 20));
1139
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(99.5, epsilon: 0.1));
1140
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1141
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(71.5, epsilon: 0.1));
1142 1143 1144 1145

    // Wait for being done with animation, and make sure it didn't change
    // height.
    await tester.pumpAndSettle(const Duration(milliseconds: 200));
1146
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
1147
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1148 1149
    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)));
1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160

    // 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.
1161
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(104.0, 48.0)));
1162
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1163 1164
    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)));
1165 1166 1167

    await tester.pump(const Duration(milliseconds: 20));
    // Delete button drawer should start contracting.
1168
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(103.8, epsilon: 0.1));
1169
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1170
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(75.8, epsilon: 0.1));
1171
    expect(tester.getTopLeft(find.byKey(labelKey)), equals(const Offset(12.0, 17.0)));
1172 1173

    await tester.pump(const Duration(milliseconds: 20));
1174
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(102.9, epsilon: 0.1));
1175
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1176
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(74.9, epsilon: 0.1));
1177 1178

    await tester.pump(const Duration(milliseconds: 20));
1179
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(101.0, epsilon: 0.1));
1180
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1181
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(73.0, epsilon: 0.1));
1182 1183

    await tester.pump(const Duration(milliseconds: 20));
1184
    expect(tester.getSize(find.byType(RawChip)).width, moreOrLessEquals(97.5, epsilon: 0.1));
1185
    expect(tester.getSize(find.byKey(deleteButtonKey)), equals(const Size(24.0, 24.0)));
1186
    expect(tester.getTopLeft(find.byKey(deleteButtonKey)).dx, moreOrLessEquals(69.5, epsilon: 0.1));
1187 1188 1189 1190

    // 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));
1191 1192
    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)));
1193
    expect(find.byKey(deleteButtonKey), findsNothing);
1194
  });
1195

1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231
  testWidgets('Delete button takes up at most half of the chip', (WidgetTester tester) async {
    final UniqueKey chipKey = UniqueKey();
    bool chipPressed = false;
    bool deletePressed = false;

    await tester.pumpWidget(
      _wrapForChip(
        child: Wrap(
          children: <Widget>[
            RawChip(
              key: chipKey,
              onPressed: () {
                chipPressed = true;
              },
              onDeleted: () {
                deletePressed = true;
              },
              label: const Text(''),
              ),
          ],
        ),
      ),
    );

    await tester.tapAt(tester.getCenter(find.byKey(chipKey)));
    await tester.pump();
    expect(chipPressed, isTrue);
    expect(deletePressed, isFalse);
    chipPressed = false;

    await tester.tapAt(tester.getCenter(find.byKey(chipKey)) + const Offset(1.0, 0.0));
    await tester.pump();
    expect(chipPressed, isFalse);
    expect(deletePressed, isTrue);
  });

1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278
  testWidgets('Chip creates centered, unique ripple when label is tapped', (WidgetTester tester) async {
    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 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();
1279
  });
1280

1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313
  testWidgets('Delete button is focusable', (WidgetTester tester) async {
    final GlobalKey labelKey = GlobalKey();
    final GlobalKey deleteButtonKey = GlobalKey();

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

    Focus.of(deleteButtonKey.currentContext!).requestFocus();
    await tester.pump();

    // They shouldn't have the same focus node.
    expect(Focus.of(deleteButtonKey.currentContext!), isNot(equals(Focus.of(labelKey.currentContext!))));
    expect(Focus.of(deleteButtonKey.currentContext!).hasFocus, isTrue);
    expect(Focus.of(deleteButtonKey.currentContext!).hasPrimaryFocus, isTrue);
    // Delete button is a child widget of the Chip, so the Chip should have focus if
    // the delete button does.
    expect(Focus.of(labelKey.currentContext!).hasFocus, isTrue);
    expect(Focus.of(labelKey.currentContext!).hasPrimaryFocus, isFalse);

    Focus.of(labelKey.currentContext!).requestFocus();
    await tester.pump();

    expect(Focus.of(deleteButtonKey.currentContext!).hasFocus, isFalse);
    expect(Focus.of(deleteButtonKey.currentContext!).hasPrimaryFocus, isFalse);
    expect(Focus.of(labelKey.currentContext!).hasFocus, isTrue);
    expect(Focus.of(labelKey.currentContext!).hasPrimaryFocus, isTrue);
  });

1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337
  testWidgets('Delete button creates non-centered, unique ripple when tapped', (WidgetTester tester) async {
    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));

1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390
    // There should be one unique ink ripple.
    expect(box, ripplePattern(const Offset(3.0, 3.0), 1.44));
    expect(box, uniqueRipplePattern(const Offset(3.0, 3.0), 1.44));

    // 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), 4.32));
    expect(box, uniqueRipplePattern(const Offset(5.0, 5.0), 4.32));

    // 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();
  });

  testWidgets('Delete button in a chip with null onPressed creates ripple when tapped', (WidgetTester tester) async {
    final UniqueKey labelKey = UniqueKey();
    final UniqueKey deleteButtonKey = UniqueKey();

    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        labelKey: labelKey,
        onPressed: null,
        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));
1391 1392

    // There should be one unique ink ripple.
1393 1394
    expect(box, ripplePattern(const Offset(3.0, 3.0), 1.44));
    expect(box, uniqueRipplePattern(const Offset(3.0, 3.0), 1.44));
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404

    // 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.
1405 1406
    expect(box, ripplePattern(const Offset(5.0, 5.0), 4.32));
    expect(box, uniqueRipplePattern(const Offset(5.0, 5.0), 4.32));
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418

    // 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();
1419
  });
1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436

  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.
1437
    final Offset topLeftOfInkWell = tester.getTopLeft(find.byType(InkWell).first);
1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448
    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();
1449
  });
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502

  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();
1503
  });
1504 1505 1506

  testWidgets('Selection with avatar works as expected on RawChip', (WidgetTester tester) async {
    bool selected = false;
1507
    final UniqueKey labelKey = UniqueKey();
1508
    Future<void> pushChip({ Widget? avatar, bool selectable = false }) async {
1509
      return tester.pumpWidget(
1510
        _wrapForChip(
1511
          child: Wrap(
1512
            children: <Widget>[
1513 1514
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1515 1516
                  avatar: avatar,
                  onSelected: selectable != null
1517 1518 1519 1520 1521 1522
                    ? (bool value) {
                        setState(() {
                          selected = value;
                        });
                      }
                    : null,
1523
                  selected: selected,
1524
                  label: Text('Long Chip Label', key: labelKey),
1525 1526 1527 1528
                  shape: const StadiumBorder(),
                );
              }),
            ],
1529 1530 1531 1532 1533 1534
          ),
        ),
      );
    }

    // With avatar, but not selectable.
1535
    final UniqueKey avatarKey = UniqueKey();
1536
    await pushChip(
1537
      avatar: SizedBox(width: 40.0, height: 40.0, key: avatarKey),
1538
    );
1539
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(258.0, 48.0)));
1540 1541 1542

    // Turn on selection.
    await pushChip(
1543
      avatar: SizedBox(width: 40.0, height: 40.0, key: avatarKey),
1544 1545 1546 1547 1548 1549 1550
      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));
1551
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
1552 1553
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
1554
    expect(getSelectProgress(tester), moreOrLessEquals(0.002, epsilon: 0.01));
1555 1556 1557
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 50));
1558
    expect(getSelectProgress(tester), moreOrLessEquals(0.54, epsilon: 0.01));
1559 1560 1561 1562 1563 1564 1565 1566 1567 1568
    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));
1569
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
1570 1571
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 20));
1572
    expect(getSelectProgress(tester), moreOrLessEquals(0.875, epsilon: 0.01));
1573 1574 1575
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 20));
1576
    expect(getSelectProgress(tester), moreOrLessEquals(0.13, epsilon: 0.01));
1577 1578 1579 1580 1581 1582
    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));
1583
  });
1584 1585 1586

  testWidgets('Selection without avatar works as expected on RawChip', (WidgetTester tester) async {
    bool selected = false;
1587
    final UniqueKey labelKey = UniqueKey();
1588
    Future<void> pushChip({ bool selectable = false }) async {
1589
      return tester.pumpWidget(
1590
        _wrapForChip(
1591
          child: Wrap(
1592
            children: <Widget>[
1593 1594
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1595
                  onSelected: selectable != null
1596 1597 1598 1599 1600 1601
                    ? (bool value) {
                        setState(() {
                          selected = value;
                        });
                      }
                    : null,
1602
                  selected: selected,
1603
                  label: Text('Long Chip Label', key: labelKey),
1604 1605 1606 1607
                  shape: const StadiumBorder(),
                );
              }),
            ],
1608 1609 1610 1611 1612 1613 1614
          ),
        ),
      );
    }

    // Without avatar, but not selectable.
    await pushChip();
1615
    expect(tester.getSize(find.byType(RawChip)), equals(const Size(234.0, 48.0)));
1616 1617 1618 1619 1620 1621 1622 1623

    // 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));
1624
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
1625 1626
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
1627 1628
    expect(getSelectProgress(tester), moreOrLessEquals(0.002, epsilon: 0.01));
    expect(getAvatarDrawerProgress(tester), moreOrLessEquals(0.459, epsilon: 0.01));
1629 1630
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 50));
1631 1632
    expect(getSelectProgress(tester), moreOrLessEquals(0.54, epsilon: 0.01));
    expect(getAvatarDrawerProgress(tester), moreOrLessEquals(0.92, epsilon: 0.01));
1633 1634 1635 1636 1637 1638 1639 1640 1641
    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));
1642
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
1643 1644
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 20));
1645 1646
    expect(getSelectProgress(tester), moreOrLessEquals(0.875, epsilon: 0.01));
    expect(getAvatarDrawerProgress(tester), moreOrLessEquals(0.96, epsilon: 0.01));
1647 1648
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 20));
1649 1650
    expect(getSelectProgress(tester), moreOrLessEquals(0.13, epsilon: 0.01));
    expect(getAvatarDrawerProgress(tester), moreOrLessEquals(0.75, epsilon: 0.01));
1651 1652 1653 1654 1655
    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));
1656
  });
1657 1658 1659

  testWidgets('Activation works as expected on RawChip', (WidgetTester tester) async {
    bool selected = false;
1660
    final UniqueKey labelKey = UniqueKey();
1661
    Future<void> pushChip({ Widget? avatar, bool selectable = false }) async {
1662
      return tester.pumpWidget(
1663
        _wrapForChip(
1664
          child: Wrap(
1665
            children: <Widget>[
1666 1667
              StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
                return RawChip(
1668 1669
                  avatar: avatar,
                  onSelected: selectable != null
1670 1671 1672 1673 1674 1675
                    ? (bool value) {
                        setState(() {
                          selected = value;
                        });
                      }
                    : null,
1676
                  selected: selected,
1677
                  label: Text('Long Chip Label', key: labelKey),
1678 1679 1680 1681 1682
                  shape: const StadiumBorder(),
                  showCheckmark: false,
                );
              }),
            ],
1683 1684 1685 1686 1687
          ),
        ),
      );
    }

1688
    final UniqueKey avatarKey = UniqueKey();
1689
    await pushChip(
1690
      avatar: SizedBox(width: 40.0, height: 40.0, key: avatarKey),
1691 1692 1693 1694 1695 1696
      selectable: true,
    );
    await tester.pumpAndSettle();

    await tester.tap(find.byKey(labelKey));
    expect(selected, equals(true));
1697
    expect(SchedulerBinding.instance.transientCallbackCount, equals(2));
1698 1699
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 50));
1700
    expect(getSelectProgress(tester), moreOrLessEquals(0.002, epsilon: 0.01));
1701 1702 1703
    expect(getAvatarDrawerProgress(tester), equals(1.0));
    expect(getDeleteDrawerProgress(tester), equals(0.0));
    await tester.pump(const Duration(milliseconds: 50));
1704
    expect(getSelectProgress(tester), moreOrLessEquals(0.54, epsilon: 0.01));
1705 1706 1707 1708 1709 1710 1711
    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();
1712
  });
1713 1714

  testWidgets('Chip uses ThemeData chip theme if present', (WidgetTester tester) async {
1715
    final ThemeData theme = ThemeData(
1716 1717 1718 1719 1720 1721 1722
      platform: TargetPlatform.android,
      primarySwatch: Colors.red,
    );
    final ChipThemeData chipTheme = theme.chipTheme;

    Widget buildChip(ChipThemeData data) {
      return _wrapForChip(
1723
        child: Theme(
1724 1725
          data: theme,
          child: const InputChip(
1726
            label: Text('Label'),
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
          ),
        ),
      );
    }

    await tester.pumpWidget(buildChip(chipTheme));

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

1741
    expect(materialBox, paints..path(color: chipTheme.disabledColor));
1742 1743
  });

1744 1745 1746
  testWidgets('Chip merges ChipThemeData label style with the provided label style', (WidgetTester tester) async {
    // The font family should be preserved even if the chip overrides some label style properties
    final ThemeData theme = ThemeData(
1747
      fontFamily: 'MyFont',
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
    );

    Widget buildChip() {
      return _wrapForChip(
        child: Theme(
          data: theme,
          child: const Chip(
            label: Text('Label'),
            labelStyle: TextStyle(fontWeight: FontWeight.w200),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildChip());

1764
    final TextStyle labelStyle = getLabelStyle(tester, 'Label').style;
1765
    expect(labelStyle.inherit, false);
1766 1767 1768 1769
    expect(labelStyle.fontFamily, 'MyFont');
    expect(labelStyle.fontWeight, FontWeight.w200);
  });

1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813
  testWidgets('ChipTheme labelStyle with inherit:true', (WidgetTester tester) async {
    Widget buildChip() {
      return _wrapForChip(
        child: Theme(
          data: ThemeData.light().copyWith(
            chipTheme: const ChipThemeData(
              labelStyle: TextStyle(height: 4), // inherit: true
            ),
          ),
          child: const Chip(label: Text('Label')), // labeStyle: null
        ),
      );
    }

    await tester.pumpWidget(buildChip());
    final TextStyle labelStyle = getLabelStyle(tester, 'Label').style;
    expect(labelStyle.inherit, true); // because chipTheme.labelStyle.merge(null)
    expect(labelStyle.height, 4);
  });

  testWidgets('Chip does not merge inherit:false label style with the theme label style', (WidgetTester tester) async {
    Widget buildChip() {
      return _wrapForChip(
        child: Theme(
          data: ThemeData(fontFamily: 'MyFont'),
          child: const DefaultTextStyle(
            style: TextStyle(height: 8),
            child: Chip(
              label: Text('Label'),
              labelStyle: TextStyle(fontWeight: FontWeight.w200, inherit: false),
            ),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildChip());
    final TextStyle labelStyle = getLabelStyle(tester, 'Label').style;
    expect(labelStyle.inherit, false);
    expect(labelStyle.fontFamily, null);
    expect(labelStyle.height, null);
    expect(labelStyle.fontWeight, FontWeight.w200);
  });

1814
  testWidgets('Chip size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
1815
    final Key key1 = UniqueKey();
1816 1817
    await tester.pumpWidget(
      _wrapForChip(
1818 1819 1820 1821
        child: Theme(
          data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded),
          child: Center(
            child: RawChip(
1822 1823 1824 1825 1826 1827 1828 1829 1830 1831
              key: key1,
              label: const Text('test'),
            ),
          ),
        ),
      ),
    );

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

1832
    final Key key2 = UniqueKey();
1833 1834
    await tester.pumpWidget(
      _wrapForChip(
1835 1836 1837 1838
        child: Theme(
          data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap),
          child: Center(
            child: RawChip(
1839 1840 1841 1842 1843 1844 1845 1846 1847
              key: key2,
              label: const Text('test'),
            ),
          ),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(key2)), const Size(80.0, 32.0));
1848
  });
1849

1850
  testWidgets('Chip uses the right theme colors for the right components', (WidgetTester tester) async {
1851
    final ThemeData themeData = ThemeData(
1852 1853 1854
      platform: TargetPlatform.android,
      primarySwatch: Colors.blue,
    );
1855 1856 1857 1858 1859
    final ChipThemeData defaultChipTheme = ChipThemeData.fromDefaults(
      brightness: themeData.brightness,
      secondaryColor: Colors.blue,
      labelStyle: themeData.textTheme.bodyText1!,
    );
1860 1861
    bool value = false;
    Widget buildApp({
1862 1863 1864
      ChipThemeData? chipTheme,
      Widget? avatar,
      Widget? deleteIcon,
1865 1866 1867 1868
      bool isSelectable = true,
      bool isPressable = false,
      bool isDeletable = true,
      bool showCheckmark = true,
1869
    }) {
1870
      chipTheme ??= defaultChipTheme;
1871
      return _wrapForChip(
1872
        child: Theme(
1873
          data: themeData,
1874
          child: ChipTheme(
1875
            data: chipTheme,
1876 1877
            child: StatefulBuilder(builder: (BuildContext context, StateSetter setState) {
              return RawChip(
1878
                showCheckmark: showCheckmark,
1879
                onDeleted: isDeletable ? () { } : null,
1880 1881 1882
                avatar: avatar,
                deleteIcon: deleteIcon,
                isEnabled: isSelectable || isPressable,
1883
                shape: chipTheme?.shape,
1884
                selected: isSelectable && value,
1885
                label: Text('$value'),
1886
                onSelected: isSelectable
1887 1888 1889 1890 1891 1892
                  ? (bool newValue) {
                      setState(() {
                        value = newValue;
                      });
                    }
                  : null,
1893
                onPressed: isPressable
1894 1895 1896 1897 1898 1899
                  ? () {
                      setState(() {
                        value = true;
                      });
                    }
                  : null,
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
              );
            }),
          ),
        ),
      );
    }

    await tester.pumpWidget(buildApp());

    RenderBox materialBox = getMaterialBox(tester);
    IconThemeData iconData = getIconData(tester);
1911
    DefaultTextStyle labelStyle = getLabelStyle(tester, 'false');
1912 1913

    // Check default theme for enabled widget.
1914
    expect(materialBox, paints..path(color: defaultChipTheme.backgroundColor));
1915 1916 1917 1918 1919
    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);
1920
    expect(materialBox, paints..path(color: defaultChipTheme.selectedColor));
1921 1922 1923 1924
    await tester.tap(find.byType(RawChip));
    await tester.pumpAndSettle();

    // Check default theme with disabled widget.
1925
    await tester.pumpWidget(buildApp(isSelectable: false));
1926 1927
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
1928
    labelStyle = getLabelStyle(tester, 'false');
1929
    expect(materialBox, paints..path(color: defaultChipTheme.disabledColor));
1930 1931 1932
    expect(labelStyle.style.color, equals(Colors.black.withAlpha(0xde)));

    // Apply a custom theme.
1933 1934 1935 1936
    const Color customColor1 = Color(0xcafefeed);
    const Color customColor2 = Color(0xdeadbeef);
    const Color customColor3 = Color(0xbeefcafe);
    const Color customColor4 = Color(0xaddedabe);
1937
    final ChipThemeData customTheme = defaultChipTheme.copyWith(
1938 1939 1940 1941 1942 1943
      brightness: Brightness.dark,
      backgroundColor: customColor1,
      disabledColor: customColor2,
      selectedColor: customColor3,
      deleteIconColor: customColor4,
    );
1944
    await tester.pumpWidget(buildApp(chipTheme: customTheme));
1945 1946 1947
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
    iconData = getIconData(tester);
1948
    labelStyle = getLabelStyle(tester, 'false');
1949 1950

    // Check custom theme for enabled widget.
1951
    expect(materialBox, paints..path(color: customTheme.backgroundColor));
1952 1953 1954 1955 1956
    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);
1957
    expect(materialBox, paints..path(color: customTheme.selectedColor));
1958 1959 1960 1961 1962
    await tester.tap(find.byType(RawChip));
    await tester.pumpAndSettle();

    // Check custom theme with disabled widget.
    await tester.pumpWidget(buildApp(
1963
      chipTheme: customTheme,
1964 1965 1966 1967
      isSelectable: false,
    ));
    await tester.pumpAndSettle();
    materialBox = getMaterialBox(tester);
1968
    labelStyle = getLabelStyle(tester, 'false');
1969
    expect(materialBox, paints..path(color: customTheme.disabledColor));
1970 1971
    expect(labelStyle.style.color, equals(Colors.black.withAlpha(0xde)));
  });
1972 1973 1974

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

1977 1978
      await tester.pumpWidget(const MaterialApp(
        home: Material(
1979 1980
          child: RawChip(
            label: Text('test'),
1981 1982 1983 1984
          ),
        ),
      ));

1985 1986 1987
      expect(
        semanticsTester,
        hasSemantics(
1988
          TestSemantics.root(
1989
            children: <TestSemantics>[
1990
              TestSemantics(
1991 1992
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
1993
                  TestSemantics(
1994
                    children: <TestSemantics>[
1995
                      TestSemantics(
1996 1997 1998 1999 2000
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
2001 2002 2003 2004
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
                              SemanticsFlag.isButton,
                            ],
2005 2006
                          ),
                        ],
2007 2008 2009 2010 2011 2012
                      ),
                    ],
                  ),
                ],
              ),
            ],
2013 2014 2015 2016 2017 2018
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2019 2020 2021
      semanticsTester.dispose();
    });

2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033
    testWidgets('delete', (WidgetTester tester) async {
      final SemanticsTester semanticsTester = SemanticsTester(tester);

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

2034 2035 2036
      expect(
        semanticsTester,
        hasSemantics(
2037 2038 2039 2040 2041 2042 2043 2044
          TestSemantics.root(
            children: <TestSemantics>[
              TestSemantics(
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
                  TestSemantics(
                    children: <TestSemantics>[
                      TestSemantics(
2045
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
2046 2047
                        children: <TestSemantics>[
                          TestSemantics(
2048
                            label: 'test',
2049
                            textDirection: TextDirection.ltr,
2050 2051 2052 2053
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
                              SemanticsFlag.isButton,
                            ],
2054 2055 2056 2057 2058 2059 2060
                            children: <TestSemantics>[
                              TestSemantics(
                                label: 'Delete',
                                actions: <SemanticsAction>[SemanticsAction.tap],
                                textDirection: TextDirection.ltr,
                                flags: <SemanticsFlag>[
                                  SemanticsFlag.isButton,
2061
                                  SemanticsFlag.isFocusable,
2062 2063
                                ],
                              ),
2064 2065 2066 2067 2068 2069 2070 2071 2072
                            ],
                          ),
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
2073 2074 2075 2076 2077 2078
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2079 2080 2081
      semanticsTester.dispose();
    });

2082
    testWidgets('with onPressed', (WidgetTester tester) async {
2083
      final SemanticsTester semanticsTester = SemanticsTester(tester);
2084

2085 2086 2087
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
2088
            label: const Text('test'),
2089
            onPressed: () { },
2090 2091 2092 2093
          ),
        ),
      ));

2094 2095 2096
      expect(
        semanticsTester,
        hasSemantics(
2097
          TestSemantics.root(
2098
            children: <TestSemantics>[
2099
              TestSemantics(
2100 2101
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
2102
                  TestSemantics(
2103
                    children: <TestSemantics> [
2104
                      TestSemantics(
2105 2106 2107 2108 2109 2110 2111
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
2112
                              SemanticsFlag.isButton,
2113 2114 2115 2116 2117
                              SemanticsFlag.isEnabled,
                              SemanticsFlag.isFocusable,
                            ],
                            actions: <SemanticsAction>[SemanticsAction.tap],
                          ),
2118 2119 2120 2121 2122 2123 2124
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
2125 2126 2127 2128 2129 2130
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2131 2132 2133 2134 2135 2136

      semanticsTester.dispose();
    });


    testWidgets('with onSelected', (WidgetTester tester) async {
2137
      final SemanticsTester semanticsTester = SemanticsTester(tester);
2138 2139
      bool selected = false;

2140 2141 2142
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
2143 2144 2145 2146 2147 2148 2149 2150 2151
            label: const Text('test'),
            selected: selected,
            onSelected: (bool value) {
              selected = value;
            },
          ),
        ),
      ));

2152 2153 2154
      expect(
        semanticsTester,
        hasSemantics(
2155
          TestSemantics.root(
2156
            children: <TestSemantics>[
2157
              TestSemantics(
2158 2159
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
2160
                  TestSemantics(
2161
                    children: <TestSemantics>[
2162
                      TestSemantics(
2163 2164 2165 2166 2167 2168 2169
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
2170
                              SemanticsFlag.isButton,
2171 2172 2173 2174 2175
                              SemanticsFlag.isEnabled,
                              SemanticsFlag.isFocusable,
                            ],
                            actions: <SemanticsAction>[SemanticsAction.tap],
                          ),
2176 2177 2178 2179 2180 2181 2182
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
2183 2184 2185 2186 2187 2188
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2189 2190

      await tester.tap(find.byType(RawChip));
2191 2192 2193
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
2194 2195 2196 2197 2198 2199 2200 2201 2202 2203
            label: const Text('test'),
            selected: selected,
            onSelected: (bool value) {
              selected = value;
            },
          ),
        ),
      ));

      expect(selected, true);
2204 2205 2206
      expect(
        semanticsTester,
        hasSemantics(
2207
          TestSemantics.root(
2208
            children: <TestSemantics>[
2209
              TestSemantics(
2210 2211
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
2212
                  TestSemantics(
2213
                    children: <TestSemantics>[
2214
                      TestSemantics(
2215 2216 2217 2218 2219 2220 2221
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
2222
                              SemanticsFlag.isButton,
2223 2224 2225 2226 2227 2228
                              SemanticsFlag.isEnabled,
                              SemanticsFlag.isFocusable,
                              SemanticsFlag.isSelected,
                            ],
                            actions: <SemanticsAction>[SemanticsAction.tap],
                          ),
2229 2230 2231 2232 2233 2234 2235
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
2236 2237 2238 2239 2240 2241
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2242 2243 2244 2245 2246

      semanticsTester.dispose();
    });

    testWidgets('disabled', (WidgetTester tester) async {
2247
      final SemanticsTester semanticsTester = SemanticsTester(tester);
2248

2249 2250 2251
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
2252
            isEnabled: false,
2253
            onPressed: () { },
2254 2255 2256 2257 2258
            label: const Text('test'),
          ),
        ),
      ));

2259 2260 2261
      expect(
        semanticsTester,
        hasSemantics(
2262
          TestSemantics.root(
2263
            children: <TestSemantics>[
2264
              TestSemantics(
2265 2266
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
2267
                  TestSemantics(
2268
                    children: <TestSemantics>[
2269
                      TestSemantics(
2270 2271 2272 2273 2274
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
2275 2276 2277 2278
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
                              SemanticsFlag.isButton,
                            ],
2279 2280 2281
                            actions: <SemanticsAction>[],
                          ),
                        ],
2282 2283 2284
                      ),
                    ],
                  ),
2285 2286 2287
                ],
              ),
            ],
2288 2289 2290 2291 2292 2293
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309

      semanticsTester.dispose();
    });

    testWidgets('tapEnabled explicitly false', (WidgetTester tester) async {
      final SemanticsTester semanticsTester = SemanticsTester(tester);

      await tester.pumpWidget(const MaterialApp(
        home: Material(
          child: RawChip(
            tapEnabled: false,
            label: Text('test'),
          ),
        ),
      ));

2310 2311 2312
      expect(
        semanticsTester,
        hasSemantics(
2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
          TestSemantics.root(
            children: <TestSemantics>[
              TestSemantics(
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
                  TestSemantics(
                    children: <TestSemantics>[
                      TestSemantics(
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[], // Must not be a button when tapping is disabled.
                            actions: <SemanticsAction>[],
                          ),
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
2336 2337 2338 2339 2340 2341
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358

      semanticsTester.dispose();
    });

    testWidgets('enabled when tapEnabled and canTap', (WidgetTester tester) async {
      final SemanticsTester semanticsTester = SemanticsTester(tester);

      // These settings make a Chip which can be tapped, both in general and at this moment.
      await tester.pumpWidget(MaterialApp(
        home: Material(
          child: RawChip(
            onPressed: () {},
            label: const Text('test'),
          ),
        ),
      ));

2359 2360 2361
      expect(
        semanticsTester,
        hasSemantics(
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
          TestSemantics.root(
            children: <TestSemantics>[
              TestSemantics(
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
                  TestSemantics(
                    children: <TestSemantics>[
                      TestSemantics(
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
                              SemanticsFlag.isButton,
                              SemanticsFlag.isEnabled,
                              SemanticsFlag.isFocusable,
                            ],
                            actions: <SemanticsAction>[SemanticsAction.tap],
                          ),
                        ],
                      ),
                    ],
                  ),
                ],
              ),
            ],
2390 2391 2392 2393 2394 2395
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410

      semanticsTester.dispose();
    });

    testWidgets('disabled when tapEnabled but not canTap', (WidgetTester tester) async {
      final SemanticsTester semanticsTester = SemanticsTester(tester);
        // These settings make a Chip which _could_ be tapped, but not currently (ensures `canTap == false`).
        await tester.pumpWidget(const MaterialApp(
        home: Material(
          child: RawChip(
            label: Text('test'),
          ),
        ),
      ));

2411 2412 2413
      expect(
        semanticsTester,
        hasSemantics(
2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435
          TestSemantics.root(
            children: <TestSemantics>[
              TestSemantics(
                textDirection: TextDirection.ltr,
                children: <TestSemantics>[
                  TestSemantics(
                    children: <TestSemantics>[
                      TestSemantics(
                        flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
                        children: <TestSemantics>[
                          TestSemantics(
                            label: 'test',
                            textDirection: TextDirection.ltr,
                            flags: <SemanticsFlag>[
                              SemanticsFlag.hasEnabledState,
                              SemanticsFlag.isButton,
                            ],
                          ),
                        ],
                      ),
                    ],
                  ),
2436 2437 2438
                ],
              ),
            ],
2439 2440 2441 2442 2443 2444
          ),
          ignoreTransform: true,
          ignoreId: true,
          ignoreRect: true,
        ),
      );
2445 2446 2447 2448 2449 2450 2451 2452 2453

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

  testWidgets('can be tapped outside of chip delete icon', (WidgetTester tester) async {
    bool deleted = false;
    await tester.pumpWidget(
      _wrapForChip(
2454
        child: Row(
2455
          children: <Widget>[
2456
            Chip(
2457
              materialTapTargetSize: MaterialTapTargetSize.padded,
2458
              shape: const RoundedRectangleBorder(),
2459
              avatar: const CircleAvatar(child: Text('A')),
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475
              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
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
  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(
            label: Text('raw chip'),
          ),
        ),
      ),
    );

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

    await tester.pumpWidget(
      MaterialApp(
        home: Material(
          child: ActionChip(
2508
            onPressed: () { },
jslavitz's avatar
jslavitz committed
2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521
            label: const Text('action chip'),
          ),
        ),
      ),
    );

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

    await tester.pumpWidget(
      MaterialApp(
        home: Material(
          child: FilterChip(
2522
            onSelected: (bool valueChanged) { },
jslavitz's avatar
jslavitz committed
2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545
            label: const Text('filter chip'),
          ),
        ),
      ),
    );

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

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

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

2546
  testWidgets('Chip elevation and shadow color work correctly', (WidgetTester tester) async {
2547 2548 2549 2550 2551 2552 2553
    final ThemeData theme = ThemeData(
      platform: TargetPlatform.android,
      primarySwatch: Colors.red,
    );

    final ChipThemeData chipTheme = theme.chipTheme;

2554
    InputChip inputChip = const InputChip(label: Text('Label'));
2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565

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

    await tester.pumpWidget(buildChip(chipTheme));
2566 2567
    Material material = getMaterial(tester);
    expect(material.elevation, 0.0);
2568
    expect(material.shadowColor, Colors.black);
2569

2570 2571 2572
    inputChip = const InputChip(
      label: Text('Label'),
      elevation: 4.0,
2573 2574
      shadowColor: Colors.green,
      selectedShadowColor: Colors.blue,
2575
    );
2576 2577 2578

    await tester.pumpWidget(buildChip(chipTheme));
    await tester.pumpAndSettle();
2579 2580
    material = getMaterial(tester);
    expect(material.elevation, 4.0);
2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593
    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);
2594 2595
  });

2596 2597 2598 2599
  testWidgets('can be tapped outside of chip body', (WidgetTester tester) async {
    bool pressed = false;
    await tester.pumpWidget(
      _wrapForChip(
2600
        child: Row(
2601
          children: <Widget>[
2602
            InputChip(
2603
              materialTapTargetSize: MaterialTapTargetSize.padded,
2604
              shape: const RoundedRectangleBorder(),
2605
              avatar: const CircleAvatar(child: Text('A')),
2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623
              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(
2624
        child: InputChip(
2625
          shape: const RoundedRectangleBorder(),
2626
          avatar: const CircleAvatar(child: Text('A')),
2627
          label: const Text('Chip A'),
2628
          onPressed: () { },
2629 2630 2631 2632
        ),
      ),
    );

2633
    expect(find.byType(InputChip).hitTestable(), findsOneWidget);
2634
  });
2635 2636 2637 2638 2639 2640 2641 2642

  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 {
2643 2644 2645
    const Text label = Text('label');
    await tester.pumpWidget(_wrapForChip(child: const Chip(label: label)));
    checkChipMaterialClipBehavior(tester, Clip.none);
2646

2647 2648
    await tester.pumpWidget(_wrapForChip(child: const Chip(label: label, clipBehavior: Clip.antiAlias)));
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661
  });

  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');
2662
    await tester.pumpWidget(_wrapForChip(child: FilterChip(label: label, onSelected: (bool b) { })));
2663 2664
    checkChipMaterialClipBehavior(tester, Clip.none);

2665
    await tester.pumpWidget(_wrapForChip(child: FilterChip(label: label, onSelected: (bool b) { }, clipBehavior: Clip.antiAlias)));
2666 2667 2668 2669 2670
    checkChipMaterialClipBehavior(tester, Clip.antiAlias);
  });

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

2674
    await tester.pumpWidget(_wrapForChip(child: ActionChip(label: label, clipBehavior: Clip.antiAlias, onPressed: () { })));
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685
    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);
  });
2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698

  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';
2699
        }),
2700
      ),
2701 2702 2703 2704 2705 2706 2707
    );
    const Color selectScrimColor = Color(0x60191919);
    expect(rawChip, paints..path(color: selectScrimColor, includes: <Offset>[
      const Offset(10, 10),
    ], excludes: <Offset>[
      const Offset(4, 4),
    ]));
2708
  });
2709 2710 2711 2712 2713 2714 2715

  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(
2716
            onPressed: () { },
2717 2718 2719 2720 2721 2722 2723
            label: const Text('action chip'),
          ),
        ),
      ),
    );
    expect(find.byType(InkWell), findsOneWidget);
  });
2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769

  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() {
2770
      return tester.renderObject<RenderParagraph>(find.text('Chip')).text.style!.color!;
2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809
    }

    // 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();
  });
2810

2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838
  testWidgets('Chip uses stateful border side 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);

    BorderSide getBorderSide(Set<MaterialState> states) {
      Color sideColor = defaultColor;

      if (states.contains(MaterialState.disabled))
        sideColor = disabledColor;

      else if (states.contains(MaterialState.pressed))
        sideColor = pressedColor;

      else if (states.contains(MaterialState.hovered))
        sideColor = hoverColor;

      else if (states.contains(MaterialState.focused))
        sideColor = focusedColor;

      else if (states.contains(MaterialState.selected))
        sideColor = selectedColor;

2839
      return BorderSide(color: sideColor);
2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889
    }

    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,
              side: _MaterialStateBorderSide(getBorderSide),
            ),
          ),
        ),
      );
    }

    // Default, not disabled.
    await tester.pumpWidget(chipWidget());
    expect(find.byType(RawChip), paints..rrect(color: defaultColor));

    // Selected.
    await tester.pumpWidget(chipWidget(selected: true));
    expect(find.byType(RawChip), paints..rrect(color: selectedColor));

    // Focused.
    final FocusNode chipFocusNode = focusNode.children.first;
    chipFocusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: 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(find.byType(RawChip), paints..rrect(color: hoverColor));

    // Pressed.
    await gesture.down(center);
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: pressedColor));

    // Disabled.
    await tester.pumpWidget(chipWidget(enabled: false));
    await tester.pumpAndSettle();
2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923
    expect(find.byType(RawChip), paints..rrect(color: disabledColor));

    // Teardown.
    await gesture.removePointer();
  });

  testWidgets('Chip uses stateful border side color from resolveWith', (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);

    BorderSide getBorderSide(Set<MaterialState> states) {
      Color sideColor = defaultColor;

      if (states.contains(MaterialState.disabled))
        sideColor = disabledColor;

      else if (states.contains(MaterialState.pressed))
        sideColor = pressedColor;

      else if (states.contains(MaterialState.hovered))
        sideColor = hoverColor;

      else if (states.contains(MaterialState.focused))
        sideColor = focusedColor;

      else if (states.contains(MaterialState.selected))
        sideColor = selectedColor;

2924
      return BorderSide(color: sideColor);
2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011
    }

    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,
              side: MaterialStateBorderSide.resolveWith(getBorderSide),
            ),
          ),
        ),
      );
    }

    // Default, not disabled.
    await tester.pumpWidget(chipWidget());
    expect(find.byType(RawChip), paints..rrect(color: defaultColor));

    // Selected.
    await tester.pumpWidget(chipWidget(selected: true));
    expect(find.byType(RawChip), paints..rrect(color: selectedColor));

    // Focused.
    final FocusNode chipFocusNode = focusNode.children.first;
    chipFocusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: 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(find.byType(RawChip), paints..rrect(color: hoverColor));

    // Pressed.
    await gesture.down(center);
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: pressedColor));

    // Disabled.
    await tester.pumpWidget(chipWidget(enabled: false));
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: disabledColor));

    // Teardown.
    await gesture.removePointer();
  });

  testWidgets('Chip uses stateful nullable border side color from resolveWith', (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 disabledColor = Color(0x00000006);

    const Color fallbackThemeColor = Color(0x00000007);
    const BorderSide defaultBorderSide = BorderSide(color: fallbackThemeColor, width: 10.0);

    BorderSide? getBorderSide(Set<MaterialState> states) {
      Color sideColor = defaultColor;

      if (states.contains(MaterialState.disabled))
        sideColor = disabledColor;

      else if (states.contains(MaterialState.pressed))
        sideColor = pressedColor;

      else if (states.contains(MaterialState.hovered))
        sideColor = hoverColor;

      else if (states.contains(MaterialState.focused))
        sideColor = focusedColor;

      else if (states.contains(MaterialState.selected))
        return null;

3012
      return BorderSide(color: sideColor);
3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069
    }

    Widget chipWidget({ bool enabled = true, bool selected = false }) {
      return MaterialApp(
        home: Scaffold(
          body: Focus(
            focusNode: focusNode,
            child: ChipTheme(
              data: ThemeData.light().chipTheme.copyWith(
                side: defaultBorderSide,
              ),
              child: ChoiceChip(
                label: const Text('Chip'),
                selected: selected,
                onSelected: enabled ? (_) {} : null,
                side: MaterialStateBorderSide.resolveWith(getBorderSide),
              ),
            ),
          ),
        ),
      );
    }

    // Default, not disabled.
    await tester.pumpWidget(chipWidget());
    expect(find.byType(RawChip), paints..rrect(color: defaultColor));

    // Selected.
    await tester.pumpWidget(chipWidget(selected: true));
    // Because the resolver returns `null` for this value, we should fall back
    // to the theme
    expect(find.byType(RawChip), paints..rrect(color: fallbackThemeColor));

    // Focused.
    final FocusNode chipFocusNode = focusNode.children.first;
    chipFocusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: 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(find.byType(RawChip), paints..rrect(color: hoverColor));

    // Pressed.
    await gesture.down(center);
    await tester.pumpAndSettle();
    expect(find.byType(RawChip), paints..rrect(color: pressedColor));

    // Disabled.
    await tester.pumpWidget(chipWidget(enabled: false));
    await tester.pumpAndSettle();
3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154
    expect(find.byType(RawChip), paints..rrect(color: disabledColor));

    // Teardown.
    await gesture.removePointer();
  });

  testWidgets('Chip uses stateful shape in different states', (WidgetTester tester) async {
    final FocusNode focusNode = FocusNode();
    OutlinedBorder? getShape(Set<MaterialState> states) {

      if (states.contains(MaterialState.disabled))
        return const BeveledRectangleBorder();

      else if (states.contains(MaterialState.pressed))
        return const CircleBorder();

      else if (states.contains(MaterialState.hovered))
        return const ContinuousRectangleBorder();

      else if (states.contains(MaterialState.focused))
        return const RoundedRectangleBorder();

      else if (states.contains(MaterialState.selected))
        return const BeveledRectangleBorder();

      return null;
    }

    Widget chipWidget({ bool enabled = true, bool selected = false }) {
      return MaterialApp(
        home: Scaffold(
          body: Focus(
            focusNode: focusNode,
            child: ChoiceChip(
              selected: selected,
              label: const Text('Chip'),
              shape: _MaterialStateOutlinedBorder(getShape),
              onSelected: enabled ? (_) {} : null,
            ),
          ),
        ),
      );
    }

    // Default, not disabled. Defers to default shape.
    await tester.pumpWidget(chipWidget());
    expect(getMaterial(tester).shape, isA<StadiumBorder>());

    // Selected.
    await tester.pumpWidget(chipWidget(selected: true));
    expect(getMaterial(tester).shape, isA<BeveledRectangleBorder>());

    // Focused.
    final FocusNode chipFocusNode = focusNode.children.first;
    chipFocusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(getMaterial(tester).shape, isA<RoundedRectangleBorder>());

    // 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(getMaterial(tester).shape, isA<ContinuousRectangleBorder>());

    // Pressed.
    await gesture.down(center);
    await tester.pumpAndSettle();
    expect(getMaterial(tester).shape, isA<CircleBorder>());

    // Disabled.
    await tester.pumpWidget(chipWidget(enabled: false));
    await tester.pumpAndSettle();
    expect(getMaterial(tester).shape, isA<BeveledRectangleBorder>());

    // Teardown.
    await gesture.removePointer();
  });

  testWidgets('Chip defers to theme, if shape and side resolves to null', (WidgetTester tester) async {
    const OutlinedBorder themeShape = StadiumBorder();
    const OutlinedBorder selectedShape = RoundedRectangleBorder();
3155 3156
    const BorderSide themeBorderSide = BorderSide(color: Color(0x00000001));
    const BorderSide selectedBorderSide = BorderSide(color: Color(0x00000002));
3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200

    OutlinedBorder? getShape(Set<MaterialState> states) {
      if (states.contains(MaterialState.selected))
        return selectedShape;
      return null;
    }

    BorderSide? getBorderSide(Set<MaterialState> states) {
      if (states.contains(MaterialState.selected))
        return selectedBorderSide;
      return null;
    }

    Widget chipWidget({ bool enabled = true, bool selected = false }) {
      return MaterialApp(
        theme: ThemeData(
          chipTheme: ThemeData.light().chipTheme.copyWith(
            shape: themeShape,
            side: themeBorderSide,
          ),
        ),
        home: Scaffold(
          body: ChoiceChip(
            selected: selected,
            label: const Text('Chip'),
            shape: _MaterialStateOutlinedBorder(getShape),
            side: _MaterialStateBorderSide(getBorderSide),
            onSelected: enabled ? (_) {} : null,
          ),
        ),
      );
    }

    // Default, not disabled. Defer to theme.
    await tester.pumpWidget(chipWidget());
    expect(getMaterial(tester).shape, isA<StadiumBorder>());
    expect(find.byType(RawChip), paints..rrect(color: themeBorderSide.color));

    // Selected.
    await tester.pumpWidget(chipWidget(selected: true));
    expect(getMaterial(tester).shape, isA<RoundedRectangleBorder>());
    expect(find.byType(RawChip), paints..drrect(color: selectedBorderSide.color));
  });

3201 3202 3203 3204 3205 3206 3207
  testWidgets('loses focus when disabled', (WidgetTester tester) async {
    final FocusNode focusNode = FocusNode(debugLabel: 'InputChip');
    await tester.pumpWidget(
      _wrapForChip(
        child: InputChip(
          focusNode: focusNode,
          autofocus: true,
3208
          shape: const RoundedRectangleBorder(),
3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222
          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,
3223
          shape: const RoundedRectangleBorder(),
3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264
          avatar: const CircleAvatar(child: Text('A')),
          label: const Text('Chip A'),
        ),
      ),
    );
    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'),
            ),
          ],
        ),
      ),
    );
    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);
  });
3265

3266 3267 3268 3269 3270 3271
  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 {
3272
      return tester.pumpWidget(
3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370
        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)));
  });

3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495
  testWidgets('Input chip check mark color is determined by platform brightness when light', (WidgetTester tester) async {
    await _pumpCheckmarkChip(
      tester,
      chip: _selectedInputChip(),
    );

    _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(),
    );

    _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),
    );
  });
3496

3497
  testWidgets('Chip delete button tooltip can be disabled using useDeleteButtonTooltip', (WidgetTester tester) async {
3498 3499 3500
    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        deletable: true,
3501
        useDeleteButtonTooltip: false,
3502
      ),
3503 3504
    );

3505 3506
    // Tap at the delete icon of the chip, which is at the right side of the
    // chip
3507
    final Offset topRightOfInkwell = tester.getTopLeft(find.byType(InkWell).first);
3508 3509 3510 3511 3512 3513 3514 3515
    final Offset tapLocationOfDeleteButton = topRightOfInkwell + const Offset(8, 8);
    final TestGesture tapGesture = await tester.startGesture(tapLocationOfDeleteButton);

    await tester.pump();

    // Wait for some more time while pressing and holding the delete button
    await tester.pumpAndSettle();

3516
    // There should be no delete button tooltip
3517 3518 3519 3520
    expect(findTooltipContainer('Delete'), findsNothing);

    await tapGesture.up();
  });
3521

3522
  testWidgets('Chip delete button tooltip is disabled if deleteButtonTooltipMessage is empty', (WidgetTester tester) async {
3523 3524 3525 3526 3527
    final UniqueKey deleteButtonKey = UniqueKey();
    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        deleteButtonKey: deleteButtonKey,
        deletable: true,
3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553
        deleteButtonTooltipMessage: '',
      ),
    );

    // Hover over the delete icon of the chip
    final Offset centerOfDeleteButton = tester.getCenter(find.byKey(deleteButtonKey));
    final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await hoverGesture.moveTo(centerOfDeleteButton);
    addTearDown(hoverGesture.removePointer);

    await tester.pump();

    // Wait for some more time while hovering over the delete button
    await tester.pumpAndSettle();

    // There should be no delete button tooltip
    expect(findTooltipContainer(''), findsNothing);
  });

  testWidgets('Disabling delete button tooltip does not disable chip tooltip', (WidgetTester tester) async {
    final UniqueKey deleteButtonKey = UniqueKey();
    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        deleteButtonKey: deleteButtonKey,
        deletable: true,
        deleteButtonTooltipMessage: '',
3554 3555 3556 3557
        chipTooltip: 'Chip Tooltip',
      ),
    );

3558
    // Hover over the delete icon of the chip
3559 3560 3561 3562 3563 3564 3565
    final Offset centerOfDeleteButton = tester.getCenter(find.byKey(deleteButtonKey));
    final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await hoverGesture.moveTo(centerOfDeleteButton);
    addTearDown(hoverGesture.removePointer);

    await tester.pump();

3566
    // Wait for some more time while hovering over the delete button
3567 3568
    await tester.pumpAndSettle();

3569
    // There should be no delete button tooltip
3570
    expect(findTooltipContainer(''), findsNothing);
3571 3572 3573 3574
    // There should be a chip tooltip, however.
    expect(findTooltipContainer('Chip Tooltip'), findsOneWidget);
  });

3575
  testWidgets('Triggering delete button tooltip does not trigger Chip tooltip', (WidgetTester tester) async {
3576 3577 3578 3579 3580 3581 3582 3583 3584
    final UniqueKey deleteButtonKey = UniqueKey();
    await tester.pumpWidget(
      _chipWithOptionalDeleteButton(
        deleteButtonKey: deleteButtonKey,
        deletable: true,
        chipTooltip: 'Chip Tooltip',
      ),
    );

3585
    // Hover over the delete icon of the chip
3586 3587 3588 3589 3590 3591 3592
    final Offset centerOfDeleteButton = tester.getCenter(find.byKey(deleteButtonKey));
    final TestGesture hoverGesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await hoverGesture.moveTo(centerOfDeleteButton);
    addTearDown(hoverGesture.removePointer);

    await tester.pump();

3593
    // Wait for some more time while hovering over the delete button
3594 3595
    await tester.pumpAndSettle();

3596 3597
    // There should not be a chip tooltip
    expect(findTooltipContainer('Chip Tooltip'), findsNothing);
3598
    // There should be a delete button tooltip
3599 3600 3601
    expect(findTooltipContainer('Delete'), findsOneWidget);
  });

3602
  testWidgets('intrinsicHeight implementation meets constraints', (WidgetTester tester) async {
3603
    // Regression test for https://github.com/flutter/flutter/issues/49478.
3604 3605 3606 3607 3608 3609 3610 3611 3612
    await tester.pumpWidget(_wrapForChip(
      child: const Chip(
        label: Text('text'),
        padding: EdgeInsets.symmetric(horizontal: 20),
      ),
    ));

    expect(tester.takeException(), isNull);
  });
3613
}
3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631

class _MaterialStateOutlinedBorder extends StadiumBorder implements MaterialStateOutlinedBorder {
  const _MaterialStateOutlinedBorder(this.resolver);

  final MaterialPropertyResolver<OutlinedBorder?> resolver;

  @override
  OutlinedBorder? resolve(Set<MaterialState> states) => resolver(states);
}

class _MaterialStateBorderSide extends MaterialStateBorderSide {
  const _MaterialStateBorderSide(this.resolver);

  final MaterialPropertyResolver<BorderSide?> resolver;

  @override
  BorderSide? resolve(Set<MaterialState> states) => resolver(states);
}