Water Magical
Water Magical

Reputation: 1179

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

Upvotes: 10

Views: 2851

Answers (1)

Luciano
Luciano

Reputation: 421

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;

Upvotes: 5

Related Questions