提问者:小点点

未来<动态>类型不是空类型 '() => 子类型


我试图在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

共2个答案

匿名用户

您的LaunchURL(blogModel. url)调用返回Future,而onTap需要一个void

有两种解决方案可以解决此问题。

  1. onTap: () => launchURL(blogModel.url),
    
    onTap: () {
      launchURL(blogModel.url); // here you can also use async-await
    }
    

匿名用户

这正是警察解决它的方式;如果你正在调用一个方法,你应该像这样构造它:

onP的之前:autBlock. logout()

之后:onP的:()=