Reputation: 5997
I'd like to select an entry from a DropdownButton in a form. I managed to tap on the button using the following:
await driver.tap(find.byValueKey('object_type'));
How can I find an entry now? The DropdownMenuItem entries are dynamically generated using values from a database. I think it's kind of awkward setting a key for each value, so I tried the following:
await driver.tap(find.byValueKey('object_type'));
await driver.waitFor(find.text('Car'));
await driver.tap(find.text('Car'));
However, this doesn't work as I get a timeout.
Upvotes: 0
Views: 3178
Reputation: 602
I am also faced the same issue, But I was able to resolve issue using below code
final drop = find.byValueKey('object_type');
// First, tap the dropdown button.
await driver.tap(drop);
await driver.tap(find.text('Car'));
expect(await driver.getText(find.text('Car')), isNotNull);
Suppose dropdown has large set of data then we need to scroll down the dropdown and search for the expected value.
final SerializableFinder dropFinder = find.byValueKey('object_type');
await driver.scroll(dropFinder , 0, -200, Duration(milliseconds: 3000));
await driver.tap(find.text('Car'));
expect(await driver.getText(find.text('Car')), isNotNull);
Upvotes: 1