【问题标题】:How to fix Future<dynamic> is not a subtype of type in Flutter如何修复 Future<dynamic> 不是 Flutter 中类型的子类型
【发布时间】:2021-06-20 07:40:58
【问题描述】:

我收到“type 'Futture' is not a subtype of type '() => void'”错误,我只是想知道如何解决这个错误。任何建议或帮助都会非常感激。


                      GestureDetector(
                        onTap: _launchURL(),
                        child: Text(
                          'maxis@gm.com',
                          style: TextStyle(
                              fontSize: 16,
                              color: Theme.of(context).indicatorColor),
                        ),
                      ),



  _launchURL() async {
    final url =
        Uri.encodeFull('mailto:smith@example.org?subject=News&body=New plugin');
    if (await canLaunch(url)) {
      await launch(url);
    } else {
      throw 'Could not launch $url';
    }
  }


``

【问题讨论】:

    标签: flutter dart flutter-layout flutter-dependencies flutter-web


    【解决方案1】:

    我不确定,但如果您尝试更新,也许可以

    _launchURL() async {
    

    到:

    void _launchURL() async {
    

    和

    onTap: _launchURL,
    

    更多详情,请查看link

    【讨论】:

      【解决方案2】:

      你需要在这里传递回调: 来自

      onTap: _launchURL(),
      

      到

      onTap: () => _launchURL(),
      // or
      onTap: () {
          _launchUrl();
      }
      

      【讨论】:

        猜你喜欢
        • 2019-08-04
        • 2021-02-10
        • 2020-12-09
        • 2019-12-05
        • 2019-08-18
        • 2023-03-30
        • 2021-09-18
        • 1970-01-01
        • 2021-02-06
        相关资源
        最近更新 更多