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!
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
);
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.