搜索插件、代码仓与 APP 分类

插件详情v4.2.0

google_places_autocomplete_text_field

一个完全可自定义的 Google Places 自动完成 TextFormField,适用于 Flutter 的 iOS、Android 和 Web。

AndroidiOSmacOSWindowsLinux
近 30 天下载
3120
喜欢数
38
Pub 分数
160

安装插件

flutter pub add google_places_autocomplete_text_field

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个可自定义的 Flutter 文本字段,用于 Google 地点自动补全,支持 iOS、Android 和 Web 平台。它允许用户通过 Google 地点 API 提供的实时建议搜索并选择位置。该控件专为无缝集成到需要地址或位置输入的表单中而设计,提供灵活的样式和行为。非常适合需要从用户输入的地址获取准确地理定位数据的应用。

适合场景

  • 表单中的地址输入
  • 旅行应用中的位置选择
  • 收货地址输入
  • 基于地理位置的服务
  • 用户资料设置

主要特点

  • 实时地点建议
  • 可自定义的 UI 和样式
  • 跨平台支持(iOS、Android、Web)
  • 与 Google Places API 集成
  • 内置错误处理和验证

适合对象

  • 需要位置输入的移动和网络应用程序
  • 具有配送或地图功能的应用程序
  • 需要精确地址输入的表单
  • 使用 Google Places API 的开发人员
  • 优先考虑用户体验的自动补全项目

使用建议

  • 需要 Google Places API 密钥
  • 根据查询量可能会产生使用费用
  • 依赖互联网连接
  • 建议列表外观的自定义有限
  • 高负载期间响应时间可能存在延迟

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

google_places_autocomplete_text_field

This Flutter package helps you build a TextField that provides autocompletion suggestions from the new Google Places API.

Go check it out on pub.dev!

Add the dependency to pubspec.yml ➕

dependencies:
  flutter:
    sdk: flutter
  google_places_autocomplete_text_field: <last-version>

Integrate the Google AutoComplete TextField Widget in your code 🧩

    GooglePlacesAutoCompleteTextFormField(
        textEditingController: controller,
        config: const GoogleApiConfig(
          apiKey: 'YOUR_GOOGLE_API_KEY',
          // only needed if you build for the web
          proxyURL: 'https://your-proxy.com/',
          countries: ['de'], // optional, by default the list is empty (no restrictions)
          fetchPlaceDetailsWithCoordinates: true,  // if you require the coordinates from the place details
          debounceTime: 400, // defaults to 600 ms
          locationRestriction: LocationConfig.circle(
            circleCenter: const Coordinates(latitude: 52.5200, longitude: 13.4050),
            circleRadiusInKilometers: 1000,
          ), // either this or locationBias (or nothing)
          placeTypeRestriction: PlaceType.city, // if you want specific place types
        ),
        onPredictionWithCoordinatesReceived: (prediction) {
         // this method will return latlng with place detail
        print("Coordinates: (${prediction.lat},${prediction.lng})");
        // the place details are returned on the prediction as well
        print("Address: ${prediction.formattedAddress}");
        print("Components: ${prediction.addressComponents}");
        }, // this callback is called when fetchPlaceDetailsWithCoordinates is true
        onSuggestionClicked: (prediction) {
         controller.text = prediction.description;
          controller.selection = TextSelection.fromPosition(TextPosition(offset: prediction.description.length));
        }
    )

Integrate the Google AutoComplete TextField Widget in your Web code 🌐

In case you're building for the web, you need to pass the widget a proxy URL, otherwise you will receive a CORS-Error, as there are calls to the Google Maps API being made from the frontend. If you are not Google, your domain will probably be different, thus leading to the CORS-Error. If you are Google: how ya doin 😏? I'd love to do an internship.

Customization Option

You can customize the GooglePlacesAutoCompleteTextFormField as you would with any other TextFormField.

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目

暂无相关数据。