我试图在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
您的LaunchURL(blogModel. url)
调用返回Future
,而onTap
需要一个void
。
有两种解决方案可以解决此问题。
onTap: () => launchURL(blogModel.url),
onTap: () {
launchURL(blogModel.url); // here you can also use async-await
}
这正是警察解决它的方式;如果你正在调用一个方法,你应该像这样构造它:
在onP的之前:autBlock. logout()
之后:onP的:()=