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

5
import 'package:flutter/gestures.dart' show DragStartBehavior;
6 7 8
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
9

Adam Barth's avatar
Adam Barth committed
10
import '../rendering/mock_canvas.dart';
11
import '../rendering/rendering_tester.dart' show TestClipPaintingContext;
12 13 14
import 'states.dart';

void main() {
15
  testWidgets('Empty GridView', (WidgetTester tester) async {
16
    await tester.pumpWidget(
17
      Directionality(
18
        textDirection: TextDirection.ltr,
19
        child: GridView.count(
20
          dragStartBehavior: DragStartBehavior.down,
21 22 23 24
          crossAxisCount: 4,
        ),
      ),
    );
25 26
  });

27
  testWidgets('GridView.count control test', (WidgetTester tester) async {
28
    final List<String> log = <String>[];
29

30
    await tester.pumpWidget(
31
      Directionality(
32
        textDirection: TextDirection.ltr,
33
        child: GridView.count(
34
          dragStartBehavior: DragStartBehavior.down,
35
          crossAxisCount: 4,
36
          children: kStates.map<Widget>((String state) {
37
            return GestureDetector(
38
              dragStartBehavior: DragStartBehavior.down,
39 40 41
              onTap: () {
                log.add(state);
              },
42
              child: Container(
43
                color: const Color(0xFF0000FF),
44
                child: Text(state),
45 46 47 48 49 50
              ),
            );
          }).toList(),
        ),
      ),
    );
51 52 53 54 55 56 57 58 59 60 61 62

    expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0)));

    for (int i = 0; i < 8; ++i) {
      await tester.tap(find.text(kStates[i]));
      expect(log, equals(<String>[kStates[i]]));
      log.clear();
    }

    expect(find.text(kStates[12]), findsNothing);
    expect(find.text('Nevada'), findsNothing);

63
    await tester.drag(find.text('Arkansas'), const Offset(0.0, -200.0));
64 65 66 67 68 69 70 71 72 73 74
    await tester.pump();

    for (int i = 0; i < 4; ++i)
      expect(find.text(kStates[i]), findsNothing);

    for (int i = 4; i < 12; ++i) {
      await tester.tap(find.text(kStates[i]));
      expect(log, equals(<String>[kStates[i]]));
      log.clear();
    }

75
    await tester.drag(find.text('Delaware'), const Offset(0.0, -4000.0));
76 77 78 79 80
    await tester.pump();

    expect(find.text('Alabama'), findsNothing);
    expect(find.text('Pennsylvania'), findsNothing);

81
    expect(tester.getCenter(find.text('Tennessee')), equals(const Offset(300.0, 100.0)));
82 83 84 85 86

    await tester.tap(find.text('Tennessee'));
    expect(log, equals(<String>['Tennessee']));
    log.clear();

87
    await tester.drag(find.text('Tennessee'), const Offset(0.0, 200.0));
88 89 90 91 92 93 94 95 96 97 98
    await tester.pump();

    await tester.tap(find.text('Tennessee'));
    expect(log, equals(<String>['Tennessee']));
    log.clear();

    await tester.tap(find.text('Pennsylvania'));
    expect(log, equals(<String>['Pennsylvania']));
    log.clear();
  });

99
  testWidgets('GridView.extent control test', (WidgetTester tester) async {
100
    final List<String> log = <String>[];
101

102
    await tester.pumpWidget(
103
      Directionality(
104
        textDirection: TextDirection.ltr,
105
        child: GridView.extent(
106
          dragStartBehavior: DragStartBehavior.down,
107
          maxCrossAxisExtent: 200.0,
108
          children: kStates.map<Widget>((String state) {
109
            return GestureDetector(
110
              dragStartBehavior: DragStartBehavior.down,
111 112 113
              onTap: () {
                log.add(state);
              },
114
              child: Container(
115
                color: const Color(0xFF0000FF),
116
                child: Text(state),
117 118 119 120 121 122
              ),
            );
          }).toList(),
        ),
      ),
    );
123 124 125 126 127 128 129 130 131 132 133

    expect(tester.getSize(find.text('Arkansas')), equals(const Size(200.0, 200.0)));

    for (int i = 0; i < 8; ++i) {
      await tester.tap(find.text(kStates[i]));
      expect(log, equals(<String>[kStates[i]]));
      log.clear();
    }

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

134
    await tester.drag(find.text('Arkansas'), const Offset(0.0, -4000.0));
135 136 137 138
    await tester.pump();

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

139
    expect(tester.getCenter(find.text('Tennessee')), equals(const Offset(300.0, 100.0)));
140 141 142 143 144 145

    await tester.tap(find.text('Tennessee'));
    expect(log, equals(<String>['Tennessee']));
    log.clear();
  });

146
  testWidgets('GridView large scroll jump', (WidgetTester tester) async {
147
    final List<int> log = <int>[];
148

149
    await tester.pumpWidget(
150
      Directionality(
151
        textDirection: TextDirection.ltr,
152
        child: GridView.extent(
153 154 155
          scrollDirection: Axis.horizontal,
          maxCrossAxisExtent: 200.0,
          childAspectRatio: 0.75,
156 157
          children: List<Widget>.generate(80, (int i) {
            return Builder(
158 159
              builder: (BuildContext context) {
                log.add(i);
160
                return Text('$i');
161
              },
162 163 164
            );
          }),
        ),
165
      ),
166
    );
167 168 169 170 171 172 173

    expect(tester.getSize(find.text('4')), equals(const Size(200.0 / 0.75, 200.0)));

    expect(log, equals(<int>[
      0, 1, 2, // col 0
      3, 4, 5, // col 1
      6, 7, 8, // col 2
174
      9, 10, 11, // col 3 (in cached area)
175 176 177
    ]));
    log.clear();

178 179 180 181 182 183 184
    for (int i = 0; i < 9; i++) {
      expect(find.text('$i'), findsOneWidget);
    }
    for (int i = 9; i < 80; i++) {
      expect(find.text('$i'), findsNothing);
    }

185 186
    final ScrollableState state = tester.state(find.byType(Scrollable));
    final ScrollPosition position = state.position;
187 188 189 190 191 192
    position.jumpTo(3025.0);

    expect(log, isEmpty);
    await tester.pump();

    expect(log, equals(<int>[
193
      30, 31, 32, // col 10 (in cached area)
194 195 196 197
      33, 34, 35, // col 11
      36, 37, 38, // col 12
      39, 40, 41, // col 13
      42, 43, 44, // col 14
198
      45, 46, 47, // col 15 (in cached area)
199 200 201
    ]));
    log.clear();

202 203 204 205 206 207 208 209 210 211
    for (int i = 0; i < 33; i++) {
      expect(find.text('$i'), findsNothing);
    }
    for (int i = 33; i < 45; i++) {
      expect(find.text('$i'), findsOneWidget);
    }
    for (int i = 45; i < 80; i++) {
      expect(find.text('$i'), findsNothing);
    }

212 213 214 215 216 217
    position.jumpTo(975.0);

    expect(log, isEmpty);
    await tester.pump();

    expect(log, equals(<int>[
218
      6, 7, 8, // col2 (in cached area)
219 220 221 222
      9, 10, 11, // col 3
      12, 13, 14, // col 4
      15, 16, 17, // col 5
      18, 19, 20, // col 6
223
      21, 22, 23, // col 7 (in cached area)
224 225
    ]));
    log.clear();
226 227 228 229 230 231 232 233 234 235

    for (int i = 0; i < 9; i++) {
      expect(find.text('$i'), findsNothing);
    }
    for (int i = 9; i < 21; i++) {
      expect(find.text('$i'), findsOneWidget);
    }
    for (int i = 21; i < 80; i++) {
      expect(find.text('$i'), findsNothing);
    }
236 237
  });

238
  testWidgets('GridView - change crossAxisCount', (WidgetTester tester) async {
239
    final List<int> log = <int>[];
240 241

    await tester.pumpWidget(
242
      Directionality(
243
        textDirection: TextDirection.ltr,
244
        child: GridView(
245 246 247
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
          ),
248 249
          children: List<Widget>.generate(40, (int i) {
            return Builder(
250 251
              builder: (BuildContext context) {
                log.add(i);
252
                return Text('$i');
253
              },
254 255
            );
          }),
256 257 258 259 260 261 262 263 264 265
        ),
      ),
    );

    expect(tester.getSize(find.text('4')), equals(const Size(200.0, 200.0)));

    expect(log, equals(<int>[
      0, 1, 2, 3, // row 0
      4, 5, 6, 7, // row 1
      8, 9, 10, 11, // row 2
266 267
      12, 13, 14, 15, // row 3 (in cached area)
      16, 17, 18, 19, // row 4 (in cached area)
268
    ]));
269 270 271 272 273 274
    for (int i = 0; i < 12; i++) {
      expect(find.text('$i'), findsOneWidget);
    }
    for (int i = 12; i < 40; i++) {
      expect(find.text('$i'), findsNothing);
    }
275 276 277
    log.clear();

    await tester.pumpWidget(
278
      Directionality(
279
        textDirection: TextDirection.ltr,
280
        child: GridView(
281 282 283
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 2,
          ),
284 285
          children: List<Widget>.generate(40, (int i) {
            return Builder(
286 287
              builder: (BuildContext context) {
                log.add(i);
288
                return Text('$i');
289
              },
290 291
            );
          }),
292 293 294 295 296 297 298 299
        ),
      ),
    );

    expect(log, equals(<int>[
      0, 1, 2, 3, // row 0
      4, 5, 6, 7, // row 1
      8, 9, 10, 11, // row 2
300 301
      12, 13, 14, 15, // row 3 (in cached area)
      16, 17, 18, 19, // row 4 (in cached area)
302 303 304 305 306 307 308
    ]));
    log.clear();

    expect(tester.getSize(find.text('3')), equals(const Size(400.0, 400.0)));
    expect(find.text('4'), findsNothing);
  });

309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
  testWidgets('SliverGridRegularTileLayout - can handle close to zero mainAxisStride', (WidgetTester tester) async {
    const SliverGridDelegateWithMaxCrossAxisExtent delegate = SliverGridDelegateWithMaxCrossAxisExtent(
      childAspectRatio: 1e300,
      maxCrossAxisExtent: 500.0,
    );
    final SliverGridLayout layout = delegate.getLayout(
      const SliverConstraints(
        axisDirection: AxisDirection.down,
        growthDirection: GrowthDirection.forward,
        userScrollDirection: ScrollDirection.forward,
        scrollOffset: 100.0,
        precedingScrollExtent: 0.0,
        overlap: 0.0,
        remainingPaintExtent: 0.0,
        crossAxisExtent: 500,
        crossAxisDirection: AxisDirection.right,
        viewportMainAxisExtent: 100.0,
        remainingCacheExtent: 0.0,
        cacheOrigin: 0.0,
328
      ),
329 330 331 332
    );
    expect(layout.getMinChildIndexForScrollOffset(1000.0), 0.0);
  });

333
  testWidgets('GridView - change maxChildCrossAxisExtent', (WidgetTester tester) async {
334
    final List<int> log = <int>[];
335 336

    await tester.pumpWidget(
337
      Directionality(
338
        textDirection: TextDirection.ltr,
339
        child: GridView(
340 341 342
          gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
            maxCrossAxisExtent: 200.0,
          ),
343 344
          children: List<Widget>.generate(40, (int i) {
            return Builder(
345 346
              builder: (BuildContext context) {
                log.add(i);
347
                return Text('$i');
348
              },
349 350
            );
          }),
351 352 353 354 355 356 357 358 359 360
        ),
      ),
    );

    expect(tester.getSize(find.text('4')), equals(const Size(200.0, 200.0)));

    expect(log, equals(<int>[
      0, 1, 2, 3, // row 0
      4, 5, 6, 7, // row 1
      8, 9, 10, 11, // row 2
361 362
      12, 13, 14, 15, // row 3 (in cached area)
      16, 17, 18, 19, // row 4 (in cached area)
363
    ]));
364 365 366 367 368 369
    for (int i = 0; i < 12; i++) {
      expect(find.text('$i'), findsOneWidget);
    }
    for (int i = 12; i < 40; i++) {
      expect(find.text('$i'), findsNothing);
    }
370 371 372
    log.clear();

    await tester.pumpWidget(
373
      Directionality(
374
        textDirection: TextDirection.ltr,
375
        child: GridView(
376 377 378
          gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
            maxCrossAxisExtent: 400.0,
          ),
379 380
          children: List<Widget>.generate(40, (int i) {
            return Builder(
381 382
              builder: (BuildContext context) {
                log.add(i);
383
                return Text('$i');
384
              },
385 386
            );
          }),
387 388 389 390 391 392 393 394
        ),
      ),
    );

    expect(log, equals(<int>[
      0, 1, 2, 3, // row 0
      4, 5, 6, 7, // row 1
      8, 9, 10, 11, // row 2
395 396
      12, 13, 14, 15, // row 3 (in cached area)
      16, 17, 18, 19, // row 4 (in cached area)
397 398 399 400 401 402
    ]));
    log.clear();

    expect(tester.getSize(find.text('3')), equals(const Size(400.0, 400.0)));
    expect(find.text('4'), findsNothing);
  });
403

Adam Barth's avatar
Adam Barth committed
404
  testWidgets('One-line GridView paints', (WidgetTester tester) async {
405
    const Color green = Color(0xFF00FF00);
Adam Barth's avatar
Adam Barth committed
406

407
    final Container container = Container(
Adam Barth's avatar
Adam Barth committed
408
      decoration: const BoxDecoration(
409
        color: green,
Adam Barth's avatar
Adam Barth committed
410 411 412
      ),
    );

413
    await tester.pumpWidget(
414
      Directionality(
415
        textDirection: TextDirection.ltr,
416 417
        child: Center(
          child: SizedBox(
418
            height: 200.0,
419
            child: GridView.count(
420
              cacheExtent: 0.0,
421 422 423 424
              crossAxisCount: 2,
              children: <Widget>[ container, container, container, container ],
            ),
          ),
Adam Barth's avatar
Adam Barth committed
425 426
        ),
      ),
427
    );
Adam Barth's avatar
Adam Barth committed
428 429 430 431 432

    expect(find.byType(GridView), paints..rect(color: green)..rect(color: green));
    expect(find.byType(GridView), isNot(paints..rect(color: green)..rect(color: green)..rect(color: green)));
  });

433 434
  testWidgets('GridView in zero context', (WidgetTester tester) async {
    await tester.pumpWidget(
435
      Directionality(
436
        textDirection: TextDirection.ltr,
437 438
        child: Center(
          child: SizedBox(
439 440
            width: 0.0,
            height: 0.0,
441
            child: GridView.count(
442
              crossAxisCount: 4,
443
              children: List<Widget>.generate(20, (int i) {
444
                return Text('$i');
445 446 447 448 449 450 451
              }),
            ),
          ),
        ),
      ),
    );

452
    expect(find.text('0'), findsNothing);
453 454 455 456 457
    expect(find.text('1'), findsNothing);
  });

  testWidgets('GridView in unbounded context', (WidgetTester tester) async {
    await tester.pumpWidget(
458
      Directionality(
459
        textDirection: TextDirection.ltr,
460 461
        child: SingleChildScrollView(
          child: GridView.count(
462
            crossAxisCount: 4,
463
            shrinkWrap: true,
464
            children: List<Widget>.generate(20, (int i) {
465
              return Text('$i');
466 467 468 469 470 471 472
            }),
          ),
        ),
      ),
    );

    expect(find.text('0'), findsOneWidget);
473
    expect(find.text('19'), findsOneWidget);
474 475
  });

476
  testWidgets('GridView.builder control test', (WidgetTester tester) async {
477
    await tester.pumpWidget(
478
      Directionality(
479
        textDirection: TextDirection.ltr,
480
        child: GridView.builder(
481 482 483
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
          ),
484
          shrinkWrap: true,
485 486
          itemCount: 20,
          itemBuilder: (BuildContext context, int index) {
487
            return Text('$index');
488
          },
489 490 491
        ),
      ),
    );
492 493 494 495 496
    expect(find.text('0'), findsOneWidget);
    expect(find.text('11'), findsOneWidget);
    expect(find.text('12'), findsNothing);
  });

497 498
  testWidgets('GridView.builder with undefined itemCount', (WidgetTester tester) async {
    await tester.pumpWidget(
499
      Directionality(
500
        textDirection: TextDirection.ltr,
501
        child: GridView.builder(
502 503 504 505 506
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 4,
          ),
          shrinkWrap: true,
          itemBuilder: (BuildContext context, int index) {
507
            return Text('$index');
508 509 510 511 512 513 514 515 516 517 518
          },
        ),
      ),
    );
    expect(find.text('0'), findsOneWidget);
    expect(find.text('11'), findsOneWidget);
    await tester.drag(find.byType(GridView), const Offset(0.0, -300.0));
    await tester.pump(const Duration(milliseconds: 200));
    expect(find.text('13'), findsOneWidget);
  });

519
  testWidgets('GridView cross axis layout', (WidgetTester tester) async {
520
    final Key target = UniqueKey();
521 522

    Widget build(TextDirection textDirection) {
523
      return Directionality(
524
        textDirection: textDirection,
525
        child: GridView.count(
526 527
          crossAxisCount: 4,
          children: <Widget>[
528
            Container(key: target),
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
          ],
        ),
      );
    }

    await tester.pumpWidget(build(TextDirection.ltr));

    expect(tester.getTopLeft(find.byKey(target)), Offset.zero);
    expect(tester.getBottomRight(find.byKey(target)), const Offset(200.0, 200.0));

    await tester.pumpWidget(build(TextDirection.rtl));

    expect(tester.getTopLeft(find.byKey(target)), const Offset(600.0, 0.0));
    expect(tester.getBottomRight(find.byKey(target)), const Offset(800.0, 200.0));
  });
544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571

  testWidgets('GridView crossAxisSpacing', (WidgetTester tester) async {
    // Regression test for https://github.com/flutter/flutter/issues/27151.
    final Key target = UniqueKey();

    Widget build(TextDirection textDirection) {
      return Directionality(
        textDirection: textDirection,
        child: GridView.count(
          crossAxisCount: 4,
          crossAxisSpacing: 8.0,
          children: <Widget>[
            Container(key: target),
          ],
        ),
      );
    }

    await tester.pumpWidget(build(TextDirection.ltr));

    expect(tester.getTopLeft(find.byKey(target)), Offset.zero);
    expect(tester.getBottomRight(find.byKey(target)), const Offset(194.0, 194.0));

    await tester.pumpWidget(build(TextDirection.rtl));

    expect(tester.getTopLeft(find.byKey(target)), const Offset(606.0, 0.0));
    expect(tester.getBottomRight(find.byKey(target)), const Offset(800.0, 194.0));
  });
572 573 574 575 576 577 578 579 580 581

  testWidgets('GridView does not cache itemBuilder calls', (WidgetTester tester) async {
    final Map<int, int> counters = <int, int>{};

    await tester.pumpWidget(Directionality(
      textDirection: TextDirection.ltr,
      child: GridView.builder(
        itemCount: 1000,
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
        itemBuilder: (BuildContext context, int index) {
582
          counters[index] = (counters[index] ?? 0) + 1;
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
          return SizedBox(
            key: ValueKey<int>(index),
            width: 200,
            height: 200,
          );
        },
      ),
    ));

    expect(find.byKey(const ValueKey<int>(4)), findsOneWidget);
    expect(counters[4], 1);

    await tester.fling(find.byType(GridView), const Offset(0, -300), 5000);
    await tester.pumpAndSettle();

    expect(find.byKey(const ValueKey<int>(4)), findsNothing);
    expect(counters[4], 1);

    await tester.fling(find.byType(GridView), const Offset(0, 300), 5000);
    await tester.pumpAndSettle();

    expect(find.byKey(const ValueKey<int>(4)), findsOneWidget);
    expect(counters[4], 2);
  });
607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634

  testWidgets('GridView respects clipBehavior', (WidgetTester tester) async {
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
          children: <Widget>[Container(height: 2000.0)],
        ),
      ),
    );

    // 1st, check that the render object has received the default clip behavior.
    final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
    expect(renderObject.clipBehavior, equals(Clip.hardEdge));

    // 2nd, check that the painting context has received the default clip behavior.
    final TestClipPaintingContext context = TestClipPaintingContext();
    renderObject.paint(context, Offset.zero);
    expect(context.clipBehavior, equals(Clip.hardEdge));

    // 3rd, pump a new widget to check that the render object can update its clip behavior.
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
          clipBehavior: Clip.antiAlias,
635
          children: <Widget>[Container(height: 2000.0)],
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 683 684 685 686
        ),
      ),
    );
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));

    // 4th, check that a non-default clip behavior can be sent to the painting context.
    renderObject.paint(context, Offset.zero);
    expect(context.clipBehavior, equals(Clip.antiAlias));
  });

  testWidgets('GridView.builder respects clipBehavior', (WidgetTester tester) async {
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView.builder(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
          itemCount: 10,
          itemBuilder: (BuildContext _, int __) => Container(height: 2000.0),
          clipBehavior: Clip.antiAlias,
        ),
      ),
    );
    final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });

  testWidgets('GridView.custom respects clipBehavior', (WidgetTester tester) async {
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView.custom(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3),
          childrenDelegate: SliverChildBuilderDelegate(
                (BuildContext context, int index) => Container(height: 2000.0),
            childCount: 1,
          ),
          clipBehavior: Clip.antiAlias,
        ),
      ),
    );
    final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });

  testWidgets('GridView.count respects clipBehavior', (WidgetTester tester) async {
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView.count(
          crossAxisCount: 3,
          clipBehavior: Clip.antiAlias,
687
          children: <Widget>[Container(height: 2000.0)],
688 689 690 691 692 693 694 695 696 697 698 699 700 701
        ),
      ),
    );
    final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });

  testWidgets('GridView.extent respects clipBehavior', (WidgetTester tester) async {
    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView.extent(
          maxCrossAxisExtent: 1000,
          clipBehavior: Clip.antiAlias,
702
          children: <Widget>[Container(height: 2000.0)],
703 704 705 706 707 708
        ),
      ),
    );
    final RenderViewport renderObject = tester.allRenderObjects.whereType<RenderViewport>().first;
    expect(renderObject.clipBehavior, equals(Clip.antiAlias));
  });
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724

  testWidgets('SliverGridDelegateWithFixedCrossAxisCount mainAxisExtent works as expected', (WidgetTester tester) async {
    const int crossAxisCount = 4;
    const double mainAxisExtent = 100.0;

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView(
          gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: crossAxisCount,
            mainAxisExtent: mainAxisExtent,
          ),
          children: List<Widget>.generate(20, (int i) {
            return Builder(
              builder: (BuildContext context) {
725
                return Text('$i');
726
              },
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
            );
          }),
        ),
      ),
    );

    expect(tester.getSize(find.text('4')), equals(const Size(200.0, mainAxisExtent)));
  });

  testWidgets('SliverGridDelegateWithMaxCrossAxisExtent mainAxisExtent works as expected', (WidgetTester tester) async {
    const double maxCrossAxisExtent = 200.0;
    const double mainAxisExtent = 100.0;

    await tester.pumpWidget(
      Directionality(
        textDirection: TextDirection.ltr,
        child: GridView(
          gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
            maxCrossAxisExtent: maxCrossAxisExtent,
            mainAxisExtent: mainAxisExtent,
          ),
          children: List<Widget>.generate(20, (int i) {
            return Builder(
              builder: (BuildContext context) {
751
                return Text('$i');
752
              },
753 754 755 756 757 758 759 760
            );
          }),
        ),
      ),
    );

    expect(tester.getSize(find.text('4')), equals(const Size(200.0, mainAxisExtent)));
  });
761 762 763 764 765 766 767 768 769

  testWidgets('SliverGridDelegateWithMaxCrossAxisExtent throws assertion error when maxCrossAxisExtent is 0', (WidgetTester tester) async {
    const double maxCrossAxisExtent = 0;

    expect(() => Directionality(
      textDirection: TextDirection.ltr,
      child: GridView.extent(
        maxCrossAxisExtent: maxCrossAxisExtent,
      ),
770
    ), throwsAssertionError);
771 772

  });
773
}