scroll_view_test.dart 43.6 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/services.dart' show LogicalKeyboardKey;
6
import 'package:flutter_test/flutter_test.dart';
7
import 'package:flutter/gestures.dart' show DragStartBehavior;
8
import 'package:flutter/material.dart';
9

10
import 'states.dart';
11

12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
class MaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLocalizations> {
  @override
  bool isSupported(Locale locale) => true;

  @override
  Future<MaterialLocalizations> load(Locale locale) => DefaultMaterialLocalizations.load(locale);

  @override
  bool shouldReload(MaterialLocalizationsDelegate old) => false;
}

class WidgetsLocalizationsDelegate extends LocalizationsDelegate<WidgetsLocalizations> {
  @override
  bool isSupported(Locale locale) => true;

  @override
  Future<WidgetsLocalizations> load(Locale locale) => DefaultWidgetsLocalizations.load(locale);

  @override
  bool shouldReload(WidgetsLocalizationsDelegate old) => false;
}

34
Widget textFieldBoilerplate({ required Widget child }) {
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
  return MaterialApp(
    home: Localizations(
      locale: const Locale('en', 'US'),
      delegates: <LocalizationsDelegate<dynamic>>[
        WidgetsLocalizationsDelegate(),
        MaterialLocalizationsDelegate(),
      ],
      child: Directionality(
        textDirection: TextDirection.ltr,
        child: MediaQuery(
          data: const MediaQueryData(size: Size(800.0, 600.0)),
          child: Center(
            child: Material(
              child: child,
            ),
          ),
        ),
      ),
    ),
  );
}

57
void main() {
58
  testWidgets('ListView control test', (WidgetTester tester) async {
59
    final List<String> log = <String>[];
60

61
    await tester.pumpWidget(
62
      Directionality(
63
        textDirection: TextDirection.ltr,
64
        child: ListView(
65
          dragStartBehavior: DragStartBehavior.down,
66
          children: kStates.map<Widget>((String state) {
67
            return GestureDetector(
68 69 70
              onTap: () {
                log.add(state);
              },
71
              child: Container(
72 73
                height: 200.0,
                color: const Color(0xFF0000FF),
74
                child: Text(state),
75
              ),
76
              dragStartBehavior: DragStartBehavior.down,
77 78 79 80 81
            );
          }).toList(),
        ),
      ),
    );
82 83 84 85 86 87 88

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

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

89
    await tester.drag(find.text('Alabama'), const Offset(0.0, -4000.0));
90 91 92
    await tester.pump();

    expect(find.text('Alabama'), findsNothing);
93
    expect(tester.getCenter(find.text('Massachusetts')), equals(const Offset(400.0, 100.0)));
94 95 96 97 98

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

100 101 102 103
  testWidgets('ListView dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
104
      child: ListView(
105
        padding: EdgeInsets.zero,
106 107 108 109 110 111
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
112 113 114 115
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
116 117 118 119 120 121 122 123 124 125
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
126
    expect(textField.focusNode!.hasFocus, isTrue);
127 128 129

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
130
    expect(textField.focusNode!.hasFocus, isFalse);
131 132 133 134 135 136 137
  });

  testWidgets('ListView.builder dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: ListView.builder(
138
        padding: EdgeInsets.zero,
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        itemCount: focusNodes.length,
        itemBuilder: (BuildContext context,int index) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNodes[index],
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        },
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
160
    expect(textField.focusNode!.hasFocus, isTrue);
161 162 163

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
164
    expect(textField.focusNode!.hasFocus, isFalse);
165 166 167 168 169 170 171
  });

  testWidgets('ListView.custom dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: ListView.custom(
172
        padding: EdgeInsets.zero,
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        childrenDelegate: SliverChildBuilderDelegate(
          (BuildContext context,int index) {
            return Container(
              height: 50,
              color: Colors.green,
              child: TextField(
                focusNode: focusNodes[index],
                style: const TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                )
              ),
            );
          },
          childCount: focusNodes.length,
        ),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
196
    expect(textField.focusNode!.hasFocus, isTrue);
197 198 199

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
200
    expect(textField.focusNode!.hasFocus, isFalse);
201 202 203 204 205 206 207
  });

  testWidgets('ListView.separated dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: ListView.separated(
208
        padding: EdgeInsets.zero,
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        itemCount: focusNodes.length,
        separatorBuilder: (BuildContext context, int index) => const Divider(),
        itemBuilder: (BuildContext context,int index) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNodes[index],
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        },
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
231
    expect(textField.focusNode!.hasFocus, isTrue);
232 233 234

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
235
    expect(textField.focusNode!.hasFocus, isFalse);
236 237 238 239 240 241 242
  });

  testWidgets('GridView dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView(
243
        padding: EdgeInsets.zero,
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
265
    expect(textField.focusNode!.hasFocus, isTrue);
266 267 268

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
269
    expect(textField.focusNode!.hasFocus, isFalse);
270 271 272 273 274 275 276
  });

  testWidgets('GridView.builder dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.builder(
277
        padding: EdgeInsets.zero,
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        itemCount: focusNodes.length,
        itemBuilder: (BuildContext context, int index){
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNodes[index],
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
          );
        },
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
300
    expect(textField.focusNode!.hasFocus, isTrue);
301 302 303

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
304
    expect(textField.focusNode!.hasFocus, isFalse);
305 306 307 308 309 310 311
  });

  testWidgets('GridView.count dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.count(
312
        padding: EdgeInsets.zero,
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
        crossAxisCount: 2,
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
334
    expect(textField.focusNode!.hasFocus, isTrue);
335 336 337

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
338
    expect(textField.focusNode!.hasFocus, isFalse);
339 340 341 342 343 344 345
  });

  testWidgets('GridView.extent dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.extent(
346
        padding: EdgeInsets.zero,
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
        maxCrossAxisExtent: 300,
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
368
    expect(textField.focusNode!.hasFocus, isTrue);
369 370 371

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
372
    expect(textField.focusNode!.hasFocus, isFalse);
373 374 375 376 377 378 379
  });

  testWidgets('GridView.custom dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.custom(
380
        padding: EdgeInsets.zero,
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        childrenDelegate: SliverChildBuilderDelegate(
          (BuildContext context,int index) {
            return Container(
              height: 50,
              color: Colors.green,
              child: TextField(
                focusNode: focusNodes[index],
                style: const TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                )
              ),
            );
          },
          childCount: focusNodes.length,
        ),
      ),
    ));
401 402 403 404

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
405
    expect(textField.focusNode!.hasFocus, isTrue);
406 407 408

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
409
    expect(textField.focusNode!.hasFocus, isFalse);
410 411 412 413 414 415 416
  });

  testWidgets('ListView dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
        child: ListView(
417
      padding: EdgeInsets.zero,
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435
      keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
      children: focusNodes.map((FocusNode focusNode) {
        return Container(
          height: 50,
          color: Colors.green,
          child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )),
        );
      }).toList(),
    )));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
436
    expect(textField.focusNode!.hasFocus, isTrue);
437 438

    await tester.drag(finder, const Offset(0.0, -40.0));
439
    await tester.pumpAndSettle();
440
    expect(textField.focusNode!.hasFocus, isTrue);
441 442 443 444 445 446 447
  });

  testWidgets('ListView.builder dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: ListView.builder(
448
        padding: EdgeInsets.zero,
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        itemCount: focusNodes.length,
        itemBuilder: (BuildContext context,int index) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNodes[index],
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        },
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
470
    expect(textField.focusNode!.hasFocus, isTrue);
471 472 473

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
474
    expect(textField.focusNode!.hasFocus, isTrue);
475 476 477 478 479 480 481
  });

  testWidgets('ListView.custom dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: ListView.custom(
482
        padding: EdgeInsets.zero,
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        childrenDelegate: SliverChildBuilderDelegate(
          (BuildContext context,int index) {
            return Container(
              height: 50,
              color: Colors.green,
              child: TextField(
                focusNode: focusNodes[index],
                style: const TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                )
              ),
            );
          },
          childCount: focusNodes.length,
        ),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
506
    expect(textField.focusNode!.hasFocus, isTrue);
507 508 509

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
510
    expect(textField.focusNode!.hasFocus, isTrue);
511 512 513 514 515 516 517
  });

  testWidgets('ListView.separated dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: ListView.separated(
518
        padding: EdgeInsets.zero,
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        itemCount: focusNodes.length,
        separatorBuilder: (BuildContext context, int index) => const Divider(),
        itemBuilder: (BuildContext context,int index) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNodes[index],
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        },
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
541
    expect(textField.focusNode!.hasFocus, isTrue);
542 543 544

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
545
    expect(textField.focusNode!.hasFocus, isTrue);
546 547 548 549 550 551 552
  });

  testWidgets('GridView dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView(
553
        padding: EdgeInsets.zero,
554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
575
    expect(textField.focusNode!.hasFocus, isTrue);
576 577 578

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
579
    expect(textField.focusNode!.hasFocus, isTrue);
580 581 582 583 584 585 586
  });

  testWidgets('GridView.builder dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.builder(
587
        padding: EdgeInsets.zero,
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        itemCount: focusNodes.length,
        itemBuilder: (BuildContext context, int index){
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNodes[index],
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              ),
            ),
          );
        },
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
610
    expect(textField.focusNode!.hasFocus, isTrue);
611 612 613

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
614
    expect(textField.focusNode!.hasFocus, isTrue);
615 616 617 618 619 620 621
  });

  testWidgets('GridView.count dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.count(
622
        padding: EdgeInsets.zero,
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
        crossAxisCount: 2,
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
644
    expect(textField.focusNode!.hasFocus, isTrue);
645 646 647

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
648
    expect(textField.focusNode!.hasFocus, isTrue);
649 650 651 652 653 654 655
  });

  testWidgets('GridView.extent dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.extent(
656
        padding: EdgeInsets.zero,
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
        maxCrossAxisExtent: 300,
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        children: focusNodes.map((FocusNode focusNode) {
          return Container(
            height: 50,
            color: Colors.green,
            child: TextField(
              focusNode: focusNode,
              style: const TextStyle(
                fontSize: 24,
                fontWeight: FontWeight.bold,
              )
            ),
          );
        }).toList(),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
678
    expect(textField.focusNode!.hasFocus, isTrue);
679 680 681

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
682
    expect(textField.focusNode!.hasFocus, isTrue);
683 684 685 686 687 688 689
  });

  testWidgets('GridView.custom dismiss keyboard manual test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: GridView.custom(
690
        padding: EdgeInsets.zero,
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714
        gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount:2),
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.manual,
        childrenDelegate: SliverChildBuilderDelegate(
          (BuildContext context,int index) {
            return Container(
              height: 50,
              color: Colors.green,
              child: TextField(
                focusNode: focusNodes[index],
                style: const TextStyle(
                  fontSize: 24,
                  fontWeight: FontWeight.bold,
                )
              ),
            );
          },
          childCount: focusNodes.length,
        ),
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
715
    expect(textField.focusNode!.hasFocus, isTrue);
716 717

    await tester.drag(finder, const Offset(0.0, -40.0));
718
    await tester.pumpAndSettle();
719
    expect(textField.focusNode!.hasFocus, isTrue);
720 721
  });

722 723
  testWidgets('ListView restart ballistic activity out of range', (WidgetTester tester) async {
    Widget buildListView(int n) {
724
      return Directionality(
725
        textDirection: TextDirection.ltr,
726
        child: ListView(
727
          dragStartBehavior: DragStartBehavior.down,
728
          children: kStates.take(n).map<Widget>((String state) {
729
            return Container(
730 731
              height: 200.0,
              color: const Color(0xFF0000FF),
732
              child: Text(state),
733 734 735
            );
          }).toList(),
        ),
736 737 738
      );
    }

739 740 741
    await tester.pumpWidget(buildListView(30));
    await tester.fling(find.byType(ListView), const Offset(0.0, -4000.0), 4000.0);
    await tester.pumpWidget(buildListView(15));
742 743 744 745
    await tester.pump(const Duration(milliseconds: 10));
    await tester.pump(const Duration(milliseconds: 10));
    await tester.pump(const Duration(milliseconds: 10));
    await tester.pump(const Duration(milliseconds: 10));
746
    await tester.pumpAndSettle(const Duration(milliseconds: 100));
747

748
    final Viewport viewport = tester.widget(find.byType(Viewport));
749 750
    expect(viewport.offset.pixels, equals(2400.0));
  });
Adam Barth's avatar
Adam Barth committed
751 752

  testWidgets('CustomScrollView control test', (WidgetTester tester) async {
753
    final List<String> log = <String>[];
Adam Barth's avatar
Adam Barth committed
754

755
    await tester.pumpWidget(
756
      Directionality(
757
        textDirection: TextDirection.ltr,
758
        child: CustomScrollView(
759
          dragStartBehavior: DragStartBehavior.down,
760
          slivers: <Widget>[
761 762
            SliverList(
              delegate: SliverChildListDelegate(
763
                kStates.map<Widget>((String state) {
764
                  return GestureDetector(
765
                    dragStartBehavior: DragStartBehavior.down,
766 767 768
                    onTap: () {
                      log.add(state);
                    },
769
                    child: Container(
770 771
                      height: 200.0,
                      color: const Color(0xFF0000FF),
772
                      child: Text(state),
773 774 775 776 777 778
                    ),
                  );
                }).toList(),
              ),
            ),
          ],
Adam Barth's avatar
Adam Barth committed
779
        ),
780 781
      ),
    );
Adam Barth's avatar
Adam Barth committed
782 783 784 785 786 787 788

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

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

789
    await tester.drag(find.text('Alabama'), const Offset(0.0, -4000.0));
Adam Barth's avatar
Adam Barth committed
790 791 792
    await tester.pump();

    expect(find.text('Alabama'), findsNothing);
793
    expect(tester.getCenter(find.text('Massachusetts')), equals(const Offset(400.0, 100.0)));
Adam Barth's avatar
Adam Barth committed
794 795 796 797 798

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

800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
  testWidgets('CustomScrollView dismiss keyboard onDrag test', (WidgetTester tester) async {
    final List<FocusNode> focusNodes = List<FocusNode>.generate(50, (int i) => FocusNode());

    await tester.pumpWidget(textFieldBoilerplate(
      child: CustomScrollView(
        dragStartBehavior: DragStartBehavior.down,
        keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
        slivers: <Widget>[
          SliverList(
            delegate: SliverChildListDelegate(
              focusNodes.map((FocusNode focusNode) {
                return Container(
                  height: 50,
                  color: Colors.green,
                  child: TextField(
                    focusNode: focusNode,
                    style: const TextStyle(
                      fontSize: 24,
                      fontWeight: FontWeight.bold,
                    )
                  ),
                );
              }).toList(),
            ),
          ),
        ],
      ),
    ));

    final Finder finder = find.byType(TextField).first;
    final TextField textField = tester.widget(finder);
    await tester.showKeyboard(finder);
832
    expect(textField.focusNode!.hasFocus, isTrue);
833 834 835

    await tester.drag(finder, const Offset(0.0, -40.0));
    await tester.pumpAndSettle();
836
    expect(textField.focusNode!.hasFocus, isFalse);
837 838
  });

839 840
  testWidgets('Can jumpTo during drag', (WidgetTester tester) async {
    final List<Type> log = <Type>[];
841
    final ScrollController controller = ScrollController();
842

843
    await tester.pumpWidget(
844
      Directionality(
845
        textDirection: TextDirection.ltr,
846
        child: NotificationListener<ScrollNotification>(
847 848 849 850
          onNotification: (ScrollNotification notification) {
            log.add(notification.runtimeType);
            return false;
          },
851
          child: ListView(
852 853
            controller: controller,
            children: kStates.map<Widget>((String state) {
854
              return SizedBox(
855
                height: 200.0,
856
                child: Text(state),
857 858 859 860
              );
            }).toList(),
          ),
        ),
861
      ),
862
    );
863 864 865

    expect(log, isEmpty);

866
    final TestGesture gesture = await tester.startGesture(const Offset(100.0, 100.0));
867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
    await gesture.moveBy(const Offset(0.0, -100.0));

    expect(log, equals(<Type>[
      ScrollStartNotification,
      UserScrollNotification,
      ScrollUpdateNotification,
    ]));
    log.clear();

    await tester.pump();

    controller.jumpTo(550.0);

    expect(controller.offset, equals(550.0));
    expect(log, equals(<Type>[
      ScrollEndNotification,
      UserScrollNotification,
      ScrollStartNotification,
      ScrollUpdateNotification,
      ScrollEndNotification,
    ]));
    log.clear();

    await tester.pump();
    await gesture.moveBy(const Offset(0.0, -100.0));

    expect(controller.offset, equals(550.0));
    expect(log, isEmpty);
  });
896

897
  testWidgets('Vertical CustomScrollViews are primary by default', (WidgetTester tester) async {
898
    const CustomScrollView view = CustomScrollView(scrollDirection: Axis.vertical);
899 900 901 902
    expect(view.primary, isTrue);
  });

  testWidgets('Vertical ListViews are primary by default', (WidgetTester tester) async {
903
    final ListView view = ListView(scrollDirection: Axis.vertical);
904 905 906 907
    expect(view.primary, isTrue);
  });

  testWidgets('Vertical GridViews are primary by default', (WidgetTester tester) async {
908
    final GridView view = GridView.count(
909 910 911 912 913 914 915
      scrollDirection: Axis.vertical,
      crossAxisCount: 1,
    );
    expect(view.primary, isTrue);
  });

  testWidgets('Horizontal CustomScrollViews are non-primary by default', (WidgetTester tester) async {
916
    const CustomScrollView view = CustomScrollView(scrollDirection: Axis.horizontal);
917 918 919 920
    expect(view.primary, isFalse);
  });

  testWidgets('Horizontal ListViews are non-primary by default', (WidgetTester tester) async {
921
    final ListView view = ListView(scrollDirection: Axis.horizontal);
922 923 924 925
    expect(view.primary, isFalse);
  });

  testWidgets('Horizontal GridViews are non-primary by default', (WidgetTester tester) async {
926
    final GridView view = GridView.count(
927 928 929 930 931 932 933
      scrollDirection: Axis.horizontal,
      crossAxisCount: 1,
    );
    expect(view.primary, isFalse);
  });

  testWidgets('CustomScrollViews with controllers are non-primary by default', (WidgetTester tester) async {
934 935
    final CustomScrollView view = CustomScrollView(
      controller: ScrollController(),
936 937 938 939 940 941
      scrollDirection: Axis.vertical,
    );
    expect(view.primary, isFalse);
  });

  testWidgets('ListViews with controllers are non-primary by default', (WidgetTester tester) async {
942 943
    final ListView view = ListView(
      controller: ScrollController(),
944 945 946 947 948 949
      scrollDirection: Axis.vertical,
    );
    expect(view.primary, isFalse);
  });

  testWidgets('GridViews with controllers are non-primary by default', (WidgetTester tester) async {
950 951
    final GridView view = GridView.count(
      controller: ScrollController(),
952 953 954 955 956 957
      scrollDirection: Axis.vertical,
      crossAxisCount: 1,
    );
    expect(view.primary, isFalse);
  });

958
  testWidgets('CustomScrollView sets PrimaryScrollController when primary', (WidgetTester tester) async {
959
    final ScrollController primaryScrollController = ScrollController();
960
    await tester.pumpWidget(
961
      Directionality(
962
        textDirection: TextDirection.ltr,
963
        child: PrimaryScrollController(
964
          controller: primaryScrollController,
965
          child: const CustomScrollView(primary: true),
966 967 968
        ),
      ),
    );
969
    final Scrollable scrollable = tester.widget(find.byType(Scrollable));
970 971 972 973
    expect(scrollable.controller, primaryScrollController);
  });

  testWidgets('ListView sets PrimaryScrollController when primary', (WidgetTester tester) async {
974
    final ScrollController primaryScrollController = ScrollController();
975
    await tester.pumpWidget(
976
      Directionality(
977
        textDirection: TextDirection.ltr,
978
        child: PrimaryScrollController(
979
          controller: primaryScrollController,
980
          child: ListView(primary: true),
981 982 983
        ),
      ),
    );
984
    final Scrollable scrollable = tester.widget(find.byType(Scrollable));
985 986 987 988
    expect(scrollable.controller, primaryScrollController);
  });

  testWidgets('GridView sets PrimaryScrollController when primary', (WidgetTester tester) async {
989
    final ScrollController primaryScrollController = ScrollController();
990
    await tester.pumpWidget(
991
      Directionality(
992
        textDirection: TextDirection.ltr,
993
        child: PrimaryScrollController(
994
          controller: primaryScrollController,
995
          child: GridView.count(primary: true, crossAxisCount: 1),
996 997 998
        ),
      ),
    );
999
    final Scrollable scrollable = tester.widget(find.byType(Scrollable));
1000 1001
    expect(scrollable.controller, primaryScrollController);
  });
1002 1003

  testWidgets('Nested scrollables have a null PrimaryScrollController', (WidgetTester tester) async {
1004
    const Key innerKey = Key('inner');
1005
    final ScrollController primaryScrollController = ScrollController();
1006
    await tester.pumpWidget(
1007
      Directionality(
1008
        textDirection: TextDirection.ltr,
1009
        child: PrimaryScrollController(
1010
          controller: primaryScrollController,
1011
          child: ListView(
1012 1013
            primary: true,
            children: <Widget>[
1014
              Container(
1015
                constraints: const BoxConstraints(maxHeight: 200.0),
1016
                child: ListView(key: innerKey, primary: true),
1017 1018
              ),
            ],
1019
          ),
1020
        ),
1021
      ),
1022
    );
1023

1024
    final Scrollable innerScrollable = tester.widget(
1025 1026 1027 1028 1029 1030 1031
      find.descendant(
        of: find.byKey(innerKey),
        matching: find.byType(Scrollable),
      ),
    );
    expect(innerScrollable.controller, isNull);
  });
1032 1033

  testWidgets('Primary ListViews are always scrollable', (WidgetTester tester) async {
1034
    final ListView view = ListView(primary: true);
Dan Field's avatar
Dan Field committed
1035
    expect(view.physics, isA<AlwaysScrollableScrollPhysics>());
1036 1037 1038
  });

  testWidgets('Non-primary ListViews are not always scrollable', (WidgetTester tester) async {
1039
    final ListView view = ListView(primary: false);
Dan Field's avatar
Dan Field committed
1040
    expect(view.physics, isNot(isA<AlwaysScrollableScrollPhysics>()));
1041 1042 1043
  });

  testWidgets('Defaulting-to-primary ListViews are always scrollable', (WidgetTester tester) async {
1044
    final ListView view = ListView(scrollDirection: Axis.vertical);
Dan Field's avatar
Dan Field committed
1045
    expect(view.physics, isA<AlwaysScrollableScrollPhysics>());
1046 1047 1048
  });

  testWidgets('Defaulting-to-not-primary ListViews are not always scrollable', (WidgetTester tester) async {
1049
    final ListView view = ListView(scrollDirection: Axis.horizontal);
Dan Field's avatar
Dan Field committed
1050
    expect(view.physics, isNot(isA<AlwaysScrollableScrollPhysics>()));
1051 1052 1053 1054 1055
  });

  testWidgets('primary:true leads to scrolling', (WidgetTester tester) async {
    bool scrolled = false;
    await tester.pumpWidget(
1056
      Directionality(
1057
        textDirection: TextDirection.ltr,
1058
        child: NotificationListener<OverscrollNotification>(
1059 1060 1061 1062
          onNotification: (OverscrollNotification message) {
            scrolled = true;
            return false;
          },
1063
          child: ListView(
1064
            primary: true,
1065
            children: const <Widget>[],
1066
          ),
1067 1068 1069 1070 1071 1072 1073 1074 1075 1076
        ),
      ),
    );
    await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
    expect(scrolled, isTrue);
  });

  testWidgets('primary:false leads to no scrolling', (WidgetTester tester) async {
    bool scrolled = false;
    await tester.pumpWidget(
1077
      Directionality(
1078
        textDirection: TextDirection.ltr,
1079
        child: NotificationListener<OverscrollNotification>(
1080 1081 1082 1083
          onNotification: (OverscrollNotification message) {
            scrolled = true;
            return false;
          },
1084
          child: ListView(
1085
            primary: false,
1086
            children: const <Widget>[],
1087
          ),
1088 1089 1090 1091 1092 1093 1094
        ),
      ),
    );
    await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
    expect(scrolled, isFalse);
  });

Ian Hickson's avatar
Ian Hickson committed
1095
  testWidgets('physics:AlwaysScrollableScrollPhysics actually overrides primary:false default behavior', (WidgetTester tester) async {
1096 1097
    bool scrolled = false;
    await tester.pumpWidget(
1098
      Directionality(
1099
        textDirection: TextDirection.ltr,
1100
        child: NotificationListener<OverscrollNotification>(
1101 1102 1103 1104
          onNotification: (OverscrollNotification message) {
            scrolled = true;
            return false;
          },
1105
          child: ListView(
1106 1107
            primary: false,
            physics: const AlwaysScrollableScrollPhysics(),
1108
            children: const <Widget>[],
1109
          ),
1110 1111 1112 1113 1114 1115 1116
        ),
      ),
    );
    await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
    expect(scrolled, isTrue);
  });

Ian Hickson's avatar
Ian Hickson committed
1117
  testWidgets('physics:ScrollPhysics actually overrides primary:true default behavior', (WidgetTester tester) async {
1118 1119
    bool scrolled = false;
    await tester.pumpWidget(
1120
      Directionality(
1121
        textDirection: TextDirection.ltr,
1122
        child: NotificationListener<OverscrollNotification>(
1123 1124 1125 1126
          onNotification: (OverscrollNotification message) {
            scrolled = true;
            return false;
          },
1127
          child: ListView(
1128 1129
            primary: true,
            physics: const ScrollPhysics(),
1130
            children: const <Widget>[],
1131
          ),
1132 1133 1134 1135 1136 1137
        ),
      ),
    );
    await tester.dragFrom(const Offset(100.0, 100.0), const Offset(0.0, 100.0));
    expect(scrolled, isFalse);
  });
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151

  testWidgets('separatorBuilder must return something', (WidgetTester tester) async {
    const List<String> listOfValues = <String>['ALPHA', 'BETA', 'GAMMA', 'DELTA'];

    Widget buildFrame(Widget firstSeparator) {
      return MaterialApp(
        home: Material(
          child: ListView.separated(
            itemBuilder: (BuildContext context, int index) {
              return Text(listOfValues[index]);
            },
            separatorBuilder: (BuildContext context, int index) {
              if (index == 0) {
                return firstSeparator;
1152
              } else {
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
                return const Divider();
              }
            },
            itemCount: listOfValues.length,
          ),
        ),
      );
    }

    // A separatorBuilder that always returns a Divider is fine
    await tester.pumpWidget(buildFrame(const Divider()));
    expect(tester.takeException(), isNull);
  });

  testWidgets('when itemBuilder throws, creates Error Widget', (WidgetTester tester) async {
    const List<String> listOfValues = <String>['ALPHA', 'BETA', 'GAMMA', 'DELTA'];

    Widget buildFrame(bool throwOnFirstItem) {
      return MaterialApp(
        home: Material(
          child: ListView.builder(
            itemBuilder: (BuildContext context, int index) {
              if (index == 0 && throwOnFirstItem) {
                throw Exception('itemBuilder fail');
              }
              return Text(listOfValues[index]);
            },
            itemCount: listOfValues.length,
          ),
        ),
      );
    }

    // When itemBuilder doesn't throw, no ErrorWidget
    await tester.pumpWidget(buildFrame(false));
    expect(tester.takeException(), isNull);
    final Finder finder = find.byType(ErrorWidget);
    expect(find.byType(ErrorWidget), findsNothing);

    // When it does throw, one error widget is rendered in the item's place
    await tester.pumpWidget(buildFrame(true));
Dan Field's avatar
Dan Field committed
1194
    expect(tester.takeException(), isA<Exception>());
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
    expect(finder, findsOneWidget);
  });

  testWidgets('when separatorBuilder throws, creates ErrorWidget', (WidgetTester tester) async {
    const List<String> listOfValues = <String>['ALPHA', 'BETA', 'GAMMA', 'DELTA'];
    const Key key = Key('list');

    Widget buildFrame(bool throwOnFirstSeparator) {
      return MaterialApp(
        home: Material(
          child: ListView.separated(
            key: key,
            itemBuilder: (BuildContext context, int index) {
              return Text(listOfValues[index]);
            },
            separatorBuilder: (BuildContext context, int index) {
              if (index == 0 && throwOnFirstSeparator) {
                throw Exception('separatorBuilder fail');
              }
              return const Divider();
            },
            itemCount: listOfValues.length,
          ),
        ),
      );
    }

    // When separatorBuilder doesn't throw, no ErrorWidget
    await tester.pumpWidget(buildFrame(false));
    expect(tester.takeException(), isNull);
    final Finder finder = find.byType(ErrorWidget);
    expect(find.byType(ErrorWidget), findsNothing);

    // When it does throw, one error widget is rendered in the separator's place
    await tester.pumpWidget(buildFrame(true));
Dan Field's avatar
Dan Field committed
1230
    expect(tester.takeException(), isA<Exception>());
1231 1232
    expect(finder, findsOneWidget);
  });
1233 1234 1235 1236 1237 1238 1239

  testWidgets('ListView.builder asserts on negative childCount', (WidgetTester tester) async {
    expect(() => ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return const SizedBox();
      },
      itemCount: -1,
Dan Field's avatar
Dan Field committed
1240
    ), throwsAssertionError);
1241 1242 1243 1244 1245 1246 1247 1248 1249
  });

  testWidgets('ListView.builder asserts on negative semanticChildCount', (WidgetTester tester) async {
    expect(() => ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return const SizedBox();
      },
      itemCount: 1,
      semanticChildCount: -1,
Dan Field's avatar
Dan Field committed
1250
    ), throwsAssertionError);
1251 1252 1253 1254 1255 1256 1257 1258 1259
  });

  testWidgets('ListView.builder asserts on nonsensical childCount/semanticChildCount', (WidgetTester tester) async {
    expect(() => ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return const SizedBox();
      },
      itemCount: 1,
      semanticChildCount: 4,
Dan Field's avatar
Dan Field committed
1260
    ), throwsAssertionError);
1261
  });
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305

  testWidgets('PrimaryScrollController provides fallback ScrollActions', (WidgetTester tester)  async {
    await tester.pumpWidget(
      MaterialApp(
        home: CustomScrollView(
          primary: true,
          slivers: List<Widget>.generate(
            20,
            (int index) {
              return SliverToBoxAdapter(
                child: Focus(
                  autofocus: index == 0,
                  child: SizedBox(key: ValueKey<String>('Box $index'), height: 50.0),
                ),
              );
            },
          ),
        ),
      ),
    );
    final ScrollController controller = PrimaryScrollController.of(
      tester.element(find.byType(CustomScrollView))
    )!;
    await tester.pumpAndSettle();
    expect(controller.position.pixels, equals(0.0));
    expect(
      tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
      equals(const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0)),
    );
    await tester.sendKeyEvent(LogicalKeyboardKey.pageDown);
    await tester.pumpAndSettle();
    expect(controller.position.pixels, equals(400.0));
    expect(
      tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
      equals(const Rect.fromLTRB(0.0, -400.0, 800.0, -350.0)),
    );
    await tester.sendKeyEvent(LogicalKeyboardKey.pageUp);
    await tester.pumpAndSettle();
    expect(controller.position.pixels, equals(0.0));
    expect(
      tester.getRect(find.byKey(const ValueKey<String>('Box 0'), skipOffstage: false)),
      equals(const Rect.fromLTRB(0.0, 0.0, 800.0, 50.0)),
    );
  });
1306
}