gpt4 book ai didi

flutter - 类型 'Future' 不是类型 '() => void' 的子类型

转载 作者:行者123 更新时间:2023-12-01 09:12:22 24 4
gpt4 key购买 nike

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

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

  • onTap: () => launchURL(blogModel.url),
  • onTap: () {
    launchURL(blogModel.url); // here you can also use async-await
    }
  • 关于flutter - 类型 'Future<dynamic>' 不是类型 '() => void' 的子类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57902284/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com