I have an issue with trying to test Share package. My code looks like this:
IconButton(
key: Key('share-button'),
icon: Icon(Platform.isAndroid ? Icons.share : CupertinoIcons.share),
onPressed: () {
if (activity.shareLink != null) {
Share.share('${activity.shareLink}');
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Request Error'),
),
);
}
},
)
I provided [activity.shareLink] and my test looks like this:
await tester.tap(find.byKey(Key('share-button')));
await tester.pump(Duration(seconds: 1));
expect(find.byType(Share), findsOneWidget);
And my exception is:
══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
The following TestFailure object was thrown running a test:
Expected: exactly one matching node in the widget tree
Actual: _WidgetTypeFinder:<zero widgets with type "Share" (ignoring offstage widgets)>
Which: means none were found but one was expected