简体   繁体   中英

Text Form Field with Flutter Google Places Auto Complete returning error

I am building a Flutter app, and trying to add a Text Form Field with Google Places Auto Complete API, but when I try to build the application, it returns me an error, and I can't fix it.

I have this code:

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),

When I try to build the project, it returns me the following error:

../../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);

I can't find the problem

After having researched, I have found that problem is in google_maps_webservice-0.0.19 plugin. In 0.0.19 version, they passed String to Uri and it throw exception.

The issue has been opened: Issue

How to resolve this problem:

1.You can ask them to resolve this issue.

or

  1. You can update google_maps_webservice plugin to google_maps_webservice 0.0.20-nullsafety.3

or

  1. You can fork their repository, resolve that bugs and use your forked and resolved github repository in your project

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM