awesome_place_search 2.1.0 copy "awesome_place_search: ^2.1.0" to clipboard
awesome_place_search: ^2.1.0 copied to clipboard

Flutter library that provides a user interface for searching places using the Google Places API.

Awesome Place Search #

Description #

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

Features #

  • Customizable UI for the place search dialog.
  • Support for loading and error states.
  • Customizable styles and decorations for the search input field and result items.
  • Optional country filtering for place search results.
  • Customizable search hint and error messages.
  • Various customization options for look and feel.

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 #

  • apiKey: Your API key for the place search service.
  • context: The build context for the widget, used to show the search modal.
  • onTap: Callback function triggered when a place is selected. Receives a Future that resolves to a PredictionModel.

Optional Parameters #

  • hint: Hint text to show in the search input field. (Default: "Search places...")
  • errorText: Text to display when an error occurs during the search. (Default: "An error occurred. Please try again.")
  • modalBorderRadius: Border radius for the search modal. (Default: 12.0)
  • loadingWidget: Custom widget to display while loading search results. (Default: CircularProgressIndicator())
  • searchTextFieldDecoration: Decoration for the search input field. (Default: InputDecoration() with default settings)
  • dividerItemColor: Color for the divider between search results. (Default: Colors.grey)
  • dividerItemWidth: Width for the divider between search results. (Default: 1.0)
  • placeIconWidget: Custom widget for the place icon in the search results. (Default: Icon(Icons.place))
  • onErrorWidget: Custom widget to display when an error occurs. (Default: Text(errorText))
  • elevation: Elevation for the search modal. (Default: 4.0)
  • countries: List of country codes to restrict the search results. (Default: [] - No restriction)
  • indicatorColor: Color for the loading indicator. (Default: Theme's primary color)
  • subtitleStyle: Text style for the subtitle in the search results. (Default: TextStyle() with default settings)
  • invalidKeyWidget: Custom widget to display when the API key is invalid. (Default: Text("Invalid API key"))
  • titleStyle: Text style for the title in the search results. (Default: TextStyle() with default settings)
  • autofocus: Allows the search field to automatically gain focus when displayed, enhancing user experience by anticipating their intent to start searching immediately, without needing extra interaction to focus on the field

Demo #

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

19
likes
140
points
133
downloads

Publisher

verified publisherloritotiago.pro

Weekly Downloads

Flutter library that provides a user interface for searching places using the Google Places API.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

dartz, flutter, http

More

Packages that depend on awesome_place_search