带有 Flutter Google 的文本表单字段放置自动完成返回错误

Text Form Field with Flutter Google Places Auto Complete returning error

我正在构建一个 Flutter 应用程序,并尝试添加一个带有 Google Places Auto Complete API 的文本表单字段,但是当我尝试构建该应用程序时,它 returns我出错了,我无法修复它。

我有这个代码:

import 'package:google_maps_webservice/places.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_api_headers/google_api_headers.dart';
import 'dart:async';

const kGoogleApiKey = "API_KEY";
String address = '';

Future<Null> displayPrediction(Prediction p) async {
    if (p != null) {
      GoogleMapsPlaces _places = GoogleMapsPlaces(
        apiKey: kGoogleApiKey,
        apiHeaders: await GoogleApiHeaders().getHeaders(),
      );

      PlacesDetailsResponse detail =
          await _places.getDetailsByPlaceId(p.placeId);

      var placeId = p.placeId;
      double lat = detail.result.geometry.location.lat;
      double lng = detail.result.geometry.location.lng;

      var address = detail.result.formattedAddress;
    }
  }

TextFormField(
                            decoration: textInputDecoration.copyWith(
                              hintText: "Enter Company Address",
                              prefixIcon: Icon(Icons.map),
                            ),
                            onTap: () async {
                              Prediction p = await PlacesAutocomplete.show(
                                  context: context, apiKey: kGoogleApiKey);
                              displayPrediction(p);
                            },
                            validator: (val) =>
                                val.isEmpty ? 'Enter address' : null),

当我尝试构建项目时,returns 出现以下错误:

../../Developer/flutter/.pub-cache/hosted/pub.dartlang.org/google_maps_webservice-0.0.19/lib/src/utils.dart:61:27: Error: The argument type 'String' can't be assigned to the parameter type 'Uri'.
 - 'Uri' is from 'dart:core'.
    return httpClient.get(url, headers: headers);

我找不到问题

经过研究,我发现问题出在google_maps_webservice-0.0.19插件中。在 0.0.19 版本中,他们将 String 传递给 Uri 并抛出异常。

问题已打开:Issue

如何解决这个问题:

1.You 可以请他们解决这个问题。

  1. 您可以将 google_maps_webservice 插件更新为 google_maps_webservice 0.0.20-nullsafety.3

  1. 您可以分叉他们的存储库,解决该错误并在您的项目中使用分叉和解析的 github 存储库