Rahul Dole
Rahul Dole

Reputation: 3093

Writing flutter test involving selecting a dropdown menu item

I'm writing a flutter test that involves selecting a dropdown menu item from a DropdownButtonFormField. After I tap the dropdown and then try to tap on one of the menu items, it selects a particular item always, not the one I want. Suppose the dropdown has 3 items, like so: ['Item A', 'Item B', 'Item C']

await tester.tap(find.byKey(ValueKey("dropdown_key")));
await tester.pump();
await tester.tap(find.text('Item A'));
await tester.pump();

It will select Item B always. What's missing?

Upvotes: 2

Views: 1636

Answers (1)

James Lewis
James Lewis

Reputation: 41

This is what im doing and works like a treat!

// First select the drop down box
await tester.tap(find.text('Vehicle type *'));
await tester.pumpAndSettle();
// Then select the value in it
await tester.tap(find.text('Car').first);
await tester.pumpAndSettle();

Upvotes: 4

Related Questions