autocomplete_google_places_widget 0.0.1 copy "autocomplete_google_places_widget: ^0.0.1" to clipboard
autocomplete_google_places_widget: ^0.0.1 copied to clipboard

A wrapper around Flutter's default Autocomplete widget that leverages the Google Places API to provide real-time place suggestions as users type

example/lib/main.dart

import 'dart:developer';

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

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

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Google Places Autocomplete Demo',
      home: MyHomePage(
        title: 'Google Places Autocomplete Demo',
      ),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _yourGoogleAPIKey = ''; // fill with your Google API Key

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => FocusManager.instance.primaryFocus?.unfocus(),
      child: Scaffold(
        appBar: AppBar(
          title: Text(widget.title),
        ),
        body: Padding(
          padding: const EdgeInsets.all(16.0),
          child: Center(
              child: GPlacesAutoComplete(
            googleAPIKey: _yourGoogleAPIKey,
            countries: const ['FR'],
            onOptionSelected: (p0) => log('onItemSelected: ${p0.description}'),
            enableHistory: true,
            liteModeHistory: true,
            menuBorderRadius: 25,
            fieldDecorationBuilder: (a, b) {
              return InputDecoration(
                hintText: 'e.g. Paris, France',
                labelText: 'Search for a place',
                prefixIcon: const Icon(Icons.search),
                errorMaxLines: 2,
                fillColor: const Color.fromARGB(125, 162, 177, 255),
                filled: true,
                focusedBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(12.0),
                  borderSide: const BorderSide(
                    color: Color.fromARGB(255, 162, 177, 255),
                    width: 2,
                  ),
                ),
                border: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(12.0),
                  borderSide: const BorderSide(
                    color: Colors.white,
                    width: 2,
                  ),
                ),
                enabledBorder: OutlineInputBorder(
                  borderRadius: BorderRadius.circular(12.0),
                  borderSide: const BorderSide(
                    color: Colors.white,
                    width: 2,
                  ),
                ),
              );
            },
            menuColor: const Color.fromARGB(255, 162, 177, 255),
            menuOptionBuilder: (context, index, prediction) => ListTile(
                leading: Text(emojis[index],
                    style: const TextStyle(
                        fontSize: 24, fontWeight: FontWeight.w100)),
                title: Text(
                  prediction.description ?? '',
                  style: const TextStyle(
                      color: Colors.white, fontWeight: FontWeight.w300),
                ),
                trailing: const Icon(
                  Icons.arrow_forward_ios,
                  color: Colors.white,
                  size: 12,
                )),
          )),
        ),
      ),
    );
  }

  List<String> emojis = ['👋', '🌍', '🌞', '🌜', '🌟'];
}
3
likes
0
pub points
22%
popularity

Publisher

verified publisherdhia.tech

A wrapper around Flutter's default Autocomplete widget that leverages the Google Places API to provide real-time place suggestions as users type

Repository (GitHub)
View/report issues

Topics

#autocomplete #google-places

License

unknown (license)

Dependencies

dio, flutter, shared_preferences, uuid

More

Packages that depend on autocomplete_google_places_widget