LoritoTiago / awesome_place_search

The awesome_place_search package is a Flutter library that provides a user interface for searching places using the Google Places API. With this package, you can easily implement a location search bar that shows suggestions as the user types.
MIT License
6 stars 7 forks source link

Awesome Place Search

Description

awesome_place_search is a Flutter package for integrating place search functionality in your application using a custom API.

Features

Installation

Add pubspec.yaml

dependencies:
  awesome_place_search: ^2.1.0

Basic

import 'package:flutter/material.dart';

import 'package:awesome_place_search/awesome_place_search.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {

  PredictionModel? prediction;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Welcome to Flutter'),
        ),
        body: Center(
          child: Text(prediction.description??"Prediction is null")
        ),
        floatingActionButton: FloatingActionButton(
            onPressed: () {
                _searchPlaces();
            },
            child: const Icon(Icons.add,
        ),
      ),
      ),

    );
  }

  void _searchPlaces(){
     AwesomePlaceSearch(
            context: context,
            apiKey: "Your Google Map Key",
            countries: ["ao", "pt"],
            dividerItemColor: Colors.grey.withOpacity(.5),
            dividerItemWidth: .5,
            elevation: 5,
            indicatorColor: Colors.blue,
            modalBorderRadius: 50.0,
            onTap: (value) async {
               result = await value;

              setState(() {
                prediction = result;
              });
            },
          ).show();
  }
}

Parameters:

Required Parameters

Optional Parameters


Demo

Simulator Screen Recording - iPhone 15 Pro - 2024-06-17 at 11 32 46