'ListView in integration test (Flutter)
I haven't found a complex examples for testing ListViews. Example.
I have a ListView, which has three objects Person.
Person{
String name;
String surname;
}
In UI, Person is wrapped in Column, giving them two Text Widgets for name and surname.
I click on FAB. Clicking on FAB adds new Person with name Tom and surname Thomson to the ListView. Now there are 4 objects of Person. And I know data of the last one.
How can I validate, that item was successfully added? Is there a way to check length/count of ListView?
Is there a way to validate last added item params?
Appreciate!
Solution 1:[1]
widgetList provides a matching widget in the tree, just need to mention key of Listview which required to test.
final count = tester
.widgetList<ListView>(find.byKey(ValueKey("ListViewKey")))
.length;
Solution 2:[2]
I add my ListTile titles with a unique key (ex. 'tile_surname_#'). Assuming your ListView is built with an array of Person objects called persons, you can try something like:
final String valueKey = 'tile_$newPerson.surname_${persons.length}';
final newPersonFinder = find.byValueKey(valueKey);
expect(
await driver.getText(newPersonFinder), valueKey
);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jitesh Mohite |
| Solution 2 | btdtphx |
