未处理的异常:类型 'String' 不是类型 'Uri' 的子类型

Unhandled Exception: type 'String' is not a subtype of type 'Uri'

我一直在做一个出租车克隆应用程序的 flutter 移动项目。我已将 Google 地图 API 用于地理编码和方向。我一直在关注 youtube 上的教程 (the link)。当我 运行 项目时,我没有得到任何数据并在控制台中看到这个错误

[ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: type 'String' is not a subtype of type 'Uri'

请帮帮我。我正在为一个学校项目做这件事

您可能使用了字符串(例如“https://yoursuperendpoint.com”)
并且您需要使用 URI:为此有一个特殊的 Uri class。

那里有文档:https://api.flutter.dev/flutter/dart-core/Uri-class.html

但您可能会使用 Uri.tryParse() 方法。

这很可能是由于 http package. Looking at the video tutorial, it appears that the teacher used http 0.12.2, while it seems that you are using a later version(0.13.0 or above). If you look at the changelog 的版本控制,您会看到关于 0.12.2 之后所做更改的注释:

Breaking All APIs which previously allowed a String or Uri to be passed now require a Uri.

要解决您的问题,您需要传递 Uri 而不是 String

var url = Uri.parse('https://example.com');