Repository: flutter
Issue: [integration_test] scrollUntilVisible example with multiple scrollviews
Labels: a: tests,framework,d: examples,f: integration_test,P2,team-framework,triaged-framework

## Steps to Reproduce

I am trying to write integration test for flutter ListView.builder & scroll to specific item in the list. 

This gives error - 
```
type 'ListView' is not a subtype of type 'Scrollable' in type cast
```

Below are the details for the same - 

pubspec.yaml file
```
name: sample_integration_test
description: A new Flutter project.

publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^1.0.2

dev_dependencies:
  flutter_test:
    sdk: flutter
  integration_test:
    sdk: flutter

flutter:

  uses-material-design: true

```

lib/main.dart file
```
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp(
    items: List<String>.generate(1000, (i) => 'Item $i'),
  ));
}

class MyApp extends StatelessWidget {
  final List<String> items;

  MyApp({Key? key, required this.items}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final title = 'Long List';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: ListView.builder(
          key: Key("list"),
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
              key: Key("item" + index.toString()),
              title: Text('${items[index]}'),
            );
          },
        ),
      ),
    );
  }
}

```

test_driver/integration_test.dart file
```
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();
```

integration_test/app_test.dart file
```
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:sample_integration_test/main.dart';

void main() {
  IntegrationTestWidgetsFlutterBinding.ensureInitialized();

  // Tests will go here...
  testWidgets(
    "Listview.builder scroll test",
    (WidgetTester tester) async {
      // Testing starts at the root widget in the widget tree

      await tester.pumpWidget(MyApp(
        items: List<String>.generate(1000, (i) => 'Item $i'),
      ));

      // await tester.tap(find.byType(FloatingActionButton));
      // // Wait for all the animations to finish
      await tester.pumpAndSettle();

      final list = find.byKey(Key("list"));
      final selectedItem = find.byKey(Key("item5"));

      await tester.scrollUntilVisible(selectedItem, -200.0,
          scrollable: list, maxScrolls: 200);

      await Future.delayed(const Duration(seconds: 1));
    },
  );
}

```

Command to run the test - 

```
flutter drive --driver=test_driver/integration_test.dart --target=integration_test/app_test.dart
```

**Expected results:** 

Test passed

**Actual results:** 

══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following _CastError was thrown running a test:
type 'ListView' is not a subtype of type 'Scrollable' in type 
cast


```
Running "flutter pub get" in sample_integration_test...          1,655ms
Running Gradle task 'assembleDebug'...                                  
Running Gradle task 'assembleDebug'... Done                         8.6s
✓  Built build/app/outputs/flutter-apk/app-debug.apk.
Installing build/app/outputs/flutter-apk/app.apk...                10.0s
W/Gralloc3(15285): mapper 3.x is not supported
W/Choreographer(15285): Already have a pending vsync event.  There should only be one at a time.
I/Choreographer(15285): Skipped 34 frames!  The application may be doing too much work on its main thread.
D/OnePlusJankManager(15285):  Chor uploadMDM JANK_TYPE_ONCE mViewTitle =
com.example.sample_integration_test/com.example.sample_integration_test.MainActivity--- jank level = 3
D/SharedPreferencesImpl(15285): Time required to fsync /data/user/0/com.example.sample_integration_test/shared_prefs/embryo.xml: [<1: 0, <2: 0, <4: 0, <8: 0,
<16: 0, <32: 0, <64: 0, <128: 0, <256: 0, <512: 0, <1024: 0, <2048: 1, <4096: 0, <8192: 0, <16384: 0, >=16384: 0]
VMServiceFlutterDriver: Connecting to Flutter application at http://127.0.0.1:58922/W5EAvArSXzQ=/
VMServiceFlutterDriver: Isolate found with number: 3707526729812319
VMServiceFlutterDriver: Isolate is paused at start.
VMServiceFlutterDriver: Attempting to resume isolate
I/flutter (15285): 00:00 +0: Listview.builder scroll test
VMServiceFlutterDriver: Connected to Flutter application.
I/flutter (15285): (The following exception is now available via WidgetTester.takeException:)
I/flutter (15285): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (15285): The following _CastError was thrown running a test:
I/flutter (15285): type 'ListView' is not a subtype of type 'Scrollable' in type cast
I/flutter (15285): 
I/flutter (15285): When the exception was thrown, this was the stack:
I/flutter (15285): #0      WidgetController.widget (package:flutter_test/src/controller.dart:67:44)
I/flutter (15285): #1      WidgetController.scrollUntilVisible.<anonymous closure> (package:flutter_test/src/controller.dart:1139:15)
I/flutter (15285): #2      WidgetController.scrollUntilVisible.<anonymous closure> (package:flutter_test/src/controller.dart:1137:39)
I/flutter (15285): #5      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
I/flutter (15285): #6      WidgetController.scrollUntilVisible (package:flutter_test/src/controller.dart:1137:27)
I/flutter (15285): #7      main.<anonymous closure>
(file:///Users/xenlabs/Documents/Nikhil/Trial_Apps/sample_integration_test/integration_test/app_test.dart:26:20)
I/flutter (15285): <asynchronous suspension>
I/flutter (15285): <asynchronous suspension>
I/flutter (15285): (elided 3 frames from dart:async and package:stack_trace)
I/flutter (15285): 
I/flutter (15285): The test description was:
I/flutter (15285):   Listview.builder scroll test
I/flutter (15285): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15285): (If WidgetTester.takeException is called, the above exception will be ignored. If it is not, then the above exception will be dumped when
another exception is caught by the framework or when the test ends, whichever happens first, and then the test will fail due to having not caught or expected
the exception.)
I/flutter (15285): ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
I/flutter (15285): The following _CastError was thrown running a test:
I/flutter (15285): type 'ListView' is not a subtype of type 'Scrollable' in type cast
I/flutter (15285): 
I/flutter (15285): When the exception was thrown, this was the stack:
I/flutter (15285): #0      WidgetController.widget (package:flutter_test/src/controller.dart:67:44)
I/flutter (15285): #1      WidgetController.scrollUntilVisible.<anonymous closure> (package:flutter_test/src/controller.dart:1139:15)
I/flutter (15285): #2      WidgetController.scrollUntilVisible.<anonymous closure> (package:flutter_test/src/controller.dart:1137:39)
I/flutter (15285): #5      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
I/flutter (15285): #6      WidgetController.scrollUntilVisible (package:flutter_test/src/controller.dart:1137:27)
I/flutter (15285): #7      main.<anonymous closure>
(file:///Users/xenlabs/Documents/Nikhil/Trial_Apps/sample_integration_test/integration_test/app_test.dart:26:20)
I/flutter (15285): <asynchronous suspension>
I/flutter (15285): <asynchronous suspension>
I/flutter (15285): (elided 3 frames from dart:async and package:stack_trace)
I/flutter (15285): 
I/flutter (15285): The test description was:
I/flutter (15285):   Listview.builder scroll test
I/flutter (15285): ════════════════════════════════════════════════════════════════════════════════════════════════════
I/flutter (15285): 00:02 +0: Listview.builder scroll test [E]
I/flutter (15285):   Test failed. See exception logs above.
I/flutter (15285):   The test description was: Listview.builder scroll test
I/flutter (15285):   
I/flutter (15285): 00:02 +0 -1: (tearDownAll)
W/ntegration_tes(15285): Accessing hidden method Lsun/misc/Unsafe;->compareAndSwapObject(Ljava/lang/Object;JLjava/lang/Object;Ljava/lang/Object;)Z (greylist,
linking, allowed)
I/flutter (15285): 00:02 +1 -1: Some tests failed.
Failure Details:
Failure in method: Listview.builder scroll test
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞═════════════════
The following _CastError was thrown running a test:
type 'ListView' is not a subtype of type 'Scrollable' in type
cast

When the exception was thrown, this was the stack:
#0      WidgetController.widget (package:flutter_test/src/controller.dart:67:44)
#1      WidgetController.scrollUntilVisible.<anonymous closure> (package:flutter_test/src/controller.dart:1139:15)
#2      WidgetController.scrollUntilVisible.<anonymous closure> (package:flutter_test/src/controller.dart:1137:39)
#5      TestAsyncUtils.guard (package:flutter_test/src/test_async_utils.dart:71:41)
#6      WidgetController.scrollUntilVisible (package:flutter_test/src/controller.dart:1137:27)
#7      main.<anonymous closure> (file:///Users/xenlabs/Documents/Nikhil/Trial_Apps/sample_integration_test/integration_test/app_test.dart:26:20)
<asynchronous suspension>
<asynchronous suspension>
(elided 3 frames from dart:async and package:stack_trace)

The test description was:
  Listview.builder scroll test
═════════════════════════════════════════════════════════════════

end of failure 1

```

<details>
  <summary>Logs</summary>

flutter doctor

```
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.2.0, on Mac OS X 10.15.7 19H1217 darwin-x64, locale en)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.2)
[✓] VS Code (version 1.57.0)
[✓] Connected device (3 available)

• No issues found!
```

</details>