Reputation: 11198
I am trying to open a URL on a Text
click. For this I am using InkWell
as shown below:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('${blogModel.timeElapsed} ago'),
InkWell(
child: Text('Read'),
onTap: launchURL(blogModel.url),
)
],
)
Using this I am getting following error:
════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building BlogTileWidget(dirty):
type 'Future<dynamic>' is not a subtype of type '() => void'
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
https://github.com/flutter/flutter/issues/new?template=BUG.md
Upvotes: 37
Views: 37739
Reputation: 627
It's exactly how cops solve it; if you are calling a method instead you should construct it like this:
before
onPressed: authBloc.logout()
after:
onPressed: ()=>authBloc.logout()
Upvotes: 6
Reputation: 267404
Your launchURL(blogModel.url)
call returns Future
, and onTap
needs a void
.
There are 2 solutions to fix this problem.
onTap: () => launchURL(blogModel.url),
onTap: () {
launchURL(blogModel.url); // here you can also use async-await
}
Upvotes: 105