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

5 6 7
// This file is run as part of a reduced test set in CI on Mac and Windows
// machines.
@Tags(<String>['reduced-test-set'])
8
@TestOn('!chrome')
9 10
library;

11 12
import 'dart:ui';

13
import 'package:flutter/material.dart';
14
import 'package:flutter/rendering.dart';
15
import 'package:flutter_test/flutter_test.dart';
16
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
17
import '../widgets/semantics_tester.dart';
18
import 'feedback_tester.dart';
19

20
void main() {
21 22
  final ThemeData material3Theme = ThemeData(useMaterial3: true);
  final ThemeData material2Theme = ThemeData(useMaterial3: false);
23

24
  testWidgetsWithLeakTracking('Floating Action Button control test', (WidgetTester tester) async {
25 26
    bool didPressButton = false;
    await tester.pumpWidget(
27
      Directionality(
Ian Hickson's avatar
Ian Hickson committed
28
        textDirection: TextDirection.ltr,
29 30
        child: Center(
          child: FloatingActionButton(
Ian Hickson's avatar
Ian Hickson committed
31 32 33 34 35
            onPressed: () {
              didPressButton = true;
            },
            child: const Icon(Icons.add),
          ),
36 37
        ),
      ),
38 39 40 41 42 43
    );

    expect(didPressButton, isFalse);
    await tester.tap(find.byType(Icon));
    expect(didPressButton, isTrue);
  });
44

45
  testWidgetsWithLeakTracking('Floating Action Button tooltip', (WidgetTester tester) async {
46
    await tester.pumpWidget(
47
      MaterialApp(
48
        home: Scaffold(
49
          floatingActionButton: FloatingActionButton(
50
            onPressed: () {},
51
            tooltip: 'Add',
52
            child: const Icon(Icons.add),
53 54 55 56 57 58 59 60
          ),
        ),
      ),
    );

    await tester.tap(find.byType(Icon));
    expect(find.byTooltip('Add'), findsOneWidget);
  });
61

62
  // Regression test for: https://github.com/flutter/flutter/pull/21084
63
  testWidgetsWithLeakTracking('Floating Action Button tooltip (long press button edge)', (WidgetTester tester) async {
64
    await tester.pumpWidget(
65
      MaterialApp(
66
        home: Scaffold(
67
          floatingActionButton: FloatingActionButton(
68
            onPressed: () {},
69
            tooltip: 'Add',
70
            child: const Icon(Icons.add),
71 72 73 74 75 76 77 78 79 80 81 82 83
          ),
        ),
      ),
    );

    expect(find.text('Add'), findsNothing);
    await tester.longPressAt(_rightEdgeOfFab(tester));
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsOneWidget);
  });

  // Regression test for: https://github.com/flutter/flutter/pull/21084
84
  testWidgetsWithLeakTracking('Floating Action Button tooltip (long press button edge - no child)', (WidgetTester tester) async {
85
    await tester.pumpWidget(
86
      MaterialApp(
87
        home: Scaffold(
88
          floatingActionButton: FloatingActionButton(
89
            onPressed: () {},
90 91 92 93 94 95 96 97 98 99 100 101 102
            tooltip: 'Add',
          ),
        ),
      ),
    );

    expect(find.text('Add'), findsNothing);
    await tester.longPressAt(_rightEdgeOfFab(tester));
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsOneWidget);
  });

103
  testWidgetsWithLeakTracking('Floating Action Button tooltip (no child)', (WidgetTester tester) async {
104
    await tester.pumpWidget(
105
      MaterialApp(
106
        home: Scaffold(
107
          floatingActionButton: FloatingActionButton(
108
            onPressed: () {},
109 110 111 112 113 114
            tooltip: 'Add',
          ),
        ),
      ),
    );

115
    expect(find.text('Add'), findsNothing);
116 117

    // Test hover for tooltip.
118 119 120
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
    addTearDown(() => gesture.removePointer());
121 122 123 124 125 126 127 128 129 130 131
    await gesture.moveTo(tester.getCenter(find.byType(FloatingActionButton)));
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsOneWidget);

    await gesture.moveTo(Offset.zero);
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsNothing);

    // Test long press for tooltip.
132
    await tester.longPress(find.byType(FloatingActionButton));
133
    await tester.pumpAndSettle();
134

135
    expect(find.text('Add'), findsOneWidget);
136 137
  });

138
  testWidgetsWithLeakTracking('Floating Action Button tooltip reacts when disabled', (WidgetTester tester) async {
139 140 141 142 143 144 145 146 147 148 149 150 151 152
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: null,
            tooltip: 'Add',
          ),
        ),
      ),
    );

    expect(find.text('Add'), findsNothing);

    // Test hover for tooltip.
153 154 155
    final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse);
    await gesture.addPointer();
    addTearDown(() => gesture.removePointer());
156
    await tester.pumpAndSettle();
157 158 159 160 161 162
    await gesture.moveTo(tester.getCenter(find.byType(FloatingActionButton)));
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsOneWidget);

    await gesture.moveTo(Offset.zero);
163 164 165 166 167 168 169 170 171 172 173
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsNothing);

    // Test long press for tooltip.
    await tester.longPress(find.byType(FloatingActionButton));
    await tester.pumpAndSettle();

    expect(find.text('Add'), findsOneWidget);
  });

174
  testWidgetsWithLeakTracking('Floating Action Button elevation when highlighted - effect', (WidgetTester tester) async {
175 176
    await tester.pumpWidget(
      MaterialApp(
177
        theme: material3Theme,
178 179 180 181 182 183 184 185 186 187 188 189
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: () { },
          ),
        ),
      ),
    );
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    final TestGesture gesture = await tester.press(find.byType(PhysicalShape));
    await tester.pump();
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.pump(const Duration(seconds: 1));
190
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
191 192 193 194 195
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: () { },
196
            highlightElevation: 20.0,
197 198 199 200 201
          ),
        ),
      ),
    );
    await tester.pump();
202
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
203 204 205 206 207 208 209 210 211
    await tester.pump(const Duration(seconds: 1));
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 20.0);
    await gesture.up();
    await tester.pump();
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 20.0);
    await tester.pump(const Duration(seconds: 1));
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
  });

212
  testWidgetsWithLeakTracking('Floating Action Button elevation when disabled - defaults', (WidgetTester tester) async {
213 214 215 216 217 218 219 220 221 222 223 224 225 226
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: null,
          ),
        ),
      ),
    );

    // Disabled elevation defaults to regular default elevation.
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
  });

227
  testWidgetsWithLeakTracking('Floating Action Button elevation when disabled - override', (WidgetTester tester) async {
228 229 230 231 232 233 234 235 236 237 238 239
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: null,
            disabledElevation: 0,
          ),
        ),
      ),
    );

    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 0.0);
240 241
  });

242
  testWidgetsWithLeakTracking('Floating Action Button elevation when disabled - effect', (WidgetTester tester) async {
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: null,
          ),
        ),
      ),
    );
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: null,
            disabledElevation: 3.0,
          ),
        ),
      ),
    );
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.pump(const Duration(seconds: 1));
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 3.0);
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: () { },
            disabledElevation: 3.0,
          ),
        ),
      ),
    );
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 3.0);
    await tester.pump(const Duration(seconds: 1));
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
  });

281
  testWidgetsWithLeakTracking('Floating Action Button elevation when disabled while highlighted - effect', (WidgetTester tester) async {
282 283
    await tester.pumpWidget(
      MaterialApp(
284
        theme: material3Theme,
285 286 287 288 289 290 291 292 293 294 295 296
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: () { },
          ),
        ),
      ),
    );
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.press(find.byType(PhysicalShape));
    await tester.pump();
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.pump(const Duration(seconds: 1));
297
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
298
    await tester.pumpWidget(
299 300 301
      MaterialApp(
        theme: material3Theme,
        home: const Scaffold(
302 303 304 305 306 307 308
          floatingActionButton: FloatingActionButton(
            onPressed: null,
          ),
        ),
      ),
    );
    await tester.pump();
309
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
310 311 312 313
    await tester.pump(const Duration(seconds: 1));
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.pumpWidget(
      MaterialApp(
314
        theme: material3Theme,
315 316 317 318 319 320 321 322 323 324 325 326 327
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
            onPressed: () { },
          ),
        ),
      ),
    );
    await tester.pump();
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    await tester.pump(const Duration(seconds: 1));
    expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
  });

328
  testWidgetsWithLeakTracking('Floating Action Button states elevation', (WidgetTester tester) async {
329 330 331 332
    final FocusNode focusNode = FocusNode();

    await tester.pumpWidget(
      MaterialApp(
333
        theme: material3Theme,
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368
        home: Scaffold(
          body: FloatingActionButton.extended(
            label: const Text('tooltip'),
            onPressed: () {},
            focusNode: focusNode,
          ),
        ),
      ),
    );

    final Finder fabFinder = find.byType(PhysicalShape);
    PhysicalShape getFABWidget(Finder finder) => tester.widget<PhysicalShape>(finder);

    // Default, not disabled.
    expect(getFABWidget(fabFinder).elevation, 6);

    // Focused.
    focusNode.requestFocus();
    await tester.pumpAndSettle();
    expect(getFABWidget(fabFinder).elevation, 6);

    // Hovered.
    final Offset center = tester.getCenter(fabFinder);
    final TestGesture gesture = await tester.createGesture(
      kind: PointerDeviceKind.mouse,
    );
    await gesture.addPointer();
    await gesture.moveTo(center);
    await tester.pumpAndSettle();
    expect(getFABWidget(fabFinder).elevation, 8);

    // Highlighted (pressed).
    await gesture.down(center);
    await tester.pump(); // Start the splash and highlight animations.
    await tester.pump(const Duration(milliseconds: 800)); // Wait for splash and highlight to be well under way.
369
    expect(getFABWidget(fabFinder).elevation, 6);
370 371

    focusNode.dispose();
372 373
  });

374
  testWidgetsWithLeakTracking('FlatActionButton mini size is configurable by ThemeData.materialTapTargetSize', (WidgetTester tester) async {
375
    final Key key1 = UniqueKey();
376
    await tester.pumpWidget(
377 378 379 380 381
      MaterialApp(
        home: Theme(
          data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.padded),
          child: Scaffold(
            floatingActionButton: FloatingActionButton(
382 383 384 385 386 387 388 389 390 391 392
              key: key1,
              mini: true,
              onPressed: null,
            ),
          ),
        ),
      ),
    );

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

393
    final Key key2 = UniqueKey();
394
    await tester.pumpWidget(
395 396 397 398 399
      MaterialApp(
        home: Theme(
          data: ThemeData(materialTapTargetSize: MaterialTapTargetSize.shrinkWrap),
          child: Scaffold(
            floatingActionButton: FloatingActionButton(
400 401 402 403 404 405 406 407 408 409 410 411
              key: key2,
              mini: true,
              onPressed: null,
            ),
          ),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(key2)), const Size(40.0, 40.0));
  });

412
  testWidgetsWithLeakTracking('FloatingActionButton.isExtended', (WidgetTester tester) async {
413
    await tester.pumpWidget(
414 415 416
      MaterialApp(
        theme: material3Theme,
        home: const Scaffold(
417
          floatingActionButton: FloatingActionButton(onPressed: null),
418 419 420 421 422 423 424 425 426 427
        ),
      ),
    );

    final Finder fabFinder = find.byType(FloatingActionButton);

    FloatingActionButton getFabWidget() {
      return tester.widget<FloatingActionButton>(fabFinder);
    }

428 429 430 431 432 433
    final Finder materialButtonFinder = find.byType(RawMaterialButton);

    RawMaterialButton getRawMaterialButtonWidget() {
      return tester.widget<RawMaterialButton>(materialButtonFinder);
    }

434
    expect(getFabWidget().isExtended, false);
435 436 437 438
    expect(
      getRawMaterialButtonWidget().shape,
      const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)))
    );
439 440

    await tester.pumpWidget(
441
      const MaterialApp(
442 443
        home: Scaffold(
          floatingActionButton: FloatingActionButton.extended(
444
            label: SizedBox(
445
              width: 100.0,
446
              child: Text('label'),
447
            ),
448
            icon: Icon(Icons.android),
449 450 451 452 453 454 455
            onPressed: null,
          ),
        ),
      ),
    );

    expect(getFabWidget().isExtended, true);
456 457 458 459
    expect(
      getRawMaterialButtonWidget().shape,
      const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)))
    );
460 461 462
    expect(find.text('label'), findsOneWidget);
    expect(find.byType(Icon), findsOneWidget);

463
    // Verify that the widget's height is 56 and that its internal
464
    /// horizontal layout is: 16 icon 8 label 20
465
    expect(tester.getSize(fabFinder).height, 56.0);
466

467 468 469 470 471 472 473 474 475
    final double fabLeft = tester.getTopLeft(fabFinder).dx;
    final double fabRight = tester.getTopRight(fabFinder).dx;
    final double iconLeft = tester.getTopLeft(find.byType(Icon)).dx;
    final double iconRight = tester.getTopRight(find.byType(Icon)).dx;
    final double labelLeft = tester.getTopLeft(find.text('label')).dx;
    final double labelRight = tester.getTopRight(find.text('label')).dx;
    expect(iconLeft - fabLeft, 16.0);
    expect(labelLeft - iconRight, 8.0);
    expect(fabRight - labelRight, 20.0);
476 477 478 479 480 481

    // The overall width of the button is:
    // 168 = 16 + 24(icon) + 8 + 100(label) + 20
    expect(tester.getSize(find.byType(Icon)).width, 24.0);
    expect(tester.getSize(find.text('label')).width, 100.0);
    expect(tester.getSize(fabFinder).width, 168);
482 483
  });

484
  testWidgetsWithLeakTracking('FloatingActionButton.isExtended (without icon)', (WidgetTester tester) async {
485 486 487 488 489 490
    final Finder fabFinder = find.byType(FloatingActionButton);

    FloatingActionButton getFabWidget() {
      return tester.widget<FloatingActionButton>(fabFinder);
    }

491 492 493 494 495 496
    final Finder materialButtonFinder = find.byType(RawMaterialButton);

    RawMaterialButton getRawMaterialButtonWidget() {
      return tester.widget<RawMaterialButton>(materialButtonFinder);
    }

497
    await tester.pumpWidget(
498 499 500
      MaterialApp(
        theme: material3Theme,
        home: const Scaffold(
501
          floatingActionButton: FloatingActionButton.extended(
502
            label: SizedBox(
503 504 505 506 507 508 509 510 511 512
              width: 100.0,
              child: Text('label'),
            ),
            onPressed: null,
          ),
        ),
      ),
    );

    expect(getFabWidget().isExtended, true);
513 514 515 516
    expect(
        getRawMaterialButtonWidget().shape,
        const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(16.0)))
    );
517 518 519
    expect(find.text('label'), findsOneWidget);
    expect(find.byType(Icon), findsNothing);

520
    // Verify that the widget's height is 56 and that its internal
521
    /// horizontal layout is: 20 label 20
522
    expect(tester.getSize(fabFinder).height, 56.0);
523 524 525 526 527 528 529 530 531 532 533 534 535 536

    final double fabLeft = tester.getTopLeft(fabFinder).dx;
    final double fabRight = tester.getTopRight(fabFinder).dx;
    final double labelLeft = tester.getTopLeft(find.text('label')).dx;
    final double labelRight = tester.getTopRight(find.text('label')).dx;
    expect(labelLeft - fabLeft, 20.0);
    expect(fabRight - labelRight, 20.0);

    // The overall width of the button is:
    // 140 = 20 + 100(label) + 20
    expect(tester.getSize(find.text('label')).width, 100.0);
    expect(tester.getSize(fabFinder).width, 140);
  });

537
  testWidgetsWithLeakTracking('Floating Action Button heroTag', (WidgetTester tester) async {
538
    late BuildContext theContext;
539
    await tester.pumpWidget(
540 541 542
      MaterialApp(
        home: Scaffold(
          body: Builder(
543 544 545 546 547 548 549 550 551
            builder: (BuildContext context) {
              theContext = context;
              return const FloatingActionButton(heroTag: 1, onPressed: null);
            },
          ),
          floatingActionButton: const FloatingActionButton(heroTag: 2, onPressed: null),
        ),
      ),
    );
552
    Navigator.push(theContext, PageRouteBuilder<void>(
553 554 555 556 557 558 559
      pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
        return const Placeholder();
      },
    ));
    await tester.pump(); // this would fail if heroTag was the same on both FloatingActionButtons (see below).
  });

560
  testWidgetsWithLeakTracking('Floating Action Button heroTag - with duplicate', (WidgetTester tester) async {
561
    late BuildContext theContext;
562
    await tester.pumpWidget(
563 564 565
      MaterialApp(
        home: Scaffold(
          body: Builder(
566 567 568 569 570 571 572 573 574
            builder: (BuildContext context) {
              theContext = context;
              return const FloatingActionButton(onPressed: null);
            },
          ),
          floatingActionButton: const FloatingActionButton(onPressed: null),
        ),
      ),
    );
575
    Navigator.push(theContext, PageRouteBuilder<void>(
576 577 578 579 580 581 582 583
      pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
        return const Placeholder();
      },
    ));
    await tester.pump();
    expect(tester.takeException().toString(), contains('FloatingActionButton'));
  });

584
  testWidgetsWithLeakTracking('Floating Action Button heroTag - with duplicate', (WidgetTester tester) async {
585
    late BuildContext theContext;
586
    await tester.pumpWidget(
587 588 589
      MaterialApp(
        home: Scaffold(
          body: Builder(
590 591 592 593 594 595 596 597 598
            builder: (BuildContext context) {
              theContext = context;
              return const FloatingActionButton(heroTag: 'xyzzy', onPressed: null);
            },
          ),
          floatingActionButton: const FloatingActionButton(heroTag: 'xyzzy', onPressed: null),
        ),
      ),
    );
599
    Navigator.push(theContext, PageRouteBuilder<void>(
600 601 602 603 604 605 606
      pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
        return const Placeholder();
      },
    ));
    await tester.pump();
    expect(tester.takeException().toString(), contains('xyzzy'));
  });
607

608
  testWidgetsWithLeakTracking('Floating Action Button semantics (enabled)', (WidgetTester tester) async {
609
    final SemanticsTester semantics = SemanticsTester(tester);
610 611

    await tester.pumpWidget(
612
      Directionality(
613
        textDirection: TextDirection.ltr,
614 615
        child: Center(
          child: FloatingActionButton(
616 617 618 619 620 621 622
            onPressed: () { },
            child: const Icon(Icons.add, semanticLabel: 'Add'),
          ),
        ),
      ),
    );

623
    expect(semantics, hasSemantics(TestSemantics.root(
624
      children: <TestSemantics>[
625
        TestSemantics.rootChild(
626 627 628
          label: 'Add',
          flags: <SemanticsFlag>[
            SemanticsFlag.hasEnabledState,
629
            SemanticsFlag.isButton,
630
            SemanticsFlag.isEnabled,
631
            SemanticsFlag.isFocusable,
632 633
          ],
          actions: <SemanticsAction>[
634
            SemanticsAction.tap,
635 636 637 638 639 640 641 642
          ],
        ),
      ],
    ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

    semantics.dispose();
  });

643
  testWidgetsWithLeakTracking('Floating Action Button semantics (disabled)', (WidgetTester tester) async {
644
    final SemanticsTester semantics = SemanticsTester(tester);
645 646 647 648

    await tester.pumpWidget(
      const Directionality(
        textDirection: TextDirection.ltr,
649 650
        child: Center(
          child: FloatingActionButton(
651
            onPressed: null,
652
            child: Icon(Icons.add, semanticLabel: 'Add'),
653 654 655 656 657
          ),
        ),
      ),
    );

658
    expect(semantics, hasSemantics(TestSemantics.root(
659
      children: <TestSemantics>[
660
        TestSemantics.rootChild(
661 662 663 664 665 666 667 668 669 670 671
          label: 'Add',
          flags: <SemanticsFlag>[
            SemanticsFlag.isButton,
            SemanticsFlag.hasEnabledState,
          ],
        ),
      ],
    ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

    semantics.dispose();
  });
672

673
  testWidgetsWithLeakTracking('Tooltip is used as semantics tooltip', (WidgetTester tester) async {
674
    final SemanticsTester semantics = SemanticsTester(tester);
675 676

    await tester.pumpWidget(
677 678 679
      MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton(
680 681 682 683 684 685 686 687
            onPressed: () { },
            tooltip: 'Add Photo',
            child: const Icon(Icons.add_a_photo),
          ),
        ),
      ),
    );

688
    expect(semantics, hasSemantics(TestSemantics.root(
689
      children: <TestSemantics>[
690
        TestSemantics.rootChild(
691
          children: <TestSemantics>[
692
            TestSemantics(
693
              children: <TestSemantics>[
694
                TestSemantics(
695
                  flags: <SemanticsFlag>[
696 697 698 699
                    SemanticsFlag.scopesRoute,
                  ],
                  children: <TestSemantics>[
                    TestSemantics(
700
                      tooltip: 'Add Photo',
701 702 703 704 705 706 707 708 709 710
                      actions: <SemanticsAction>[
                        SemanticsAction.tap,
                      ],
                      flags: <SemanticsFlag>[
                        SemanticsFlag.hasEnabledState,
                        SemanticsFlag.isButton,
                        SemanticsFlag.isEnabled,
                        SemanticsFlag.isFocusable,
                      ],
                    ),
711 712
                  ],
                ),
713 714
              ],
            ),
715 716 717 718 719 720 721 722
          ],
        ),
      ],
    ), ignoreTransform: true, ignoreId: true, ignoreRect: true));

    semantics.dispose();
  });

723
  testWidgetsWithLeakTracking('extended FAB hero transitions succeed', (WidgetTester tester) async {
724
    // Regression test for https://github.com/flutter/flutter/issues/18782
725

726
    await tester.pumpWidget(
727 728 729
      MaterialApp(
        home: Scaffold(
          floatingActionButton: Builder(
730
            builder: (BuildContext context) { // define context of Navigator.push()
731
              return FloatingActionButton.extended(
732 733 734
                icon: const Icon(Icons.add),
                label: const Text('A long FAB label'),
                onPressed: () {
735
                  Navigator.push(context, MaterialPageRoute<void>(
736
                    builder: (BuildContext context) {
737 738
                      return Scaffold(
                        floatingActionButton: FloatingActionButton.extended(
739 740 741 742
                          icon: const Icon(Icons.add),
                          label: const Text('X'),
                          onPressed: () { },
                        ),
743
                        body: Center(
744
                          child: ElevatedButton(
745 746 747 748 749 750 751 752 753 754 755 756 757 758
                            child: const Text('POP'),
                            onPressed: () {
                              Navigator.pop(context);
                            },
                          ),
                        ),
                      );
                    },
                  ));
                },
              );
            },
          ),
          body: const Center(
759
            child: Text('Hello World'),
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
          ),
        ),
      ),
    );

    final Finder longFAB = find.text('A long FAB label');
    final Finder shortFAB = find.text('X');
    final Finder helloWorld = find.text('Hello World');

    expect(longFAB, findsOneWidget);
    expect(shortFAB, findsNothing);
    expect(helloWorld, findsOneWidget);

    await tester.tap(longFAB);
    await tester.pumpAndSettle();

    expect(shortFAB, findsOneWidget);
    expect(longFAB, findsNothing);

    // Trigger a hero transition from shortFAB to longFAB.
    await tester.tap(find.text('POP'));
    await tester.pumpAndSettle();

    expect(longFAB, findsOneWidget);
    expect(shortFAB, findsNothing);
    expect(helloWorld, findsOneWidget);
  });
787 788

  // This test prevents https://github.com/flutter/flutter/issues/20483
789
  testWidgetsWithLeakTracking('Floating Action Button clips ink splash and highlight', (WidgetTester tester) async {
790
    final GlobalKey key = GlobalKey();
791
    await tester.pumpWidget(
792
      MaterialApp(
793
        theme: material3Theme,
794 795 796
        home: Scaffold(
          body: Center(
            child: RepaintBoundary(
797
              key: key,
798
              child: FloatingActionButton(
799
                onPressed: () { },
800 801 802 803 804 805 806 807 808 809 810 811 812
                child: const Icon(Icons.add),
              ),
            ),
          ),
        ),
      ),
    );

    await tester.press(find.byKey(key));
    await tester.pump();
    await tester.pump(const Duration(milliseconds: 1000));
    await expectLater(
      find.byKey(key),
813
      matchesGoldenFile('floating_action_button_test.clip.png'),
814 815
    );
  });
816

817
  testWidgetsWithLeakTracking('Floating Action Button changes mouse cursor when hovered', (WidgetTester tester) async {
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: Align(
            alignment: Alignment.topLeft,
            child: FloatingActionButton.extended(
              onPressed: () { },
              mouseCursor: SystemMouseCursors.text,
              label: const Text('label'),
              icon: const Icon(Icons.android),
            ),
          ),
        ),
      ),
    );

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

    await tester.pump();

839
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856

    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: Align(
            alignment: Alignment.topLeft,
            child: FloatingActionButton(
              onPressed: () { },
              mouseCursor: SystemMouseCursors.text,
              child: const Icon(Icons.add),
            ),
          ),
        ),
      ),
    );

    await gesture.moveTo(tester.getCenter(find.byType(FloatingActionButton)));
857
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873

    // Test default cursor
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: Align(
            alignment: Alignment.topLeft,
            child: FloatingActionButton(
              onPressed: () { },
              child: const Icon(Icons.add),
            ),
          ),
        ),
      ),
    );

874
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890

    // Test default cursor when disabled
    await tester.pumpWidget(
      const MaterialApp(
        home: Scaffold(
          body: Align(
            alignment: Alignment.topLeft,
            child: FloatingActionButton(
              onPressed: null,
              child: Icon(Icons.add),
            ),
          ),
        ),
      ),
    );

891
    expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
892 893
  });

894
  testWidgetsWithLeakTracking('Floating Action Button has no clip by default', (WidgetTester tester) async {
895
    final FocusNode focusNode = FocusNode();
896
    await tester.pumpWidget(
897
      Directionality(
898
        textDirection: TextDirection.ltr,
899 900 901
        child: FloatingActionButton(
          focusNode: focusNode,
          onPressed: () { /* to make sure the button is enabled */ },
902
        ),
903 904 905
      ),
    );

906 907 908
    focusNode.unfocus();
    await tester.pump();

909
    expect(
910 911
      tester.renderObject(find.byType(FloatingActionButton)),
      paintsExactlyCountTimes(#clipPath, 0),
912
    );
913 914

    focusNode.dispose();
915
  });
916

917
  testWidgetsWithLeakTracking('Can find FloatingActionButton semantics', (WidgetTester tester) async {
918 919 920 921 922 923 924 925 926 927 928
    await tester.pumpWidget(MaterialApp(
      home: FloatingActionButton(onPressed: () {}),
    ));

    expect(
      tester.getSemantics(find.byType(FloatingActionButton)),
      matchesSemantics(
        hasTapAction: true,
        hasEnabledState: true,
        isButton: true,
        isEnabled: true,
929
        isFocusable: true,
930 931
      ),
    );
932
  });
933

934
  testWidgetsWithLeakTracking('Foreground color applies to icon on fab', (WidgetTester tester) async {
935 936 937 938 939 940 941 942 943 944 945 946 947
    const Color foregroundColor = Color(0xcafefeed);

    await tester.pumpWidget(MaterialApp(
      home: FloatingActionButton(
        onPressed: () {},
        foregroundColor: foregroundColor,
        child: const Icon(Icons.access_alarm),
      ),
    ));

    final RichText iconRichText = tester.widget<RichText>(
      find.descendant(of: find.byIcon(Icons.access_alarm), matching: find.byType(RichText)),
    );
948
    expect(iconRichText.text.style!.color, foregroundColor);
949
  });
950

951
  testWidgetsWithLeakTracking('FloatingActionButton uses custom splash color', (WidgetTester tester) async {
952 953 954
    const Color splashColor = Color(0xcafefeed);

    await tester.pumpWidget(MaterialApp(
955
      theme: material2Theme,
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
      home: FloatingActionButton(
        onPressed: () {},
        splashColor: splashColor,
        child: const Icon(Icons.access_alarm),
      ),
    ));

    await tester.press(find.byType(FloatingActionButton));
    await tester.pumpAndSettle();

    expect(
      find.byType(FloatingActionButton),
      paints..circle(color: splashColor),
    );
  });
971

972
  testWidgetsWithLeakTracking('extended FAB does not show label when isExtended is false', (WidgetTester tester) async {
973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
    const Key iconKey = Key('icon');
    const Key labelKey = Key('label');

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: FloatingActionButton.extended(
          isExtended: false,
          label: const Text('', key: labelKey),
          icon: const Icon(Icons.add, key: iconKey),
          onPressed: () {},
        ),
      ),
    );

    // Verify that Icon is present and label is not.
    expect(find.byKey(iconKey), findsOneWidget);
    expect(find.byKey(labelKey), findsNothing);
  });
992

993
  testWidgetsWithLeakTracking('FloatingActionButton.small configures correct size', (WidgetTester tester) async {
994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
    final Key key = UniqueKey();
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton.small(
            key: key,
            materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
            onPressed: null,
          ),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(key)), const Size(40.0, 40.0));
  });

1010
  testWidgetsWithLeakTracking('FloatingActionButton.large configures correct size', (WidgetTester tester) async {
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025
    final Key key = UniqueKey();
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton.large(
            key: key,
            onPressed: null,
          ),
        ),
      ),
    );

    expect(tester.getSize(find.byKey(key)), const Size(96.0, 96.0));
  });

1026
  testWidgetsWithLeakTracking('FloatingActionButton.extended can customize spacing', (WidgetTester tester) async {
1027 1028 1029
    const Key iconKey = Key('icon');
    const Key labelKey = Key('label');
    const double spacing = 33.0;
1030
    const EdgeInsetsDirectional padding = EdgeInsetsDirectional.only(start: 5.0, end: 6.0);
1031 1032 1033 1034 1035 1036 1037 1038

    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          floatingActionButton: FloatingActionButton.extended(
            label: const Text('', key: labelKey),
            icon: const Icon(Icons.add, key: iconKey),
            extendedIconLabelSpacing: spacing,
1039
            extendedPadding: padding,
1040 1041 1042 1043 1044 1045 1046
            onPressed: () {},
          ),
        ),
      ),
    );

    expect(tester.getTopLeft(find.byKey(labelKey)).dx - tester.getTopRight(find.byKey(iconKey)).dx, spacing);
1047 1048
    expect(tester.getTopLeft(find.byKey(iconKey)).dx - tester.getTopLeft(find.byType(FloatingActionButton)).dx, padding.start);
    expect(tester.getTopRight(find.byType(FloatingActionButton)).dx - tester.getTopRight(find.byKey(labelKey)).dx, padding.end);
1049 1050
  });

1051
  testWidgetsWithLeakTracking('FloatingActionButton.extended can customize text style', (WidgetTester tester) async {
1052 1053 1054 1055 1056
    const Key labelKey = Key('label');
    const TextStyle style = TextStyle(letterSpacing: 2.0);

    await tester.pumpWidget(
      MaterialApp(
1057
        theme: material2Theme,
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078
        home: Scaffold(
          floatingActionButton: FloatingActionButton.extended(
            label: const Text('', key: labelKey),
            icon: const Icon(Icons.add),
            extendedTextStyle: style,
            onPressed: () {},
          ),
        ),
      ),
    );

    final RawMaterialButton rawMaterialButton = tester.widget<RawMaterialButton>(
      find.descendant(
        of: find.byType(FloatingActionButton),
        matching: find.byType(RawMaterialButton),
      ),
    );
    // The color comes from the default color scheme's onSecondary value.
    expect(rawMaterialButton.textStyle, style.copyWith(color: const Color(0xffffffff)));
  });

1079
  group('Material 2', () {
1080 1081 1082
    // These tests are only relevant for Material 2. Once Material 2
    // support is deprecated and the APIs are removed, these tests
    // can be deleted.
1083

1084
    testWidgetsWithLeakTracking('Floating Action Button elevation when highlighted - effect', (WidgetTester tester) async {
1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: Scaffold(
            floatingActionButton: FloatingActionButton(
              onPressed: () { },
            ),
          ),
        ),
      );
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
      final TestGesture gesture = await tester.press(find.byType(PhysicalShape));
      await tester.pump();
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
      await tester.pump(const Duration(seconds: 1));
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 12.0);
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: Scaffold(
            floatingActionButton: FloatingActionButton(
              onPressed: () { },
              highlightElevation: 20.0,
            ),
          ),
        ),
      );
      await tester.pump();
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 12.0);
      await tester.pump(const Duration(seconds: 1));
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 20.0);
      await gesture.up();
      await tester.pump();
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 20.0);
      await tester.pump(const Duration(seconds: 1));
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    });

1123
    testWidgetsWithLeakTracking('Floating Action Button elevation when disabled while highlighted - effect', (WidgetTester tester) async {
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: Scaffold(
            floatingActionButton: FloatingActionButton(
              onPressed: () { },
            ),
          ),
        ),
      );
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
      await tester.press(find.byType(PhysicalShape));
      await tester.pump();
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
      await tester.pump(const Duration(seconds: 1));
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 12.0);
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: const Scaffold(
            floatingActionButton: FloatingActionButton(
              onPressed: null,
            ),
          ),
        ),
      );
      await tester.pump();
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 12.0);
      await tester.pump(const Duration(seconds: 1));
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: Scaffold(
            floatingActionButton: FloatingActionButton(
              onPressed: () { },
            ),
          ),
        ),
      );
      await tester.pump();
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
      await tester.pump(const Duration(seconds: 1));
      expect(tester.widget<PhysicalShape>(find.byType(PhysicalShape)).elevation, 6.0);
    });

1170
    testWidgetsWithLeakTracking('Floating Action Button states elevation', (WidgetTester tester) async {
1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
      final FocusNode focusNode = FocusNode();

      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: Scaffold(
            body: FloatingActionButton.extended(
              label: const Text('tooltip'),
              onPressed: () {},
              focusNode: focusNode,
            ),
          ),
        ),
      );

      final Finder fabFinder = find.byType(PhysicalShape);
      PhysicalShape getFABWidget(Finder finder) => tester.widget<PhysicalShape>(finder);

      // Default, not disabled.
      expect(getFABWidget(fabFinder).elevation, 6);

      // Focused.
      focusNode.requestFocus();
      await tester.pumpAndSettle();
      expect(getFABWidget(fabFinder).elevation, 6);

      // Hovered.
      final Offset center = tester.getCenter(fabFinder);
      final TestGesture gesture = await tester.createGesture(
        kind: PointerDeviceKind.mouse,
      );
      await gesture.addPointer();
      await gesture.moveTo(center);
      await tester.pumpAndSettle();
      expect(getFABWidget(fabFinder).elevation, 8);

      // Highlighted (pressed).
      await gesture.down(center);
      await tester.pump(); // Start the splash and highlight animations.
      await tester.pump(const Duration(milliseconds: 800)); // Wait for splash and highlight to be well under way.
      expect(getFABWidget(fabFinder).elevation, 12);
1212 1213

      focusNode.dispose();
1214 1215
    });

1216
    testWidgetsWithLeakTracking('FloatingActionButton.isExtended', (WidgetTester tester) async {
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: const Scaffold(
            floatingActionButton: FloatingActionButton(onPressed: null),
          ),
        ),
      );

      final Finder fabFinder = find.byType(FloatingActionButton);

      FloatingActionButton getFabWidget() {
        return tester.widget<FloatingActionButton>(fabFinder);
      }

      final Finder materialButtonFinder = find.byType(RawMaterialButton);

      RawMaterialButton getRawMaterialButtonWidget() {
        return tester.widget<RawMaterialButton>(materialButtonFinder);
      }

      expect(getFabWidget().isExtended, false);
      expect(getRawMaterialButtonWidget().shape, const CircleBorder());

      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: const Scaffold(
            floatingActionButton: FloatingActionButton.extended(
              label: SizedBox(
                width: 100.0,
                child: Text('label'),
              ),
              icon: Icon(Icons.android),
              onPressed: null,
            ),
          ),
        ),
      );

      expect(getFabWidget().isExtended, true);
      expect(getRawMaterialButtonWidget().shape, const StadiumBorder());
      expect(find.text('label'), findsOneWidget);
      expect(find.byType(Icon), findsOneWidget);

      // Verify that the widget's height is 48 and that its internal
      /// horizontal layout is: 16 icon 8 label 20
      expect(tester.getSize(fabFinder).height, 48.0);

      final double fabLeft = tester.getTopLeft(fabFinder).dx;
      final double fabRight = tester.getTopRight(fabFinder).dx;
      final double iconLeft = tester.getTopLeft(find.byType(Icon)).dx;
      final double iconRight = tester.getTopRight(find.byType(Icon)).dx;
      final double labelLeft = tester.getTopLeft(find.text('label')).dx;
      final double labelRight = tester.getTopRight(find.text('label')).dx;
      expect(iconLeft - fabLeft, 16.0);
      expect(labelLeft - iconRight, 8.0);
      expect(fabRight - labelRight, 20.0);

      // The overall width of the button is:
      // 168 = 16 + 24(icon) + 8 + 100(label) + 20
      expect(tester.getSize(find.byType(Icon)).width, 24.0);
      expect(tester.getSize(find.text('label')).width, 100.0);
      expect(tester.getSize(fabFinder).width, 168);
    });

1283
    testWidgetsWithLeakTracking('FloatingActionButton.isExtended (without icon)', (WidgetTester tester) async {
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 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334
      final Finder fabFinder = find.byType(FloatingActionButton);

      FloatingActionButton getFabWidget() {
        return tester.widget<FloatingActionButton>(fabFinder);
      }

      final Finder materialButtonFinder = find.byType(RawMaterialButton);

      RawMaterialButton getRawMaterialButtonWidget() {
        return tester.widget<RawMaterialButton>(materialButtonFinder);
      }

      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: const Scaffold(
            floatingActionButton: FloatingActionButton.extended(
              label: SizedBox(
                width: 100.0,
                child: Text('label'),
              ),
              onPressed: null,
            ),
          ),
        ),
      );

      expect(getFabWidget().isExtended, true);
      expect(getRawMaterialButtonWidget().shape, const StadiumBorder());
      expect(find.text('label'), findsOneWidget);
      expect(find.byType(Icon), findsNothing);

      // Verify that the widget's height is 48 and that its internal
      /// horizontal layout is: 20 label 20
      expect(tester.getSize(fabFinder).height, 48.0);

      final double fabLeft = tester.getTopLeft(fabFinder).dx;
      final double fabRight = tester.getTopRight(fabFinder).dx;
      final double labelLeft = tester.getTopLeft(find.text('label')).dx;
      final double labelRight = tester.getTopRight(find.text('label')).dx;
      expect(labelLeft - fabLeft, 20.0);
      expect(fabRight - labelRight, 20.0);

      // The overall width of the button is:
      // 140 = 20 + 100(label) + 20
      expect(tester.getSize(find.text('label')).width, 100.0);
      expect(tester.getSize(fabFinder).width, 140);
    });


    // This test prevents https://github.com/flutter/flutter/issues/20483
1335
    testWidgetsWithLeakTracking('Floating Action Button clips ink splash and highlight', (WidgetTester tester) async {
1336 1337 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
      final GlobalKey key = GlobalKey();
      await tester.pumpWidget(
        MaterialApp(
          theme: material2Theme,
          home: Scaffold(
            body: Center(
              child: RepaintBoundary(
                key: key,
                child: FloatingActionButton(
                  onPressed: () { },
                  child: const Icon(Icons.add),
                ),
              ),
            ),
          ),
        ),
      );

      await tester.press(find.byKey(key));
      await tester.pump();
      await tester.pump(const Duration(milliseconds: 1000));
      await expectLater(
        find.byKey(key),
        matchesGoldenFile('floating_action_button_test_m2.clip.png'),
      );
    });
  });

1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374
  group('feedback', () {
    late FeedbackTester feedback;

    setUp(() {
      feedback = FeedbackTester();
    });

    tearDown(() {
      feedback.dispose();
    });

1375
    testWidgetsWithLeakTracking('FloatingActionButton with enabled feedback', (WidgetTester tester) async {
1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
      const bool enableFeedback = true;

      await tester.pumpWidget(MaterialApp(
        home: FloatingActionButton(
          onPressed: () {},
          enableFeedback: enableFeedback,
          child: const Icon(Icons.access_alarm),
        ),
      ));

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

1392
    testWidgetsWithLeakTracking('FloatingActionButton with disabled feedback', (WidgetTester tester) async {
1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
      const bool enableFeedback = false;

      await tester.pumpWidget(MaterialApp(
        home: FloatingActionButton(
          onPressed: () {},
          enableFeedback: enableFeedback,
          child: const Icon(Icons.access_alarm),
        ),
      ));

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

1409
    testWidgetsWithLeakTracking('FloatingActionButton with enabled feedback by default', (WidgetTester tester) async {
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422
      await tester.pumpWidget(MaterialApp(
        home: FloatingActionButton(
          onPressed: () {},
          child: const Icon(Icons.access_alarm),
        ),
      ));

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

1423
    testWidgetsWithLeakTracking('FloatingActionButton with disabled feedback using FloatingActionButtonTheme', (WidgetTester tester) async {
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
      const bool enableFeedbackTheme = false;
      final ThemeData theme = ThemeData(
        floatingActionButtonTheme: const FloatingActionButtonThemeData(
          enableFeedback: enableFeedbackTheme,
        ),
      );

      await tester.pumpWidget(MaterialApp(
        home: Theme(
          data: theme,
          child: FloatingActionButton(
            onPressed: () {},
            child: const Icon(Icons.access_alarm),
          ),
        ),
      ));

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

1447
    testWidgetsWithLeakTracking('FloatingActionButton.enableFeedback is overridden by FloatingActionButtonThemeData.enableFeedback', (WidgetTester tester) async {
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
      const bool enableFeedbackTheme = false;
      const bool enableFeedback = true;
      final ThemeData theme = ThemeData(
        floatingActionButtonTheme: const FloatingActionButtonThemeData(
          enableFeedback: enableFeedbackTheme,
        ),
      );

      await tester.pumpWidget(MaterialApp(
        home: Theme(
          data: theme,
          child: FloatingActionButton(
            enableFeedback: enableFeedback,
            onPressed: () {},
            child: const Icon(Icons.access_alarm),
          ),
        ),
      ));

      await tester.tap(find.byType(RawMaterialButton));
      await tester.pump(const Duration(seconds: 1));
      expect(feedback.clickSoundCount, 1);
      expect(feedback.hapticCount, 0);
    });
  });
1473
}
1474 1475 1476 1477 1478

Offset _rightEdgeOfFab(WidgetTester tester) {
  final Finder fab = find.byType(FloatingActionButton);
  return tester.getRect(fab).centerRight - const Offset(1.0, 0.0);
}