Using package:flutter_test, I can create a finder that finds widgets with a key:
expect(find.byKey(const ValueKey('counter')), findsOneWidget);
or by text:
expect(find.text('0'), findsOneWidget);
I can also find widgets descending from this widget:
expect(
find.descendant(
of: find.byKey(const ValueKey('counter')),
matching: find.text('0'),
),
findsNothing,
);
Or an ancestor:
expect(
find.ancestor(
of: find.text('0'),
matching: find.byKey(const ValueKey('counter')),
),
findsNothing,
);
But how do I combine these finders to verify that there is a widget with a 'counter' Key and with '0' as its text? For example:
Text(
'$_counter',
key: const Key('counter'),
style: Theme.of(context).textTheme.headline4,
),