google_places_suggestions_autocomplete_field 0.0.2 copy "google_places_suggestions_autocomplete_field: ^0.0.2" to clipboard
google_places_suggestions_autocomplete_field: ^0.0.2 copied to clipboard

A Flutter package that provides a customizable autocomplete text field for location search using the Google Places API.

example/lib/main.dart

import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:google_places_suggestions_autocomplete_field/google_places_suggestions_autocomplete_field.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: HomeScreen(),
    );
  }
}

class HomeScreen extends StatefulWidget {
  @override
  State<HomeScreen> createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  String? resultObject;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: [
          Container(
            margin: EdgeInsets.symmetric(vertical: 100, horizontal: 100),
            height: 50,
            width: 400,
            child: GooglePlacesSuggestionsAutoCompleteField(
              controller: TextEditingController(),
              googleAPIKey: "zyz",/// Replace with your Google Places API Key
              countries: "za,de", ///The countries for the predictions.
              onPlaceSelected: (place) {
                setState(() {
                  resultObject = jsonEncode(place.toJson());
                });
                debugPrint("place: ${jsonEncode(place.toJson())}");
              },
            ),
          ),
          resultObject != null ? Container(
              margin: EdgeInsets.symmetric(vertical: 100, horizontal: 100),
              child: Text("Returned Location: $resultObject")
          ) : Container()
        ],
      ),
    );
  }
}
1
likes
120
points
147
downloads

Publisher

verified publishertopcode.co.za

Weekly Downloads

A Flutter package that provides a customizable autocomplete text field for location search using the Google Places API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

collection, flutter, http, uuid

More

Packages that depend on google_places_suggestions_autocomplete_field