本文介绍了输入“未来<动态>"不是类型 '() => 的子类型空白'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 Text 点击时打开一个 URL.为此,我使用 InkWell 如下所示:

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

推荐答案

你的 launchURL(blogModel.url) 调用返回 FutureonTap 需要一个 void.

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
    }
    

  • 这篇关于输入“未来&lt;动态&gt;"不是类型 '() =&gt; 的子类型空白'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    07-22 20:33