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
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
}
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With