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

5 6
import 'dart:math';

7 8 9
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
10
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
11

12
void main() {
13
  group('Basic floating action button locations', () {
14
    testWidgetsWithLeakTracking('still animates motion when the floating action button is null', (WidgetTester tester) async {
15
      await tester.pumpWidget(_buildFrame(fab: null));
16 17 18 19

      expect(find.byType(FloatingActionButton), findsNothing);
      expect(tester.binding.transientCallbackCount, 0);

20
      await tester.pumpWidget(_buildFrame(fab: null, location: FloatingActionButtonLocation.endFloat));
21 22 23 24

      expect(find.byType(FloatingActionButton), findsNothing);
      expect(tester.binding.transientCallbackCount, greaterThan(0));

25
      await tester.pumpWidget(_buildFrame(fab: null, location: FloatingActionButtonLocation.centerFloat));
26 27 28 29 30

      expect(find.byType(FloatingActionButton), findsNothing);
      expect(tester.binding.transientCallbackCount, greaterThan(0));
    });

31
    testWidgetsWithLeakTracking('moves fab from center to end and back', (WidgetTester tester) async {
32
      await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.endFloat));
33 34 35 36

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 356.0));
      expect(tester.binding.transientCallbackCount, 0);

37
      await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.centerFloat));
38 39 40 41 42 43 44 45

      expect(tester.binding.transientCallbackCount, greaterThan(0));

      await tester.pumpAndSettle();

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(400.0, 356.0));
      expect(tester.binding.transientCallbackCount, 0);

46
      await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.endFloat));
47

48 49 50 51 52 53 54 55
      expect(tester.binding.transientCallbackCount, greaterThan(0));

      await tester.pumpAndSettle();

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 356.0));
      expect(tester.binding.transientCallbackCount, 0);
    });

56
    testWidgetsWithLeakTracking('moves to and from custom-defined positions', (WidgetTester tester) async {
57
      await tester.pumpWidget(_buildFrame(location: const _StartTopFloatingActionButtonLocation()));
58 59 60

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(44.0, 56.0));

61
      await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.centerFloat));
62 63 64 65 66 67 68
      expect(tester.binding.transientCallbackCount, greaterThan(0));

      await tester.pumpAndSettle();

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(400.0, 356.0));
      expect(tester.binding.transientCallbackCount, 0);

69
      await tester.pumpWidget(_buildFrame(location: const _StartTopFloatingActionButtonLocation()));
70

71 72 73 74 75 76 77 78 79
      expect(tester.binding.transientCallbackCount, greaterThan(0));

      await tester.pumpAndSettle();

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(44.0, 56.0));
      expect(tester.binding.transientCallbackCount, 0);

    });

80
    group('interrupts in-progress animations without jumps', () {
81 82 83 84 85
      _GeometryListener? geometryListener;
      ScaffoldGeometry? geometry;
      _GeometryListenerState? listenerState;
      Size? previousRect;
      Iterable<double>? previousRotations;
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101

      // The maximum amounts we expect the fab width and height to change
      // during one step of a transition.
      const double maxDeltaWidth = 12.5;
      const double maxDeltaHeight = 12.5;

      // The maximum amounts we expect the fab icon to rotate during one step
      // of a transition.
      const double maxDeltaRotation = 0.09;

      // We'll listen to the Scaffold's geometry for any 'jumps' to detect
      // changes in the size and rotation of the fab.
      void setupListener(WidgetTester tester) {
        // Measure the delta in width and height of the fab, and check that it never grows
        // by more than the expected maximum deltas.
        void check() {
102 103
          geometry = listenerState?.cache.value;
          final Size? currentRect = geometry?.floatingActionButtonArea?.size;
104 105 106
          // Measure the delta in width and height of the rect, and check that
          // it never grows by more than a safe amount.
          if (previousRect != null && currentRect != null) {
107 108
            final double deltaWidth = currentRect.width - previousRect!.width;
            final double deltaHeight = currentRect.height - previousRect!.height;
109 110 111 112 113
            expect(
              deltaWidth.abs(),
              lessThanOrEqualTo(maxDeltaWidth),
              reason: "The Floating Action Button's width should not change "
                  'faster than $maxDeltaWidth per animation step.\n'
114
                  'Previous rect: $previousRect, current rect: $currentRect',
115 116 117 118 119 120
            );
            expect(
              deltaHeight.abs(),
              lessThanOrEqualTo(maxDeltaHeight),
              reason: "The Floating Action Button's width should not change "
                  'faster than $maxDeltaHeight per animation step.\n'
121
                  'Previous rect: $previousRect, current rect: $currentRect',
122 123 124 125 126 127 128
            );
          }
          previousRect = currentRect;

          // Measure the delta in rotation.
          // Check that it never grows by more than a safe amount.
          //
129
          // There may be multiple transitions all active at
130 131 132 133
          // the same time. We are concerned only with the closest one.
          final Iterable<RotationTransition> rotationTransitions = tester.widgetList(
            find.byType(RotationTransition),
          );
134
          final Iterable<double> currentRotations = rotationTransitions.map((RotationTransition t) => t.turns.value);
135

136
          if (previousRotations != null && previousRotations!.isNotEmpty && currentRotations.isNotEmpty
137 138
              && previousRect != null && currentRect != null) {
            final List<double> deltas = <double>[];
139
            for (final double currentRotation in currentRotations) {
140 141
              late double minDelta;
              for (final double previousRotation in previousRotations!) {
142
                final double delta = (previousRotation - currentRotation).abs();
143
                minDelta = delta;
144 145 146 147 148 149
                minDelta = min(delta, minDelta);
              }
              deltas.add(minDelta);
            }

            if (deltas.where((double delta) => delta < maxDeltaRotation).isEmpty) {
150 151 152 153 154 155 156
              fail(
                "The Floating Action Button's rotation should not change "
                'faster than $maxDeltaRotation per animation step.\n'
                'Detected deltas were: $deltas\n'
                'Previous values: $previousRotations, current values: $currentRotations\n'
                'Previous rect: $previousRect, current rect: $currentRect',
              );
157 158 159
            }
          }
          previousRotations = currentRotations;
160
        }
161

162
        listenerState = tester.state(find.byType(_GeometryListener));
163
        listenerState!.geometryListenable!.addListener(check);
164
      }
165

166 167 168 169
      setUp(() {
        // We create the geometry listener here, but it can only be set up
        // after it is pumped into the widget tree and a tester is
        // available.
170
        geometryListener = const _GeometryListener();
171 172 173 174 175 176
        geometry = null;
        listenerState = null;
        previousRect = null;
        previousRotations = null;
      });

177
      testWidgetsWithLeakTracking('moving the fab to centerFloat', (WidgetTester tester) async {
178
        // Create a scaffold with the fab at endFloat
179
        await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.endFloat, listener: geometryListener));
180 181 182
        setupListener(tester);

        // Move the fab to centerFloat'
183
        await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.centerFloat, listener: geometryListener));
184 185 186
        await tester.pumpAndSettle();
      });

187
      testWidgetsWithLeakTracking('interrupting motion towards the StartTop location.', (WidgetTester tester) async {
188
        await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.centerFloat, listener: geometryListener));
189 190 191
        setupListener(tester);

        // Move the fab to the top start after creating the fab.
192
        await tester.pumpWidget(_buildFrame(location: const _StartTopFloatingActionButtonLocation(), listener: geometryListener));
193 194 195
        await tester.pump(kFloatingActionButtonSegue ~/ 2);

        // Interrupt motion to move to the end float
196
        await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.endFloat, listener: geometryListener));
197 198 199
        await tester.pumpAndSettle();
      });

200
      testWidgetsWithLeakTracking('interrupting entrance to remove the fab.', (WidgetTester tester) async {
201
        await tester.pumpWidget(_buildFrame(fab: null, location: FloatingActionButtonLocation.centerFloat, listener: geometryListener));
202 203 204
        setupListener(tester);

        // Animate the fab in.
205
        await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.endFloat, listener: geometryListener));
206 207 208 209
        await tester.pump(kFloatingActionButtonSegue ~/ 2);

        // Remove the fab.
        await tester.pumpWidget(
210
          _buildFrame(
211 212 213 214 215 216
            fab: null,
            location: FloatingActionButtonLocation.endFloat,
            listener: geometryListener,
          ),
        );
        await tester.pumpAndSettle();
217
      });
218

219
      testWidgetsWithLeakTracking('interrupting entrance of a new fab.', (WidgetTester tester) async {
220
        await tester.pumpWidget(
221
          _buildFrame(
222 223 224 225 226 227 228 229
            fab: null,
            location: FloatingActionButtonLocation.endFloat,
            listener: geometryListener,
          ),
        );
        setupListener(tester);

        // Bring in a new fab.
230
        await tester.pumpWidget(_buildFrame(location: FloatingActionButtonLocation.centerFloat, listener: geometryListener));
231 232 233 234
        await tester.pump(kFloatingActionButtonSegue ~/ 2);

        // Interrupt motion to move the fab.
        await tester.pumpWidget(
235
          _buildFrame(
236 237 238 239 240 241
            location: FloatingActionButtonLocation.endFloat,
            listener: geometryListener,
          ),
        );
        await tester.pumpAndSettle();
      });
242
    });
243 244
  });

245
  testWidgetsWithLeakTracking('Docked floating action button locations', (WidgetTester tester) async {
246
    await tester.pumpWidget(
247
      _buildFrame(
248 249 250 251 252 253 254 255 256
        location: FloatingActionButtonLocation.endDocked,
        bab: const SizedBox(height: 100.0),
        viewInsets: EdgeInsets.zero,
      ),
    );

    // Scaffold 800x600, FAB is 56x56, BAB is 800x100, FAB's center is
    // at the top of the BAB.
    expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 500.0));
257

258
    await tester.pumpWidget(
259
      _buildFrame(
260 261 262 263 264 265 266 267 268 269
        location: FloatingActionButtonLocation.centerDocked,
        bab: const SizedBox(height: 100.0),
        viewInsets: EdgeInsets.zero,
      ),
    );
    await tester.pumpAndSettle();
    expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(400.0, 500.0));


    await tester.pumpWidget(
270
      _buildFrame(
271 272 273 274 275 276 277
        location: FloatingActionButtonLocation.endDocked,
        bab: const SizedBox(height: 100.0),
        viewInsets: EdgeInsets.zero,
      ),
    );
    await tester.pumpAndSettle();
    expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 500.0));
278
  });
279

280
  testWidgetsWithLeakTracking('Docked floating action button locations: no BAB, small BAB', (WidgetTester tester) async {
281
    await tester.pumpWidget(
282
      _buildFrame(
283 284 285 286 287 288 289
        location: FloatingActionButtonLocation.endDocked,
        viewInsets: EdgeInsets.zero,
      ),
    );
    expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 572.0));

    await tester.pumpWidget(
290
      _buildFrame(
291 292 293 294 295 296
        location: FloatingActionButtonLocation.endDocked,
        bab: const SizedBox(height: 16.0),
        viewInsets: EdgeInsets.zero,
      ),
    );
    expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 572.0));
297
  });
298

299
  testWidgetsWithLeakTracking('Contained floating action button locations', (WidgetTester tester) async {
300 301 302 303 304 305 306 307 308 309 310 311 312 313
    await tester.pumpWidget(
      _buildFrame(
        location: FloatingActionButtonLocation.endContained,
        bab: const SizedBox(height: 100.0),
        viewInsets: EdgeInsets.zero,
      ),
    );

    // Scaffold 800x600, FAB is 56x56, BAB is 800x100, FAB's center is
    // at the top of the BAB.
    // Formula: scaffold height - BAB height + FAB height / 2 + BAB top & bottom margins.
    expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(756.0, 550.0));
 });

314
  testWidgetsWithLeakTracking('Mini-start-top floating action button location', (WidgetTester tester) async {
315 316 317 318 319 320
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          appBar: AppBar(),
          floatingActionButton: FloatingActionButton(onPressed: () { }, mini: true),
          floatingActionButtonLocation: FloatingActionButtonLocation.miniStartTop,
321 322
          body: const Column(
            children: <Widget>[
323 324 325 326 327 328 329 330 331 332
              ListTile(
                leading: CircleAvatar(),
              ),
            ],
          ),
        ),
      ),
    );
    expect(tester.getCenter(find.byType(FloatingActionButton)).dx, tester.getCenter(find.byType(CircleAvatar)).dx);
    expect(tester.getCenter(find.byType(FloatingActionButton)).dy, kToolbarHeight);
333
  });
334

335
  testWidgetsWithLeakTracking('Start-top floating action button location LTR', (WidgetTester tester) async {
336 337 338 339 340 341 342 343 344
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          appBar: AppBar(),
          floatingActionButton: const FloatingActionButton(onPressed: null),
          floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
345
    expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTWH(16.0, 28.0, 56.0, 56.0)));
346
  });
347

348
  testWidgetsWithLeakTracking('End-top floating action button location RTL', (WidgetTester tester) async {
349 350 351 352 353 354 355 356 357 358 359 360
    await tester.pumpWidget(
      MaterialApp(
        home: Directionality(
          textDirection: TextDirection.rtl,
          child: Scaffold(
            appBar: AppBar(),
            floatingActionButton: const FloatingActionButton(onPressed: null),
            floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
          ),
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
361
    expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTWH(16.0, 28.0, 56.0, 56.0)));
362
  });
363

364
  testWidgetsWithLeakTracking('Start-top floating action button location RTL', (WidgetTester tester) async {
365 366 367 368 369 370 371 372 373 374 375 376
    await tester.pumpWidget(
      MaterialApp(
        home: Directionality(
          textDirection: TextDirection.rtl,
          child: Scaffold(
            appBar: AppBar(),
            floatingActionButton: const FloatingActionButton(onPressed: null),
            floatingActionButtonLocation: FloatingActionButtonLocation.startTop,
          ),
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
377
    expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTWH(800.0 - 56.0 - 16.0, 28.0, 56.0, 56.0)));
378
  });
379

380
  testWidgetsWithLeakTracking('End-top floating action button location LTR', (WidgetTester tester) async {
381 382 383 384 385 386 387 388 389
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          appBar: AppBar(),
          floatingActionButton: const FloatingActionButton(onPressed: null),
          floatingActionButtonLocation: FloatingActionButtonLocation.endTop,
        ),
      ),
    );
Dan Field's avatar
Dan Field committed
390
    expect(tester.getRect(find.byType(FloatingActionButton)), rectMoreOrLessEquals(const Rect.fromLTWH(800.0 - 56.0 - 16.0, 28.0, 56.0, 56.0)));
391
  });
392 393

  group('New Floating Action Button Locations', () {
394
    testWidgetsWithLeakTracking('startTop', (WidgetTester tester) async {
395 396 397 398 399
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.startTop));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _topOffsetY));
    });

400
    testWidgetsWithLeakTracking('centerTop', (WidgetTester tester) async {
401 402 403 404 405
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerTop));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _topOffsetY));
    });

406
    testWidgetsWithLeakTracking('endTop', (WidgetTester tester) async {
407 408 409 410 411
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.endTop));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX, _topOffsetY));
    });

412
    testWidgetsWithLeakTracking('startFloat', (WidgetTester tester) async {
413 414 415 416 417
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.startFloat));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _floatOffsetY));
    });

418
    testWidgetsWithLeakTracking('centerFloat', (WidgetTester tester) async {
419 420 421 422 423
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerFloat));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _floatOffsetY));
    });

424
    testWidgetsWithLeakTracking('endFloat', (WidgetTester tester) async {
425 426 427 428 429
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.endFloat));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX, _floatOffsetY));
    });

430
    testWidgetsWithLeakTracking('startDocked', (WidgetTester tester) async {
431 432 433 434 435
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.startDocked));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _dockedOffsetY));
    });

436
    testWidgetsWithLeakTracking('centerDocked', (WidgetTester tester) async {
437 438 439 440 441
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerDocked));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _dockedOffsetY));
    });

442
    testWidgetsWithLeakTracking('endDocked', (WidgetTester tester) async {
443 444 445 446 447
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.endDocked));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX, _dockedOffsetY));
    });

448
    testWidgetsWithLeakTracking('endContained', (WidgetTester tester) async {
449 450 451 452 453
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.endContained));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX, _containedOffsetY));
    });

454
    testWidgetsWithLeakTracking('miniStartTop', (WidgetTester tester) async {
455 456 457 458 459
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniStartTop));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniLeftOffsetX, _topOffsetY));
    });

460
    testWidgetsWithLeakTracking('miniEndTop', (WidgetTester tester) async {
461 462 463 464 465
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniEndTop));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniRightOffsetX, _topOffsetY));
    });

466
    testWidgetsWithLeakTracking('miniStartFloat', (WidgetTester tester) async {
467 468 469 470 471
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniStartFloat));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniLeftOffsetX, _miniFloatOffsetY));
    });

472
    testWidgetsWithLeakTracking('miniCenterFloat', (WidgetTester tester) async {
473 474 475 476 477
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniCenterFloat));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _miniFloatOffsetY));
    });

478
    testWidgetsWithLeakTracking('miniEndFloat', (WidgetTester tester) async {
479 480 481 482 483
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniEndFloat));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniRightOffsetX, _miniFloatOffsetY));
    });

484
    testWidgetsWithLeakTracking('miniStartDocked', (WidgetTester tester) async {
485 486 487 488 489
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniStartDocked));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniLeftOffsetX, _dockedOffsetY));
    });

490
    testWidgetsWithLeakTracking('miniEndDocked', (WidgetTester tester) async {
491 492 493 494 495 496 497
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniEndDocked));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniRightOffsetX, _dockedOffsetY));
    });

    // Test a few RTL cases.

498
    testWidgetsWithLeakTracking('endTop, RTL', (WidgetTester tester) async {
499 500 501 502 503
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.endTop, textDirection: TextDirection.rtl));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _topOffsetY));
    });

504
    testWidgetsWithLeakTracking('miniStartFloat, RTL', (WidgetTester tester) async {
505 506 507 508 509 510 511
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.miniStartFloat, textDirection: TextDirection.rtl));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_miniRightOffsetX, _miniFloatOffsetY));
    });
  });

  group('Custom Floating Action Button Locations', () {
512
    testWidgetsWithLeakTracking('Almost end float', (WidgetTester tester) async {
513 514 515 516 517
      await tester.pumpWidget(_singleFabScaffold(_AlmostEndFloatFabLocation()));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX - 50, _floatOffsetY));
    });

518
    testWidgetsWithLeakTracking('Almost end float, RTL', (WidgetTester tester) async {
519 520 521 522 523
      await tester.pumpWidget(_singleFabScaffold(_AlmostEndFloatFabLocation(), textDirection: TextDirection.rtl));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX + 50, _floatOffsetY));
    });

524
    testWidgetsWithLeakTracking('Quarter end top', (WidgetTester tester) async {
525 526 527 528 529
      await tester.pumpWidget(_singleFabScaffold(_QuarterEndTopFabLocation()));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX * 0.75 + _leftOffsetX * 0.25, _topOffsetY));
    });

530
    testWidgetsWithLeakTracking('Quarter end top, RTL', (WidgetTester tester) async {
531 532 533 534 535 536 537
      await tester.pumpWidget(_singleFabScaffold(_QuarterEndTopFabLocation(), textDirection: TextDirection.rtl));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX * 0.75 + _rightOffsetX * 0.25, _topOffsetY));
    });
  });

  group('Moves involving new locations', () {
538
    testWidgetsWithLeakTracking('Moves between new locations and new locations', (WidgetTester tester) async {
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerTop));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _topOffsetY));

      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.startFloat));

      expect(tester.binding.transientCallbackCount, greaterThan(0));
      await tester.pumpAndSettle();
      expect(tester.binding.transientCallbackCount, 0);

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _floatOffsetY));

      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.startDocked));

      expect(tester.binding.transientCallbackCount, greaterThan(0));
      await tester.pumpAndSettle();
      expect(tester.binding.transientCallbackCount, 0);

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _dockedOffsetY));
    });

560
    testWidgetsWithLeakTracking('Moves between new locations and old locations', (WidgetTester tester) async {
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589
      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.endDocked));

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_rightOffsetX, _dockedOffsetY));

      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.startDocked));

      expect(tester.binding.transientCallbackCount, greaterThan(0));
      await tester.pumpAndSettle();
      expect(tester.binding.transientCallbackCount, 0);

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_leftOffsetX, _dockedOffsetY));

      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerFloat));

      expect(tester.binding.transientCallbackCount, greaterThan(0));
      await tester.pumpAndSettle();
      expect(tester.binding.transientCallbackCount, 0);

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _floatOffsetY));

      await tester.pumpWidget(_singleFabScaffold(FloatingActionButtonLocation.centerTop));

      expect(tester.binding.transientCallbackCount, greaterThan(0));
      await tester.pumpAndSettle();
      expect(tester.binding.transientCallbackCount, 0);

      expect(tester.getCenter(find.byType(FloatingActionButton)), const Offset(_centerOffsetX, _topOffsetY));
    });

590
    testWidgetsWithLeakTracking('Moves between new locations and old locations with custom animator', (WidgetTester tester) async {
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630
      final FloatingActionButtonAnimator animator = _LinearMovementFabAnimator();
      const Offset begin = Offset(_centerOffsetX, _topOffsetY);
      const Offset end = Offset(_rightOffsetX - 50, _floatOffsetY);

      final Duration animationDuration = kFloatingActionButtonSegue * 2;

      await tester.pumpWidget(_singleFabScaffold(
        FloatingActionButtonLocation.centerTop,
        animator: animator,
      ));

      expect(find.byType(FloatingActionButton), findsOneWidget);

      expect(tester.binding.transientCallbackCount, 0);

      await tester.pumpWidget(_singleFabScaffold(
        _AlmostEndFloatFabLocation(),
        animator: animator,
      ));

      expect(tester.binding.transientCallbackCount, greaterThan(0));

      await tester.pump(animationDuration * 0.25);

      expect(tester.getCenter(find.byType(FloatingActionButton)), offsetMoreOrLessEquals(begin * 0.75 + end * 0.25));

      await tester.pump(animationDuration * 0.25);

      expect(tester.getCenter(find.byType(FloatingActionButton)), offsetMoreOrLessEquals(begin * 0.5 + end * 0.5));

      await tester.pump(animationDuration * 0.25);

      expect(tester.getCenter(find.byType(FloatingActionButton)), offsetMoreOrLessEquals(begin * 0.25 + end * 0.75));

      await tester.pumpAndSettle();

      expect(tester.getCenter(find.byType(FloatingActionButton)), end);

      expect(tester.binding.transientCallbackCount, 0);
    });
631

632
    testWidgetsWithLeakTracking('Animator can be updated', (WidgetTester tester) async {
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
      FloatingActionButtonAnimator fabAnimator = FloatingActionButtonAnimator.scaling;
      FloatingActionButtonLocation fabLocation = FloatingActionButtonLocation.startFloat;

      final Duration animationDuration = kFloatingActionButtonSegue * 2;

      await tester.pumpWidget(_singleFabScaffold(
        fabLocation,
        animator: fabAnimator,
      ));

      expect(find.byType(FloatingActionButton), findsOneWidget);
      expect(tester.binding.transientCallbackCount, 0);
      expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 44.0);

      fabLocation = FloatingActionButtonLocation.endFloat;
      await tester.pumpWidget(_singleFabScaffold(
        fabLocation,
        animator: fabAnimator,
      ));

      expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, lessThan(16.0));

      await tester.pump(animationDuration * 0.25);
      expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, greaterThan(16));

      await tester.pump(animationDuration * 0.25);
      expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 756.0);
      expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, lessThan(800 - 16));

      await tester.pump(animationDuration * 0.25);
      expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, lessThan(800 - 16));

      await tester.pump(animationDuration * 0.25);
      expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, equals(800 - 16));

      fabLocation = FloatingActionButtonLocation.startFloat;
      fabAnimator = _NoScalingFabAnimator();
      await tester.pumpWidget(_singleFabScaffold(
        fabLocation,
        animator: fabAnimator,
      ));

      await tester.pump(animationDuration * 0.25);
      expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 756.0);
      expect(tester.getTopRight(find.byType(FloatingActionButton)).dx, equals(800 - 16));

      await tester.pump(animationDuration * 0.25);
      expect(tester.getCenter(find.byType(FloatingActionButton)).dx, 44.0);
      expect(tester.getTopLeft(find.byType(FloatingActionButton)).dx, lessThan(16.0));
    });
683
  });
684

685
  group('Locations account for safe interactive areas', () {
686
    Widget buildTest(
687 688 689 690 691 692 693 694 695 696
      FloatingActionButtonLocation location,
      MediaQueryData data,
      Key key, {
      bool mini = false,
      bool appBar = false,
      bool bottomNavigationBar = false,
      bool bottomSheet = false,
      bool resizeToAvoidBottomInset = true,
    }) {
      return MaterialApp(
697
        theme: ThemeData(useMaterial3: false),
698 699 700 701
        home: MediaQuery(
          data: data,
          child: Scaffold(
            resizeToAvoidBottomInset: resizeToAvoidBottomInset,
702
            bottomSheet: bottomSheet ? const SizedBox(
703
              height: 100,
704
              child: Center(child: Text('BottomSheet')),
705 706 707 708 709 710
            ) : null,
            appBar: appBar ? AppBar(title: const Text('Demo')) : null,
            bottomNavigationBar: bottomNavigationBar ? BottomNavigationBar(
              items: const <BottomNavigationBarItem>[
                BottomNavigationBarItem(
                  icon: Icon(Icons.star),
711
                  label: '0',
712 713 714
                ),
                BottomNavigationBarItem(
                  icon: Icon(Icons.star_border),
715
                  label: '1',
716 717 718 719 720 721 722 723
                ),
              ],
            ) : null,
            floatingActionButtonLocation: location,
            floatingActionButton: Builder(
              builder: (BuildContext context) {
                return FloatingActionButton(
                  onPressed: () {
724
                    ScaffoldMessenger.of(context).showSnackBar(
725 726 727 728 729
                      const SnackBar(content: Text('Snacky!')),
                    );
                  },
                  mini: mini,
                  key: key,
730
                  child: const Text('FAB'),
731
                );
732
              },
733
            ),
734 735
          ),
        ),
736 737 738 739 740 741
      );
    }

    // Test float locations, for each (6), keyboard presented or not:
    //  - Default
    //  - with resizeToAvoidBottomInset: false
742 743 744 745
    //  - with BottomNavigationBar
    //  - with BottomNavigationBar and resizeToAvoidBottomInset: false
    //  - with BottomNavigationBar & BottomSheet
    //  - with BottomNavigationBar & BottomSheet, resizeToAvoidBottomInset: false
746 747 748
    //  - with BottomSheet
    //  - with BottomSheet and resizeToAvoidBottomInset: false
    //  - with SnackBar
749
    Future<void> runFloatTests(
750
      WidgetTester tester,
751
      FloatingActionButtonLocation location, {
752 753 754 755
      required Rect defaultRect,
      required Rect bottomNavigationBarRect,
      required Rect bottomSheetRect,
      required Rect snackBarRect,
756 757 758 759 760
      bool mini = false,
    }) async  {
      const double keyboardHeight = 200.0;
      const double viewPadding = 50.0;
      final Key floatingActionButton = UniqueKey();
761
      const double bottomNavHeight = 106.0;
762
      // Default
763
      await tester.pumpWidget(buildTest(
764 765 766 767 768 769 770 771 772 773
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(bottom: viewPadding)),
        floatingActionButton,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect),
      );
      // Present keyboard and check position, should change
774
      await tester.pumpWidget(buildTest(
775 776 777 778 779 780 781 782 783 784 785 786
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect.translate(
          0.0,
787
          viewPadding - keyboardHeight,
788 789 790 791 792
        )),
      );

      // With resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default position
793
      await tester.pumpWidget(buildTest(
794 795 796 797 798 799 800 801 802 803 804 805 806 807
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect),
      );

808
      // BottomNavigationBar default
809
      await tester.pumpWidget(buildTest(
810 811 812 813 814 815 816 817 818 819 820 821 822 823
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomNavigationBarRect),
      );
      // Present keyboard and check position, FAB position changes
824
      await tester.pumpWidget(buildTest(
825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomNavigationBarRect.translate(
          0.0,
          -keyboardHeight + bottomNavHeight,
        )),
      );

      // BottomNavigationBar with resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default position
845
      await tester.pumpWidget(buildTest(
846 847 848 849
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
850
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
851 852 853 854 855 856 857 858 859 860 861 862
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomNavigationBarRect),
      );

      // BottomNavigationBar + BottomSheet default
863
      await tester.pumpWidget(buildTest(
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        bottomSheet: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect.translate(
          0.0,
          -bottomNavHeight,
        )),
      );
      // Present keyboard and check position, FAB position changes
882
      await tester.pumpWidget(buildTest(
883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        bottomSheet: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect.translate(
          0.0,
          -keyboardHeight,
        )),
      );

      // BottomNavigationBar + BottomSheet with resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default position
904
      await tester.pumpWidget(buildTest(
905 906 907 908
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
909
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        bottomSheet: true,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect.translate(
          0.0,
          -bottomNavHeight,
        )),
      );

925
      // BottomSheet default
926
      await tester.pumpWidget(buildTest(
927 928 929 930 931 932 933 934 935 936 937
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(bottom: viewPadding)),
        floatingActionButton,
        bottomSheet: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect),
      );
      // Present keyboard and check position, bottomSheet and FAB both resize
938
      await tester.pumpWidget(buildTest(
939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        bottomSheet: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect.translate(0.0, -keyboardHeight)),
      );

      // bottomSheet with resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default bottomSheet position
955
      await tester.pumpWidget(buildTest(
956 957 958
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
959
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
960 961 962 963 964 965 966 967 968 969 970 971
        ),
        floatingActionButton,
        bottomSheet: true,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect),
      );

      // SnackBar default
972
      await tester.pumpWidget(buildTest(
973 974 975 976 977 978 979 980 981 982 983 984 985
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(bottom: viewPadding)),
        floatingActionButton,
        mini: mini,
      ));
      await tester.tap(find.byKey(floatingActionButton));
      await tester.pumpAndSettle(); // Show SnackBar
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(snackBarRect),
      );

      // SnackBar when resized for presented keyboard
986
      await tester.pumpWidget(buildTest(
987 988 989
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
990
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
991 992 993 994 995 996 997 998
        ),
        floatingActionButton,
        mini: mini,
      ));
      await tester.tap(find.byKey(floatingActionButton));
      await tester.pumpAndSettle(); // Show SnackBar
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
999
        rectMoreOrLessEquals(snackBarRect.translate(0.0, -keyboardHeight + kFloatingActionButtonMargin/2)),
1000 1001 1002
      );
    }

1003
    testWidgetsWithLeakTracking('startFloat', (WidgetTester tester) async {
1004
      const Rect defaultRect = Rect.fromLTRB(16.0, 478.0, 72.0, 534.0);
1005
      // Positioned relative to BottomNavigationBar
1006
      const Rect bottomNavigationBarRect = Rect.fromLTRB(16.0, 422.0, 72.0, 478.0);
1007 1008 1009
      // Position relative to BottomSheet
      const Rect bottomSheetRect = Rect.fromLTRB(16.0, 472.0, 72.0, 528.0);
      // Positioned relative to SnackBar
1010
      const Rect snackBarRect = Rect.fromLTRB(16.0, 478.0, 72.0, 534.0);
1011
      await runFloatTests(
1012 1013
        tester,
        FloatingActionButtonLocation.startFloat,
1014 1015 1016 1017
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1018 1019 1020
      );
    });

1021
    testWidgetsWithLeakTracking('miniStartFloat', (WidgetTester tester) async {
1022
      const Rect defaultRect = Rect.fromLTRB(12.0, 490.0, 60.0, 538.0);
1023
      // Positioned relative to BottomNavigationBar
1024
      const Rect bottomNavigationBarRect = Rect.fromLTRB(12.0, 434.0, 60.0, 482.0);
1025 1026 1027
      // Positioned relative to BottomSheet
      const Rect bottomSheetRect = Rect.fromLTRB(12.0, 480.0, 60.0, 528.0);
      // Positioned relative to SnackBar
1028
      const Rect snackBarRect = Rect.fromLTRB(12.0, 490.0, 60.0, 538.0);
1029
      await runFloatTests(
1030 1031
        tester,
        FloatingActionButtonLocation.miniStartFloat,
1032 1033 1034 1035
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1036 1037 1038 1039
        mini: true,
      );
    });

1040
    testWidgetsWithLeakTracking('centerFloat', (WidgetTester tester) async {
1041
      const Rect defaultRect = Rect.fromLTRB(372.0, 478.0, 428.0, 534.0);
1042
      // Positioned relative to BottomNavigationBar
1043
      const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 422.0, 428.0, 478.0);
1044 1045 1046
      // Positioned relative to BottomSheet
      const Rect bottomSheetRect = Rect.fromLTRB(372.0, 472.0, 428.0, 528.0);
      // Positioned relative to SnackBar
1047
      const Rect snackBarRect = Rect.fromLTRB(372.0, 478.0, 428.0, 534.0);
1048
      await runFloatTests(
1049 1050
        tester,
        FloatingActionButtonLocation.centerFloat,
1051 1052 1053 1054
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1055 1056 1057
      );
    });

1058
    testWidgetsWithLeakTracking('miniCenterFloat', (WidgetTester tester) async {
1059
      const Rect defaultRect = Rect.fromLTRB(376.0, 490.0, 424.0, 538.0);
1060
      // Positioned relative to BottomNavigationBar
1061
      const Rect bottomNavigationBarRect = Rect.fromLTRB(376.0, 434.0, 424.0, 482.0);
1062 1063 1064
      // Positioned relative to BottomSheet
      const Rect bottomSheetRect = Rect.fromLTRB(376.0, 480.0, 424.0, 528.0);
      // Positioned relative to SnackBar
1065
      const Rect snackBarRect = Rect.fromLTRB(376.0, 490.0, 424.0, 538.0);
1066
      await runFloatTests(
1067 1068
        tester,
        FloatingActionButtonLocation.miniCenterFloat,
1069 1070 1071 1072
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1073 1074 1075 1076
        mini: true,
      );
    });

1077
    testWidgetsWithLeakTracking('endFloat', (WidgetTester tester) async {
1078
      const Rect defaultRect = Rect.fromLTRB(728.0, 478.0, 784.0, 534.0);
1079
      // Positioned relative to BottomNavigationBar
1080
      const Rect bottomNavigationBarRect = Rect.fromLTRB(728.0, 422.0, 784.0, 478.0);
1081 1082 1083
      // Positioned relative to BottomSheet
      const Rect bottomSheetRect = Rect.fromLTRB(728.0, 472.0, 784.0, 528.0);
      // Positioned relative to SnackBar
1084
      const Rect snackBarRect = Rect.fromLTRB(728.0, 478.0, 784.0, 534.0);
1085
      await runFloatTests(
1086 1087
        tester,
        FloatingActionButtonLocation.endFloat,
1088 1089 1090 1091
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1092 1093 1094
      );
    });

1095
    testWidgetsWithLeakTracking('miniEndFloat', (WidgetTester tester) async {
1096
      const Rect defaultRect = Rect.fromLTRB(740.0, 490.0, 788.0, 538.0);
1097
      // Positioned relative to BottomNavigationBar
1098
      const Rect bottomNavigationBarRect = Rect.fromLTRB(740.0, 434.0, 788.0, 482.0);
1099 1100 1101
      // Positioned relative to BottomSheet
      const Rect bottomSheetRect = Rect.fromLTRB(740.0, 480.0, 788.0, 528.0);
      // Positioned relative to SnackBar
1102
      const Rect snackBarRect = Rect.fromLTRB(740.0, 490.0, 788.0, 538.0);
1103
      await runFloatTests(
1104 1105
        tester,
        FloatingActionButtonLocation.miniEndFloat,
1106 1107 1108 1109
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1110 1111 1112 1113
        mini: true,
      );
    });

1114 1115 1116
    // Test docked locations, for each (6), keyboard presented or not.
    // If keyboard is presented and resizeToAvoidBottomInset: true, test whether
    // the FAB is away from the keyboard(and thus not clipped):
1117 1118 1119 1120 1121 1122 1123
    //  - Default
    //  - Default with resizeToAvoidBottomInset: false
    //  - docked with BottomNavigationBar
    //  - docked with BottomNavigationBar and resizeToAvoidBottomInset: false
    //  - docked with BottomNavigationBar & BottomSheet
    //  - docked with BottomNavigationBar & BottomSheet, resizeToAvoidBottomInset: false
    //  - with SnackBar
1124
    Future<void> runDockedTests(
1125
      WidgetTester tester,
1126
      FloatingActionButtonLocation location, {
1127 1128 1129 1130
      required Rect defaultRect,
      required Rect bottomNavigationBarRect,
      required Rect bottomSheetRect,
      required Rect snackBarRect,
1131 1132 1133 1134
      bool mini = false,
    }) async  {
      const double keyboardHeight = 200.0;
      const double viewPadding = 50.0;
1135
      const double bottomNavHeight = 106.0;
1136
      const double scaffoldHeight = 600.0;
1137 1138 1139
      final Key floatingActionButton = UniqueKey();
      final double fabHeight = mini ? 48.0 : 56.0;
      // Default
1140
      await tester.pumpWidget(buildTest(
1141 1142 1143 1144 1145 1146 1147 1148 1149 1150
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(bottom: viewPadding)),
        floatingActionButton,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect),
      );
      // Present keyboard and check position, should change
1151
      await tester.pumpWidget(buildTest(
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect.translate(
          0.0,
1164
          viewPadding - keyboardHeight - kFloatingActionButtonMargin,
1165 1166
        )),
      );
1167 1168 1169 1170 1171
      // The FAB should be away from the keyboard
      expect(
        tester.getRect(find.byKey(floatingActionButton)).bottom,
        lessThan(scaffoldHeight - keyboardHeight),
      );
1172 1173 1174

      // With resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default position
1175
      await tester.pumpWidget(buildTest(
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect),
      );

      // BottomNavigationBar default
1191
      await tester.pumpWidget(buildTest(
1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomNavigationBarRect),
      );
      // Present keyboard and check position, FAB position changes
1206
      await tester.pumpWidget(buildTest(
1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomNavigationBarRect.translate(
          0.0,
1221
          bottomNavHeight + fabHeight / 2.0 - keyboardHeight - kFloatingActionButtonMargin - fabHeight,
1222 1223
        )),
      );
1224 1225 1226 1227 1228
      // The FAB should be away from the keyboard
      expect(
        tester.getRect(find.byKey(floatingActionButton)).bottom,
        lessThan(scaffoldHeight - keyboardHeight),
      );
1229 1230 1231

      // BottomNavigationBar with resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default position
1232
      await tester.pumpWidget(buildTest(
1233 1234 1235 1236
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
1237
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomNavigationBarRect),
      );

      // BottomNavigationBar + BottomSheet default
1250
      await tester.pumpWidget(buildTest(
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        bottomSheet: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect),
      );
      // Present keyboard and check position, FAB position changes
1266
      await tester.pumpWidget(buildTest(
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        bottomSheet: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect.translate(
          0.0,
          -keyboardHeight + bottomNavHeight,
        )),
      );
1285 1286 1287 1288 1289
      // The FAB should be away from the keyboard
      expect(
        tester.getRect(find.byKey(floatingActionButton)).bottom,
        lessThan(scaffoldHeight - keyboardHeight),
      );
1290 1291 1292

      // BottomNavigationBar + BottomSheet with resizeToAvoidBottomInset: false
      // With keyboard presented, should maintain default position
1293
      await tester.pumpWidget(buildTest(
1294 1295 1296 1297
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
1298
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        bottomSheet: true,
        resizeToAvoidBottomInset: false,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(bottomSheetRect),
      );

      // SnackBar default
1312
      await tester.pumpWidget(buildTest(
1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(bottom: viewPadding)),
        floatingActionButton,
        mini: mini,
      ));
      await tester.tap(find.byKey(floatingActionButton));
      await tester.pumpAndSettle(); // Show SnackBar
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(snackBarRect),
      );

      // SnackBar with BottomNavigationBar
1326
      await tester.pumpWidget(buildTest(
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343
        location,
        const MediaQueryData(
          padding: EdgeInsets.only(bottom: viewPadding),
          viewPadding: EdgeInsets.only(bottom: viewPadding),
        ),
        floatingActionButton,
        bottomNavigationBar: true,
        mini: mini,
      ));
      await tester.tap(find.byKey(floatingActionButton));
      await tester.pumpAndSettle(); // Show SnackBar
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(snackBarRect.translate(0.0, -bottomNavHeight)),
      );

      // SnackBar when resized for presented keyboard
1344
      await tester.pumpWidget(buildTest(
1345 1346 1347
        location,
        const MediaQueryData(
          viewPadding: EdgeInsets.only(bottom: viewPadding),
1348
          viewInsets: EdgeInsets.only(bottom: keyboardHeight),
1349 1350 1351 1352 1353 1354 1355 1356 1357 1358
        ),
        floatingActionButton,
        mini: mini,
      ));
      await tester.tap(find.byKey(floatingActionButton));
      await tester.pumpAndSettle(); // Show SnackBar
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(snackBarRect.translate(0.0, -keyboardHeight)),
      );
1359 1360 1361 1362 1363
      // The FAB should be away from the keyboard
      expect(
        tester.getRect(find.byKey(floatingActionButton)).bottom,
        lessThan(scaffoldHeight - keyboardHeight),
      );
1364 1365
    }

1366
    testWidgetsWithLeakTracking('startDocked', (WidgetTester tester) async {
1367 1368
      const Rect defaultRect = Rect.fromLTRB(16.0, 494.0, 72.0, 550.0);
      // Positioned relative to BottomNavigationBar
1369
      const Rect bottomNavigationBarRect = Rect.fromLTRB(16.0, 466.0, 72.0, 522.0);
1370
      // Positioned relative to BottomNavigationBar & BottomSheet
1371
      const Rect bottomSheetRect = Rect.fromLTRB(16.0, 366.0, 72.0, 422.0);
1372 1373
      // Positioned relative to SnackBar
      const Rect snackBarRect = Rect.fromLTRB(16.0, 486.0, 72.0, 542.0);
1374
      await runDockedTests(
1375 1376
        tester,
        FloatingActionButtonLocation.startDocked,
1377 1378 1379 1380
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1381 1382 1383
      );
    });

1384
    testWidgetsWithLeakTracking('miniStartDocked', (WidgetTester tester) async {
1385 1386
      const Rect defaultRect = Rect.fromLTRB(12.0, 502.0, 60.0, 550.0);
      // Positioned relative to BottomNavigationBar
1387
      const Rect bottomNavigationBarRect = Rect.fromLTRB(12.0, 470.0, 60.0, 518.0);
1388
      // Positioned relative to BottomNavigationBar & BottomSheet
1389
      const Rect bottomSheetRect = Rect.fromLTRB(12.0, 370.0, 60.0, 418.0);
1390 1391
      // Positioned relative to SnackBar
      const Rect snackBarRect = Rect.fromLTRB(12.0, 494.0, 60.0, 542.0);
1392
      await runDockedTests(
1393 1394
        tester,
        FloatingActionButtonLocation.miniStartDocked,
1395 1396 1397 1398
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1399 1400 1401 1402
        mini: true,
      );
    });

1403
    testWidgetsWithLeakTracking('centerDocked', (WidgetTester tester) async {
1404 1405
      const Rect defaultRect = Rect.fromLTRB(372.0, 494.0, 428.0, 550.0);
      // Positioned relative to BottomNavigationBar
1406
      const Rect bottomNavigationBarRect = Rect.fromLTRB(372.0, 466.0, 428.0, 522.0);
1407
      // Positioned relative to BottomNavigationBar & BottomSheet
1408
      const Rect bottomSheetRect = Rect.fromLTRB(372.0, 366.0, 428.0, 422.0);
1409 1410
      // Positioned relative to SnackBar
      const Rect snackBarRect = Rect.fromLTRB(372.0, 486.0, 428.0, 542.0);
1411
      await runDockedTests(
1412 1413
        tester,
        FloatingActionButtonLocation.centerDocked,
1414 1415 1416 1417
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1418 1419 1420
      );
    });

1421
    testWidgetsWithLeakTracking('miniCenterDocked', (WidgetTester tester) async {
1422 1423
      const Rect defaultRect = Rect.fromLTRB(376.0, 502.0, 424.0, 550.0);
      // Positioned relative to BottomNavigationBar
1424
      const Rect bottomNavigationBarRect = Rect.fromLTRB(376.0, 470.0, 424.0, 518.0);
1425
      // Positioned relative to BottomNavigationBar & BottomSheet
1426
      const Rect bottomSheetRect = Rect.fromLTRB(376.0, 370.0, 424.0, 418.0);
1427 1428
      // Positioned relative to SnackBar
      const Rect snackBarRect = Rect.fromLTRB(376.0, 494.0, 424.0, 542.0);
1429
      await runDockedTests(
1430 1431
        tester,
        FloatingActionButtonLocation.miniCenterDocked,
1432 1433 1434 1435
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1436 1437 1438 1439
        mini: true,
      );
    });

1440
    testWidgetsWithLeakTracking('endDocked', (WidgetTester tester) async {
1441 1442
      const Rect defaultRect = Rect.fromLTRB(728.0, 494.0, 784.0, 550.0);
      // Positioned relative to BottomNavigationBar
1443
      const Rect bottomNavigationBarRect = Rect.fromLTRB(728.0, 466.0, 784.0, 522.0);
1444
      // Positioned relative to BottomNavigationBar & BottomSheet
1445
      const Rect bottomSheetRect = Rect.fromLTRB(728.0, 366.0, 784.0, 422.0);
1446 1447
      // Positioned relative to SnackBar
      const Rect snackBarRect = Rect.fromLTRB(728.0, 486.0, 784.0, 542.0);
1448
      await runDockedTests(
1449 1450
        tester,
        FloatingActionButtonLocation.endDocked,
1451 1452 1453 1454
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1455 1456 1457
      );
    });

1458
    testWidgetsWithLeakTracking('miniEndDocked', (WidgetTester tester) async {
1459 1460
      const Rect defaultRect = Rect.fromLTRB(740.0, 502.0, 788.0, 550.0);
      // Positioned relative to BottomNavigationBar
1461
      const Rect bottomNavigationBarRect = Rect.fromLTRB(740.0, 470.0, 788.0, 518.0);
1462
      // Positioned relative to BottomNavigationBar & BottomSheet
1463
      const Rect bottomSheetRect = Rect.fromLTRB(740.0, 370.0, 788.0, 418.0);
1464 1465
      // Positioned relative to SnackBar
      const Rect snackBarRect = Rect.fromLTRB(740.0, 494.0, 788.0, 542.0);
1466
      await runDockedTests(
1467 1468
        tester,
        FloatingActionButtonLocation.miniEndDocked,
1469 1470 1471 1472
        defaultRect: defaultRect,
        bottomNavigationBarRect: bottomNavigationBarRect,
        bottomSheetRect: bottomSheetRect,
        snackBarRect: snackBarRect,
1473 1474 1475 1476 1477 1478 1479
        mini: true,
      );
    });

    // Test top locations, for each (6):
    //  - Default
    //  - with an AppBar
1480
    Future<void> runTopTests(
1481
      WidgetTester tester,
1482
      FloatingActionButtonLocation location, {
1483 1484
      required Rect defaultRect,
      required Rect appBarRect,
1485 1486 1487 1488 1489
      bool mini = false,
    }) async  {
      const double viewPadding = 50.0;
      final Key floatingActionButton = UniqueKey();
      // Default
1490
      await tester.pumpWidget(buildTest(
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(top: viewPadding)),
        floatingActionButton,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(defaultRect),
      );

      // AppBar default
1502
      await tester.pumpWidget(buildTest(
1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
        location,
        const MediaQueryData(viewPadding: EdgeInsets.only(top: viewPadding)),
        floatingActionButton,
        appBar: true,
        mini: mini,
      ));
      expect(
        tester.getRect(find.byKey(floatingActionButton)),
        rectMoreOrLessEquals(appBarRect),
      );
    }

1515
    testWidgetsWithLeakTracking('startTop', (WidgetTester tester) async {
1516 1517 1518
      const Rect defaultRect = Rect.fromLTRB(16.0, 50.0, 72.0, 106.0);
      // Positioned relative to AppBar
      const Rect appBarRect = Rect.fromLTRB(16.0, 28.0, 72.0, 84.0);
1519
      await runTopTests(
1520 1521
        tester,
        FloatingActionButtonLocation.startTop,
1522 1523
        defaultRect: defaultRect,
        appBarRect: appBarRect,
1524 1525 1526
      );
    });

1527
    testWidgetsWithLeakTracking('miniStartTop', (WidgetTester tester) async {
1528 1529 1530
      const Rect defaultRect = Rect.fromLTRB(12.0, 50.0, 60.0, 98.0);
      // Positioned relative to AppBar
      const Rect appBarRect = Rect.fromLTRB(12.0, 32.0, 60.0, 80.0);
1531
      await runTopTests(
1532 1533
        tester,
        FloatingActionButtonLocation.miniStartTop,
1534 1535
        defaultRect: defaultRect,
        appBarRect: appBarRect,
1536 1537 1538 1539
        mini: true,
      );
    });

1540
    testWidgetsWithLeakTracking('centerTop', (WidgetTester tester) async {
1541 1542 1543
      const Rect defaultRect = Rect.fromLTRB(372.0, 50.0, 428.0, 106.0);
      // Positioned relative to AppBar
      const Rect appBarRect = Rect.fromLTRB(372.0, 28.0, 428.0, 84.0);
1544
      await runTopTests(
1545 1546
        tester,
        FloatingActionButtonLocation.centerTop,
1547 1548
        defaultRect: defaultRect,
        appBarRect: appBarRect,
1549 1550 1551
      );
    });

1552
    testWidgetsWithLeakTracking('miniCenterTop', (WidgetTester tester) async {
1553 1554 1555
      const Rect defaultRect = Rect.fromLTRB(376.0, 50.0, 424.0, 98.0);
      // Positioned relative to AppBar
      const Rect appBarRect = Rect.fromLTRB(376.0, 32.0, 424.0, 80.0);
1556
      await runTopTests(
1557 1558
        tester,
        FloatingActionButtonLocation.miniCenterTop,
1559 1560
        defaultRect: defaultRect,
        appBarRect: appBarRect,
1561 1562 1563 1564
        mini: true,
      );
    });

1565
    testWidgetsWithLeakTracking('endTop', (WidgetTester tester) async {
1566 1567 1568
      const Rect defaultRect = Rect.fromLTRB(728.0, 50.0, 784.0, 106.0);
      // Positioned relative to AppBar
      const Rect appBarRect = Rect.fromLTRB(728.0, 28.0, 784.0, 84.0);
1569
      await runTopTests(
1570 1571
        tester,
        FloatingActionButtonLocation.endTop,
1572 1573
        defaultRect: defaultRect,
        appBarRect: appBarRect,
1574 1575 1576
      );
    });

1577
    testWidgetsWithLeakTracking('miniEndTop', (WidgetTester tester) async {
1578 1579 1580
      const Rect defaultRect = Rect.fromLTRB(740.0, 50.0, 788.0, 98.0);
      // Positioned relative to AppBar
      const Rect appBarRect = Rect.fromLTRB(740.0, 32.0, 788.0, 80.0);
1581
      await runTopTests(
1582 1583
        tester,
        FloatingActionButtonLocation.miniEndTop,
1584 1585
        defaultRect: defaultRect,
        appBarRect: appBarRect,
1586 1587 1588 1589 1590
        mini: true,
      );
    });
  });
}
1591 1592

class _GeometryListener extends StatefulWidget {
1593 1594
  const _GeometryListener();

1595
  @override
1596
  State createState() => _GeometryListenerState();
1597 1598 1599 1600 1601
}

class _GeometryListenerState extends State<_GeometryListener> {
  @override
  Widget build(BuildContext context) {
1602
    return CustomPaint(
1603
      painter: cache,
1604 1605 1606 1607
    );
  }

  int numNotifications = 0;
1608 1609
  ValueListenable<ScaffoldGeometry>? geometryListenable;
  late _GeometryCachePainter cache;
1610 1611 1612 1613 1614

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    final ValueListenable<ScaffoldGeometry> newListenable = Scaffold.geometryOf(context);
1615
    if (geometryListenable == newListenable) {
1616
      return;
1617
    }
1618

1619
    if (geometryListenable != null) {
1620
      geometryListenable!.removeListener(onGeometryChanged);
1621
    }
1622

1623
    geometryListenable = newListenable;
1624 1625
    geometryListenable!.addListener(onGeometryChanged);
    cache = _GeometryCachePainter(geometryListenable!);
1626 1627 1628 1629 1630 1631 1632
  }

  void onGeometryChanged() {
    numNotifications += 1;
  }
}

1633 1634 1635 1636 1637 1638 1639 1640 1641
const double _leftOffsetX = 44.0;
const double _centerOffsetX = 400.0;
const double _rightOffsetX = 756.0;
const double _miniLeftOffsetX = _leftOffsetX - kMiniButtonOffsetAdjustment;
const double _miniRightOffsetX = _rightOffsetX + kMiniButtonOffsetAdjustment;

const double _topOffsetY = 56.0;
const double _floatOffsetY = 500.0;
const double _dockedOffsetY = 544.0;
1642
const double _containedOffsetY = 544.0 + 56.0 / 2;
1643 1644
const double _miniFloatOffsetY = _floatOffsetY + kMiniButtonOffsetAdjustment;

1645 1646 1647 1648 1649 1650
Widget _singleFabScaffold(FloatingActionButtonLocation location, {
  bool useMaterial3 = false,
  FloatingActionButtonAnimator? animator,
  bool mini = false,
  TextDirection textDirection = TextDirection.ltr,
}) {
1651
  return MaterialApp(
1652
    theme: ThemeData(useMaterial3: useMaterial3),
1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
    home: Directionality(
      textDirection: textDirection,
      child: Scaffold(
        appBar: AppBar(
          title: const Text('FloatingActionButtonLocation Test.'),
        ),
        bottomNavigationBar: BottomNavigationBar(
          items: const <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
1663
              label: 'Home',
1664 1665 1666
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.school),
1667
              label: 'School',
1668 1669 1670 1671 1672 1673
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {},
          mini: mini,
1674
          child: const Icon(Icons.beach_access),
1675 1676 1677 1678 1679 1680 1681
        ),
        floatingActionButtonLocation: location,
        floatingActionButtonAnimator: animator,
      ),
    ),
  );
}
1682 1683 1684 1685 1686 1687 1688 1689 1690

// The Scaffold.geometryOf() value is only available at paint time.
// To fetch it for the tests we implement this CustomPainter that just
// caches the ScaffoldGeometry value in its paint method.
class _GeometryCachePainter extends CustomPainter {
  _GeometryCachePainter(this.geometryListenable) : super(repaint: geometryListenable);

  final ValueListenable<ScaffoldGeometry> geometryListenable;

1691
  late ScaffoldGeometry value;
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702
  @override
  void paint(Canvas canvas, Size size) {
    value = geometryListenable.value;
  }

  @override
  bool shouldRepaint(_GeometryCachePainter oldDelegate) {
    return true;
  }
}

1703
Widget _buildFrame({
1704
  FloatingActionButton? fab = const FloatingActionButton(
1705
    onPressed: null,
1706
    child: Text('1'),
1707
  ),
1708 1709
  FloatingActionButtonLocation? location,
  _GeometryListener? listener,
1710 1711
  TextDirection textDirection = TextDirection.ltr,
  EdgeInsets viewInsets = const EdgeInsets.only(bottom: 200.0),
1712
  Widget? bab,
1713
}) {
1714 1715 1716 1717 1718 1719 1720
  return Localizations(
    locale: const Locale('en', 'us'),
    delegates: const <LocalizationsDelegate<dynamic>>[
      DefaultWidgetsLocalizations.delegate,
      DefaultMaterialLocalizations.delegate,
    ],
    child: Directionality(
1721 1722 1723 1724 1725 1726 1727 1728 1729 1730
      textDirection: textDirection,
      child: MediaQuery(
        data: MediaQueryData(viewInsets: viewInsets),
        child: Scaffold(
          appBar: AppBar(title: const Text('FabLocation Test')),
          floatingActionButtonLocation: location,
          floatingActionButton: fab,
          bottomNavigationBar: bab,
          body: listener,
        ),
1731 1732
      ),
    ),
1733
  );
1734
}
1735

1736 1737
class _StartTopFloatingActionButtonLocation extends FloatingActionButtonLocation {
  const _StartTopFloatingActionButtonLocation();
1738 1739 1740

  @override
  Offset getOffset(ScaffoldPrelayoutGeometry scaffoldGeometry) {
1741 1742 1743 1744 1745 1746 1747 1748 1749
    double fabX;
    switch (scaffoldGeometry.textDirection) {
      case TextDirection.rtl:
        final double startPadding = kFloatingActionButtonMargin + scaffoldGeometry.minInsets.right;
        fabX = scaffoldGeometry.scaffoldSize.width - scaffoldGeometry.floatingActionButtonSize.width - startPadding;
      case TextDirection.ltr:
        final double startPadding = kFloatingActionButtonMargin + scaffoldGeometry.minInsets.left;
        fabX = startPadding;
    }
1750
    final double fabY = scaffoldGeometry.contentTop - (scaffoldGeometry.floatingActionButtonSize.height / 2.0);
1751
    return Offset(fabX, fabY);
1752
  }
1753
}
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776

class _AlmostEndFloatFabLocation extends StandardFabLocation
    with FabEndOffsetX, FabFloatOffsetY {
  @override
  double getOffsetX (ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) {
    final double directionalAdjustment =
        scaffoldGeometry.textDirection == TextDirection.ltr ? -50.0 : 50.0;
    return super.getOffsetX(scaffoldGeometry, adjustment) + directionalAdjustment;
  }
}

class _QuarterEndTopFabLocation extends StandardFabLocation
    with FabEndOffsetX, FabTopOffsetY {
  @override
  double getOffsetX (ScaffoldPrelayoutGeometry scaffoldGeometry, double adjustment) {
    return super.getOffsetX(scaffoldGeometry, adjustment) * 0.75
        + (FloatingActionButtonLocation.startFloat as StandardFabLocation)
            .getOffsetX(scaffoldGeometry, adjustment) * 0.25;
  }
}

class _LinearMovementFabAnimator extends FloatingActionButtonAnimator {
  @override
1777 1778
  Offset getOffset({required Offset begin, required Offset end, required double progress}) {
    return Offset.lerp(begin, end, progress)!;
1779 1780 1781
  }

  @override
1782
  Animation<double> getScaleAnimation({required Animation<double> parent}) {
1783 1784 1785 1786
    return const AlwaysStoppedAnimation<double>(1.0);
  }

  @override
1787
  Animation<double> getRotationAnimation({required Animation<double> parent}) {
1788 1789 1790
    return const AlwaysStoppedAnimation<double>(1.0);
  }
}
1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807

class _NoScalingFabAnimator extends FloatingActionButtonAnimator {
  @override
  Offset getOffset({required Offset begin, required Offset end, required double progress}) {
    return progress < 0.5 ? begin : end;
  }

  @override
  Animation<double> getScaleAnimation({required Animation<double> parent}) {
    return const AlwaysStoppedAnimation<double>(1.0);
  }

  @override
  Animation<double> getRotationAnimation({required Animation<double> parent}) {
    return const AlwaysStoppedAnimation<double>(1.0);
  }
}