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

import 'dart:math' as math;

import 'package:flutter/widgets.dart';
8
import 'package:flutter_test/flutter_test.dart';
9
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
10 11 12

final Matcher doesNotOverscroll = isNot(paints..circle());

13
Future<void> slowDrag(WidgetTester tester, Offset start, Offset offset) async {
14
  final TestGesture gesture = await tester.startGesture(start);
15 16 17 18 19 20 21 22
  for (int index = 0; index < 10; index += 1) {
    await gesture.moveBy(offset);
    await tester.pump(const Duration(milliseconds: 20));
  }
  await gesture.up();
}

void main() {
23
  testWidgetsWithLeakTracking('Overscroll indicator color', (WidgetTester tester) async {
24
    await tester.pumpWidget(
25
      const Directionality(
26
        textDirection: TextDirection.ltr,
27
        child: CustomScrollView(
28
          slivers: <Widget>[
29
            SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
30 31
          ],
        ),
32 33
      ),
    );
34
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
35 36 37 38

    expect(painter, doesNotOverscroll);

    // the scroll gesture from tester.scroll happens in zero time, so nothing should appear:
39
    await tester.drag(find.byType(Scrollable), const Offset(0.0, 100.0));
40 41 42 43 44 45
    expect(painter, doesNotOverscroll);
    await tester.pump(); // allow the ticker to register itself
    expect(painter, doesNotOverscroll);
    await tester.pump(const Duration(milliseconds: 100)); // animate
    expect(painter, doesNotOverscroll);

46
    final TestGesture gesture = await tester.startGesture(const Offset(200.0, 200.0));
47 48 49 50 51
    await tester.pump(const Duration(milliseconds: 100)); // animate
    expect(painter, doesNotOverscroll);
    await gesture.up();
    expect(painter, doesNotOverscroll);

52
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
53 54
    expect(painter, paints..circle(color: const Color(0x0DFFFFFF)));

55
    await tester.pumpAndSettle(const Duration(seconds: 1));
56 57
    expect(painter, doesNotOverscroll);
  });
58

59
  testWidgetsWithLeakTracking('Nested scrollable', (WidgetTester tester) async {
60
    await tester.pumpWidget(
61
      Directionality(
62
        textDirection: TextDirection.ltr,
63
        child: GlowingOverscrollIndicator(
64 65 66
          axisDirection: AxisDirection.down,
          color: const Color(0x0DFFFFFF),
          notificationPredicate: (ScrollNotification notification) => notification.depth == 1,
67
          child: const SingleChildScrollView(
68
            scrollDirection: Axis.horizontal,
69
            child: SizedBox(
70
                width: 600.0,
71
                child: CustomScrollView(
72
                  slivers: <Widget>[
73
                    SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
74 75 76 77 78 79 80
                  ],
                ),
              ),
            ),
          ),
        ),
      );
81

82 83
    final RenderObject outerPainter = tester.renderObject(find.byType(CustomPaint).first);
    final RenderObject innerPainter = tester.renderObject(find.byType(CustomPaint).last);
84

85 86 87 88
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
    expect(outerPainter, paints..circle());
    expect(innerPainter, paints..circle());
  });
89

90
  testWidgetsWithLeakTracking('Overscroll indicator changes side when you drag on the other side', (WidgetTester tester) async {
91
    await tester.pumpWidget(
92
      const Directionality(
93
        textDirection: TextDirection.ltr,
94
        child: CustomScrollView(
95
          slivers: <Widget>[
96
            SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
97 98
          ],
        ),
99 100
      ),
    );
101
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
102

103
    await slowDrag(tester, const Offset(400.0, 200.0), const Offset(0.0, 10.0));
104
    expect(painter, paints..circle(x: 400.0));
105
    await slowDrag(tester, const Offset(100.0, 200.0), const Offset(0.0, 10.0));
106
    expect(painter, paints..something((Symbol method, List<dynamic> arguments) {
107
      if (method != #drawCircle) {
108
        return false;
109
      }
110
      final Offset center = arguments[0] as Offset;
111
      if (center.dx < 400.0) {
112
        return true;
113
      }
114 115
      throw 'Dragging on left hand side did not overscroll on left hand side.';
    }));
116
    await slowDrag(tester, const Offset(700.0, 200.0), const Offset(0.0, 10.0));
117
    expect(painter, paints..something((Symbol method, List<dynamic> arguments) {
118
      if (method != #drawCircle) {
119
        return false;
120
      }
121
      final Offset center = arguments[0] as Offset;
122
      if (center.dx > 400.0) {
123
        return true;
124
      }
125 126 127
      throw 'Dragging on right hand side did not overscroll on right hand side.';
    }));

128
    await tester.pumpAndSettle(const Duration(seconds: 1));
129 130 131
    expect(painter, doesNotOverscroll);
  });

132
  testWidgetsWithLeakTracking('Overscroll indicator changes side when you shift sides', (WidgetTester tester) async {
133
    await tester.pumpWidget(
134
      const Directionality(
135
        textDirection: TextDirection.ltr,
136
        child: CustomScrollView(
137
          slivers: <Widget>[
138
            SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
139 140
          ],
        ),
141 142
      ),
    );
143
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
144
    final TestGesture gesture = await tester.startGesture(const Offset(300.0, 200.0));
145 146 147 148 149 150 151
    await gesture.moveBy(const Offset(0.0, 10.0));
    await tester.pump(const Duration(milliseconds: 20));
    double oldX = 0.0;
    for (int index = 0; index < 10; index += 1) {
      await gesture.moveBy(const Offset(50.0, 50.0));
      await tester.pump(const Duration(milliseconds: 20));
      expect(painter, paints..something((Symbol method, List<dynamic> arguments) {
152
        if (method != #drawCircle) {
153
          return false;
154
        }
155
        final Offset center = arguments[0] as Offset;
156
        if (center.dx <= oldX) {
157
          throw 'Sliding to the right did not make the center of the radius slide to the right.';
158
        }
159
        oldX = center.dx;
160 161 162 163 164
        return true;
      }));
    }
    await gesture.up();

165
    await tester.pumpAndSettle(const Duration(seconds: 1));
166 167 168
    expect(painter, doesNotOverscroll);
  });

169
  group("Flipping direction of scrollable doesn't change overscroll behavior", () {
170
    testWidgetsWithLeakTracking('down', (WidgetTester tester) async {
171
      await tester.pumpWidget(
172
        const Directionality(
173
          textDirection: TextDirection.ltr,
174
          child: CustomScrollView(
175 176
            physics: AlwaysScrollableScrollPhysics(),
            slivers: <Widget>[
177
              SliverToBoxAdapter(child: SizedBox(height: 20.0)),
178 179
            ],
          ),
180 181
        ),
      );
182
      final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
183
      await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
184 185
      expect(painter, paints..save()..circle()..restore()..save()..scale(y: -1.0)..restore()..restore());

186
      await tester.pumpAndSettle(const Duration(seconds: 1));
187 188 189
      expect(painter, doesNotOverscroll);
    });

190
    testWidgetsWithLeakTracking('up', (WidgetTester tester) async {
191
      await tester.pumpWidget(
192
        const Directionality(
193
          textDirection: TextDirection.ltr,
194
          child: CustomScrollView(
195
            reverse: true,
196 197
            physics: AlwaysScrollableScrollPhysics(),
            slivers: <Widget>[
198
              SliverToBoxAdapter(child: SizedBox(height: 20.0)),
199 200
            ],
          ),
201 202
        ),
      );
203
      final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
204
      await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
205 206
      expect(painter, paints..save()..scale(y: -1.0)..restore()..save()..circle()..restore()..restore());

207
      await tester.pumpAndSettle(const Duration(seconds: 1));
208 209 210 211
      expect(painter, doesNotOverscroll);
    });
  });

212
  testWidgetsWithLeakTracking('Overscroll in both directions', (WidgetTester tester) async {
213
    await tester.pumpWidget(
214
      const Directionality(
215
        textDirection: TextDirection.ltr,
216
        child: CustomScrollView(
217 218
          physics: AlwaysScrollableScrollPhysics(),
          slivers: <Widget>[
219
            SliverToBoxAdapter(child: SizedBox(height: 20.0)),
220 221
          ],
        ),
222 223
      ),
    );
224
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
225
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
226 227
    expect(painter, paints..circle());
    expect(painter, isNot(paints..circle()..circle()));
228
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -5.0));
229 230
    expect(painter, paints..circle()..circle());

231
    await tester.pumpAndSettle(const Duration(seconds: 1));
232 233 234
    expect(painter, doesNotOverscroll);
  });

235
  testWidgetsWithLeakTracking('Overscroll ignored from alternate axis', (WidgetTester tester) async {
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
    await tester.pumpWidget(
      const Directionality(
        textDirection: TextDirection.ltr,
        child: ScrollConfiguration(
          behavior: TestScrollBehaviorNoGlow(),
          child: GlowingOverscrollIndicator(
            axisDirection: AxisDirection.right,
            color: Color(0xFF0000FF),
            child: CustomScrollView(
              physics: AlwaysScrollableScrollPhysics(),
              slivers: <Widget>[
                SliverToBoxAdapter(child: SizedBox(height: 20.0)),
              ],
            ),
          ),
        ),
      ),
    );
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
    expect(painter, doesNotOverscroll);
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -5.0));
    expect(painter, doesNotOverscroll);

    await tester.pumpAndSettle(const Duration(seconds: 1));
    expect(painter, doesNotOverscroll);
  });

264
  testWidgetsWithLeakTracking('Overscroll horizontally', (WidgetTester tester) async {
265
    await tester.pumpWidget(
266
      const Directionality(
267
        textDirection: TextDirection.ltr,
268
        child: CustomScrollView(
269
          scrollDirection: Axis.horizontal,
270 271
          physics: AlwaysScrollableScrollPhysics(),
          slivers: <Widget>[
272
            SliverToBoxAdapter(child: SizedBox(height: 20.0)),
273 274
          ],
        ),
275
      ),
276
    );
277
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
278
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0));
279
    expect(painter, paints..rotate(angle: math.pi / 2.0)..circle()..saveRestore());
280
    expect(painter, isNot(paints..circle()..circle()));
281
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(-5.0, 0.0));
282 283 284 285 286 287 288 289
    expect(
      painter,
      paints
        ..rotate(angle: math.pi / 2.0)
        ..circle()
        ..rotate(angle: math.pi / 2.0)
        ..circle(),
    );
290

291
    await tester.pumpAndSettle(const Duration(seconds: 1));
292 293 294
    expect(painter, doesNotOverscroll);
  });

295
  testWidgetsWithLeakTracking('Nested overscrolls do not throw exceptions', (WidgetTester tester) async {
296
    await tester.pumpWidget(Directionality(
297
      textDirection: TextDirection.ltr,
298
      child: PageView(
299
        children: <Widget>[
300
          ListView(
301
            children: <Widget>[
302
              Container(
303 304
                width: 2000.0,
                height: 2000.0,
305
                color: const Color(0xFF00FF00),
306 307 308 309 310
              ),
            ],
          ),
        ],
      ),
311
    ));
312

313
    await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 2000.0));
314
    await tester.pumpAndSettle();
315 316
  });

317
  testWidgetsWithLeakTracking('Changing settings', (WidgetTester tester) async {
318 319
    RenderObject painter;

320
    await tester.pumpWidget(
321
      const Directionality(
322
        textDirection: TextDirection.ltr,
323 324
        child: ScrollConfiguration(
          behavior: TestScrollBehavior1(),
325
          child: CustomScrollView(
326
            scrollDirection: Axis.horizontal,
327
            physics: AlwaysScrollableScrollPhysics(),
328
            reverse: true,
329
            slivers: <Widget>[
330
              SliverToBoxAdapter(child: SizedBox(height: 20.0)),
331 332
            ],
          ),
333
        ),
334
      ),
335
    );
336
    painter = tester.renderObject(find.byType(CustomPaint));
337
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0));
338
    expect(painter, paints..rotate(angle: math.pi / 2.0)..circle(color: const Color(0x0A00FF00)));
339 340
    expect(painter, isNot(paints..circle()..circle()));

341
    await tester.pumpAndSettle(const Duration(seconds: 1));
342
    await tester.pumpWidget(
343
      const Directionality(
344
        textDirection: TextDirection.ltr,
345 346
        child: ScrollConfiguration(
          behavior: TestScrollBehavior2(),
347
          child: CustomScrollView(
348
            scrollDirection: Axis.horizontal,
349 350
            physics: AlwaysScrollableScrollPhysics(),
            slivers: <Widget>[
351
              SliverToBoxAdapter(child: SizedBox(height: 20.0)),
352 353
            ],
          ),
354
        ),
355
      ),
356
    );
357
    painter = tester.renderObject(find.byType(CustomPaint));
358
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(5.0, 0.0));
359
    expect(painter, paints..rotate(angle: math.pi / 2.0)..circle(color: const Color(0x0A0000FF))..saveRestore());
360 361
    expect(painter, isNot(paints..circle()..circle()));
  });
362

363
  testWidgetsWithLeakTracking('CustomScrollView overscroll indicator works if there is sliver before center', (WidgetTester tester) async {
364 365 366 367 368
    final Key centerKey = UniqueKey();
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: ScrollConfiguration(
369
          behavior: const TestScrollBehavior2(),
370 371 372 373 374 375
          child: CustomScrollView(
            center: centerKey,
            physics: const AlwaysScrollableScrollPhysics(),
            slivers: <Widget>[
              SliverList(
                delegate: SliverChildBuilderDelegate(
376
                  (BuildContext context, int index) => Text('First sliver $index'),
377 378 379 380 381 382
                  childCount: 2,
                ),
              ),
              SliverList(
                key: centerKey,
                delegate: SliverChildBuilderDelegate(
383
                  (BuildContext context, int index) => Text('Second sliver $index'),
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401
                  childCount: 5,
                ),
              ),
            ],
          ),
        ),
      ),
    );

    expect(find.text('First sliver 1'), findsNothing);

    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 300.0));
    expect(find.text('First sliver 1'), findsOneWidget);
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
    // The scroll offset and paint extend should cancel out each other.
    expect(painter, paints..save()..translate(y: 0.0)..scale()..circle());
  });

402
  testWidgetsWithLeakTracking('CustomScrollView overscroll indicator works well with [CustomScrollView.center] and [OverscrollIndicatorNotification.paintOffset]', (WidgetTester tester) async {
403 404 405 406 407
    final Key centerKey = UniqueKey();
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: ScrollConfiguration(
408
          behavior: const TestScrollBehavior2(),
409 410 411 412 413 414 415 416 417 418 419 420 421
          child: NotificationListener<OverscrollIndicatorNotification>(
            onNotification: (OverscrollIndicatorNotification notification) {
              if (notification.leading) {
                notification.paintOffset = 50.0;
              }
              return false;
            },
            child: CustomScrollView(
              center: centerKey,
              physics: const AlwaysScrollableScrollPhysics(),
              slivers: <Widget>[
                SliverList(
                  delegate: SliverChildBuilderDelegate(
422
                    (BuildContext context, int index) => Text('First sliver $index'),
423 424 425 426 427 428
                    childCount: 2,
                  ),
                ),
                SliverList(
                  key: centerKey,
                  delegate: SliverChildBuilderDelegate(
429
                    (BuildContext context, int index) => Text('Second sliver $index'),
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
                    childCount: 5,
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );

    expect(find.text('First sliver 1'), findsNothing);

    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0)); // offset will be magnified ten times
    expect(find.text('First sliver 1'), findsOneWidget);
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
    // The OverscrollIndicator should respect the [OverscrollIndicatorNotification.paintOffset] setting.
    expect(painter, paints..save()..translate(y: 50.0)..scale()..circle());
  });

449
  testWidgetsWithLeakTracking('The OverscrollIndicator should not overflow the scrollable view edge', (WidgetTester tester) async {
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
    // Regressing test for https://github.com/flutter/flutter/issues/64149
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: NotificationListener<OverscrollIndicatorNotification>(
          onNotification: (OverscrollIndicatorNotification notification) {
            notification.paintOffset = 50.0; // both the leading and trailing indicator have a 50.0 pixels offset.
            return false;
          },
          child: const CustomScrollView(
            slivers: <Widget>[
              SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
            ],
          ),
        ),
      ),
    );
    final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
    expect(painter, paints..save()..translate(y: 50.0)..scale()..circle());
    // Reverse scroll (30 pixels), and the offset < notification.paintOffset.
    await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, -30.0));
    await tester.pump();
    // The OverscrollIndicator should move with the CustomScrollView.
    expect(painter, paints..save()..translate(y: 50.0 - 30.0)..scale()..circle());

    // Reverse scroll (30+20 pixels) and offset == notification.paintOffset.
    await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, -20.0));
    await tester.pump();
    expect(painter, paints..save()..translate(y: 50.0 - 50.0)..scale()..circle());

    // Reverse scroll (30+20+10 pixels) and offset > notification.paintOffset.
    await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, -10.0));
    await tester.pump();
    // The OverscrollIndicator should not overflow the CustomScrollView's edge.
    expect(painter, paints..save()..translate(y: 50.0 - 50.0)..scale()..circle());

    await tester.pumpAndSettle(); // Finish the leading indicator.

    // trigger the trailing indicator
    await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -200.0));
    expect(painter, paints..scale(y: -1.0)..save()..translate(y: 50.0)..scale()..circle());

    // Reverse scroll (30 pixels), and the offset < notification.paintOffset.
    await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, 30.0));
    await tester.pump();
    // The OverscrollIndicator should move with the CustomScrollView.
    expect(painter, paints..scale(y: -1.0)..save()..translate(y: 50.0 - 30.0)..scale()..circle());

    // Reverse scroll (30+20 pixels) and offset == notification.paintOffset.
    await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, 20.0));
    await tester.pump();
    expect(painter, paints..scale(y: -1.0)..save()..translate(y: 50.0 - 50.0)..scale()..circle());

    // Reverse scroll (30+20+10 pixels) and offset > notification.paintOffset.
    await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, 10.0));
    await tester.pump();
    // The OverscrollIndicator should not overflow the CustomScrollView's edge.
    expect(painter, paints..scale(y: -1.0)..save()..translate(y: 50.0 - 50.0)..scale()..circle());
  });

  group('[OverscrollIndicatorNotification.paintOffset] test', () {
512
    testWidgetsWithLeakTracking('Leading', (WidgetTester tester) async {
513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
      await tester.pumpWidget(
        Directionality(
          textDirection: TextDirection.ltr,
          child: NotificationListener<OverscrollIndicatorNotification>(
            onNotification: (OverscrollIndicatorNotification notification) {
              if (notification.leading) {
                notification.paintOffset = 50.0;
              }
              return false;
            },
            child: const CustomScrollView(
              slivers: <Widget>[
                SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
              ],
            ),
          ),
        ),
      );
      final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
      await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, 5.0));
533
      // The OverscrollIndicator should respect the [OverscrollIndicatorNotification.paintOffset] setting.
534 535 536 537
      expect(painter, paints..save()..translate(y: 50.0)..scale()..circle());
      // Reverse scroll direction.
      await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, -30.0));
      await tester.pump();
538
      // The OverscrollIndicator should move with the CustomScrollView.
539 540 541
      expect(painter, paints..save()..translate(y: 50.0 - 30.0)..scale()..circle());
    });

542
    testWidgetsWithLeakTracking('Trailing', (WidgetTester tester) async {
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
      await tester.pumpWidget(
        Directionality(
          textDirection: TextDirection.ltr,
          child: NotificationListener<OverscrollIndicatorNotification>(
            onNotification: (OverscrollIndicatorNotification notification) {
              if (!notification.leading) {
                notification.paintOffset = 50.0;
              }
              return false;
            },
            child: const CustomScrollView(
              slivers: <Widget>[
                SliverToBoxAdapter(child: SizedBox(height: 2000.0)),
              ],
            ),
          ),
        ),
      );
      final RenderObject painter = tester.renderObject(find.byType(CustomPaint));
      await tester.dragFrom(const Offset(200.0, 200.0), const Offset(200.0, -10000.0));
      await tester.pump();
      await slowDrag(tester, const Offset(200.0, 200.0), const Offset(0.0, -5.0));
565
      // The OverscrollIndicator should respect the [OverscrollIndicatorNotification.paintOffset] setting.
566 567 568 569
      expect(painter, paints..scale(y: -1.0)..save()..translate(y: 50.0)..scale()..circle());
      // Reverse scroll direction.
      await tester.dragFrom(const Offset(200.0, 200.0), const Offset(0.0, 30.0));
      await tester.pump();
570
      // The OverscrollIndicator should move with the CustomScrollView.
571 572 573
      expect(painter, paints..scale(y: -1.0)..save()..translate(y: 50.0 - 30.0)..scale()..circle());
    });
  });
574 575
}

Adam Barth's avatar
Adam Barth committed
576
class TestScrollBehavior1 extends ScrollBehavior {
577 578
  const TestScrollBehavior1();

579
  @override
580
  Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
581
    return GlowingOverscrollIndicator(
582
      axisDirection: details.direction,
583
      color: const Color(0xFF00FF00),
584
      child: child,
585
    );
586 587 588
  }
}

Adam Barth's avatar
Adam Barth committed
589
class TestScrollBehavior2 extends ScrollBehavior {
590 591
  const TestScrollBehavior2();

592
  @override
593
  Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
594
    return GlowingOverscrollIndicator(
595
      axisDirection: details.direction,
596
      color: const Color(0xFF0000FF),
597
      child: child,
598
    );
599 600
  }
}
601 602 603 604 605 606 607 608 609

class TestScrollBehaviorNoGlow extends ScrollBehavior {
  const TestScrollBehaviorNoGlow();

  @override
  Widget buildOverscrollIndicator(BuildContext context, Widget child, ScrollableDetails details) {
    return child;
  }
}