Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - how to get widget count on integration test

how can i get the widget count

final SerializableFinder finder = find.byType('MyWidget');
await driver.tap(finder);

but MyWidget may be more than one,
that will throw exception

like image 586
Water Magical Avatar asked Jun 27 '19 14:06

Water Magical


Video Answer


1 Answers

You will need to use some attribute that allows you to find the widget you need. For example, add a Key to each of these widgets, so it's easier to find the one you need:

...MyWidget(key: Key('myWidget1'))...

So, find it by key:

find.byKey(Key('myWidget1'))

If you want to find the widget count, you can use this:

final finder = find.byType(MyWidget, skipOffstage: false); // Without quotes!
final count = tester.widgetList<MyWidget>(finder).length;
like image 131
Luciano Avatar answered Nov 27 '22 11:11

Luciano