1

I failed to apply the Handle scrolling documentation with widget DropdownButton and DropdownButtonFormField.

I attempted to create a list of 10 000 strings, scroll to find the 750th and tap it. The test generates a warning message on the final tap: "A call to tap()...that would not hit...Maybe the widget is actually off-screen, or another widget is obscuring it, or the widget cannot receive pointer events."

Somehow the test says that it passes which is very diturbing.

Any help would be very appreciated.

Here is the code I used for the widget:

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    const title = 'Long List';
    // Generate a list of "Item 1" ... "Item 10000"
    List<String> items =  List<String>.generate(10000, (i) => "Item $i");
    return MaterialApp(
      title: title,
      home: Scaffold(
        body: buildListView(items),
      ),
    );
  }

  DropdownButton buildListView(List<String> items) {
    // Flutter documentation implementation https://api.flutter.dev/flutter/material/DropdownButton-class.html
    return DropdownButton(
      items: items.map<DropdownMenuItem<String>>((String value) {
        return DropdownMenuItem<String>(
          value: value,
          child: Text(value),
        );
      }).toList(),
      onChanged: (value) {},
    );
  }
}

And the "passing" test:

testWidgets('Counter increments smoke test', (WidgetTester tester) async {
  // Build our app and trigger a frame.
  await tester.pumpWidget(MyApp());

  // Find the list
  final listFinder = find.byType(Scrollable);
  // Item searched from list
  final itemFinder = find.text('Item 750');

  // Open the list
  await tester.tap(find.byType(DropdownButton<dynamic>));
  await tester.pumpAndSettle();

  // Scroll until the item to be found appears.
  await tester.scrollUntilVisible(
    itemFinder,
    500.0,
    scrollable: listFinder,
    maxScrolls: 100
  );
  await tester.pumpAndSettle();

  // Tap the value generates warning "A call to tap()...that would not hit..."
  await tester.tap(itemFinder);
  await tester.pumpAndSettle();

  // But finding the value passes ?...
  expect(itemFinder, findsOneWidget);
});
L. REUS
  • 13
  • 5

0 Answers0