我正在尝试通过Text
点击打开一个URL。为此,我正在使用InkWell
,如下所示:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('${blogModel.timeElapsed} ago'),
InkWell(
child: Text('Read'),
onTap: launchURL(blogModel.url),
)
],
)
使用此错误信息:
════════ 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
答案 0 :(得分:4)
您的launchURL(blogModel.url)
呼叫返回Future
,而onTap
需要一个void
。
有2种解决方案可以解决此问题。
onTap: () => launchURL(blogModel.url),
onTap: () {
launchURL(blogModel.url); // here you can also use async-await
}
答案 1 :(得分:0)
这正是警察解决问题的方式;如果你调用一个方法,你应该像这样构造它:
之前
onPressed: authBloc.logout()
之后:
onPressed: ()=>authBloc.logout()