Awesome Place Search

描述

awesome_place_search 包是一个 Flutter 库,它提供了一个使用 Google Places API 搜索位置的用户界面。使用此包,您可以轻松实现一个位置搜索栏,该搜索栏会在用户键入时显示建议。

安装

添加 pubspec.yaml

dependencies:
  awesome_place_search: ^1.0.6

基础

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,
        key: "Your Google map key", //Insert Your google Api Key
        onTap: (value) async {
           final result = await value;
           setState(() {
                prediction=result;
            });
        },
     ).show();
  }
}

维护者

演示

Awesome Place Search Demo

GitHub

查看 Github