flutter_google_places just loading & not show the result

Issue

I try using flutter_google_places: ^0.3.0 to autocomplete google search location, but the output just only loading not showing the location result.

here my code,

maps-example.dart

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
import 'package:location/location.dart' as Loc;
import 'package:geocoding/geocoding.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_maps_webservice/places.dart';

const kGoogleApiKey = "YourAPIKEY";
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);

class MapScreen extends StatefulWidget {
  static const String routeName = '/maps';

  const MapScreen({Key? key}) : super(key: key);

  @override
  _MapScreenState createState() => _MapScreenState();
}

class _MapScreenState extends State<MapScreen> {

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Stack(
        children: <Widget>[
          RaisedButton(
            onPressed: () async {
              Prediction? p = await PlacesAutocomplete.show(
                context: context,
                apiKey: kGoogleApiKey,
                mode: Mode.overlay,
                radius: 10000000,
                types: [],
                strictbounds: false,
                decoration: InputDecoration(
                  hintText: 'Search Location',
                  focusedBorder: OutlineInputBorder(
                    borderRadius: BorderRadius.circular(20),
                    borderSide: BorderSide(
                      color: Colors.white,
                    ),
                  ),
                ),
              );
            },
          )
        ],
      ),
    );
  }
}

i already check my api key was not restrict but still happen like this.

here my output

enter image description here

thanks for your reply 🙂

Solution

if your billing its activate on Google APIS try adding components

   Prediction? p =
                                        await PlacesAutocomplete.show(
                                            context: context,
                                            radius: 10000000,
                                            types: [],
                                            logo: const SizedBox.shrink(),
                                            strictbounds: false,
                                            mode: Mode.overlay,
                                            language: "fr",
                                            components: [ //add this 
                                              Component(
                                                  Component.country, "fr"),
                                              Component(
                                                  Component.country, "in"),
                                              Component(Component.country, "UK")
                                            ],
                                            apiKey: kGoogleApiKey);

Answered By – Ashutosh singh

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.