【问题标题】:bad import of http on flutter for web在 web 上 Flutter 上的 http 导入错误
【发布时间】:2020-05-26 09:48:48
【问题描述】:

我试图向服务器发出 http 请求,但是当我导入包 http 时,vs 代码会打印下一个错误:

Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).

Please check the following imports:

`import 'package:http/http.dart' as http;` from fcfm_pa|lib/src/pages/registro_page.dart at 5:1

有人知道发生了什么吗?

【问题讨论】:

  • 我能够解决此问题的最简单方法是从测试版频道更改为主频道。我建议任何面临这个问题的人也这样做。

标签: http flutter flutter-dependencies flutter-web


【解决方案1】:

您应该使用以下库声明更新您的 pubspec.yaml 文件:

dependencies:
  http: ^0.12.0+4

然后导入库。完成后,请确保在终端上执行:

flutter pub get

甚至可能是flutter clean 以确保您拥有正确的一切。进行新的构建,您应该一切顺利。

【讨论】:

  • 现在我收到下一个错误“无法为 Web 构建应用程序。”
  • 你能在你的答案上加上你的“flutter doctor -v”吗?这样我们就可以知道您的具体版本等
【解决方案2】:

如果您使用的是 Beta 通道,则会出现此问题。

尝试flutter channel master,然后再次运行应用程序,此问题应该不会再出现了。

【讨论】:

    猜你喜欢
    • 2022-01-07
    • 2020-05-15
    • 2019-04-26
    • 2022-08-20
    • 2021-08-24
    • 1970-01-01
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多