适用于 Android、iOS、Web、macOS、Windows 和 Linux 上的 Flutter 应用的可自定义 Google 地点自动补全小部件。它允许用户通过 Google 地点 API 提供的实时建议搜索地点。该包简化了在表单或地图中集成地点选择的过程,为跨平台提供无缝体验。开发者可以自定义外观、处理地点选择并高效管理位置查询。非常适合需要地址输入、基于位置的服务或地理编码功能的应用程序。
GooglePlaceAutoCompleteTextField(
textEditingController: controller,
googleAPIKey: "YOUR_GOOGLE_API_KEY",
inputDecoration: InputDecoration()
debounceTime: 800// default 600 ms,
countries: ["in","fr"],// optional by default null is set
isLatLngRequired:true,// if you required coordinates from place detail
getPlaceDetailWithLatLng: (Prediction prediction) {
// this method will return latlng with place detailprint("placeDetails" + prediction.lng.toString());
}, // this callback is called when isLatLngRequired is true
itemClick: (Prediction prediction) {
controller.text=prediction.description;
controller.selection = TextSelection.fromPosition(TextPosition(offset: prediction.description.length));
}
// if we want to make custom list item builder
itemBuilder: (context, index, Prediction prediction) {
returnContainer(
padding: EdgeInsets.all(10),
child: Row(
children: [
Icon(Icons.location_on),
SizedBox(
width: 7,
),
Expanded(child: Text("${prediction.description??""}"))
],
),
);
}
// if you want to add seperator between list items
seperatedBuilder: Divider(),
// want to show close icon
isCrossBtnShown: true,
// optional container padding
containerHorizontalPadding: 10,
// place type
placeType: PlaceType.geocode,
// keyboard type (defaults to TextInputType.streetAddress)
keyboardType: TextInputType.text, // optional - defaults to streetAddress for better address input
)
Customization Option
You can customize a text field input decoration and debounce time