ios - Flutter 自动完成谷歌地方表格
问题描述
我想在我的文本表单字段中实现一个自动完成的谷歌位置。但是我有以下我无法理解的内容。无法识别 Google 地方信息并且迟到被标记为文本。如果有人可以帮助我,那就太好了。先感谢您。我实际上有这个问题:
第一个错误:没有为类型“_RegisterScreen2State”定义方法“GoogleMapPlaces”。第二个错误:意外的文本“迟到”。
您可以在下面添加的我的图片中看到两个标记为红色的错误
**我正在使用最后一个颤振版本,flutter_google_places:^0.3.0 和地理编码器:^0.2.1
enum MobileVerificationState {
SHOW_MOBILE_FORM_STATE, // The user provides the phone number
SHOW_OTP_FORM_STATE // The user has to enter the code he received
}
class RegisterScreen2 extends StatefulWidget {
final UsersInformations user;
const RegisterScreen2(this.user);
@override
_RegisterScreen2State createState() => _RegisterScreen2State();
}
class _RegisterScreen2State extends State<RegisterScreen2> {
@override
void initState(){
super.initState();
_places = GoogleMapPlaces(apiKey: kGoogleApiKey);
}
final kGoogleApiKey = "MY IPA KEY";
late GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);
.....
getMobileFormWidget(context, user) {
return Scaffold(
backgroundColor: Colors.white,
body: Form(
child: SingleChildScrollView(
child: Column(
children: [
Stack(
children: [
Container(
height: 100,
decoration: BoxDecoration(
color: Colors.green.shade50,
borderRadius: const BorderRadius.only(
bottomLeft: Radius.circular(30),
bottomRight: Radius.circular(30))),
),
Padding(
padding: const EdgeInsets.only(top: 70),
child: Stack(
// ignore: prefer_const_literals_to_create_immutables
children: [
Center(
child: CircleAvatar(
radius: 60,
backgroundColor: Colors.white,
backgroundImage: image != null
? FileImage(image)
: const NetworkImage(
"https://cdn-icons-png.flaticon.com/512/1177/1177568.png"),
),
),
Positioned(
bottom: -5,
right: 145,
child: InkWell(
onTap: () => getImage(),
child: Icon(Icons.camera_alt_rounded)))
],
),
),
],
),
const SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.all(10.0),
child: Padding(
padding: EdgeInsets.only(left: 15, right: 15, top: 5),
child: TextFormField(
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey.shade300)),
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.deepPurple.shade900)),
focusedErrorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red.shade900)),
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.red.shade900)),
hintText: "Adresse",
),
onChanged: (val) async {
Prediction p = await PlacesAutocomplete.show(
context: context,
apiKey: kGoogleApiKey,
mode: Mode.overlay, // Mode.fullscreen
language: "fr",
components: [
new Component(Component.country, "fr"),
]);
displayPrediction(p);
user.setAdress = val;
},
),
),
),
……
Future<Null> displayPrediction(Prediction p) async {
if (p != null) {
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(p.placeId);
var placeId = p.placeId;
double lat = detail.result.geometry.location.lat;
double lng = detail.result.geometry.location.lng;
var address = await Geocoder.local.findAddressesFromQuery(p.description);
print(lat);
print(lng);
}
}
}
解决方案
第一个错误是一个错字,你写GoogleMapPlaces
的不是GoogleMapsPlaces
.
然后,您可以执行以下两项操作之一,具体取决于您是否已迁移到 dart 2.13。
late GoogleMapsPlaces _places = ....
将您的行更改为以下之一:
如果你有零安全
late GoogleMapsPlaces _places;
如果您没有零安全性
GoogleMapsPlaces _places;
这应该可以解决您的两个错误。
推荐阅读
- javascript - 如何在 Sapper 上使用 worker_threads?
- matlab - matlab中的采样率
- javascript - 如何在图像上方带有文本段落的鼠标移除后使图像上的 CSS 过渡返回到初始状态
- python - style.format() 和十进制列的问题
- c# - 如何授予用户访问权限以使用 c# 编辑注册表
- c# - 在 ASP.NET Core 应用程序中运行多个端点
- python - 在 While 循环中使用多个 If 语句
- swiftui - 在环境中存储一个模拟对象
- python - 如何在一个函数中休眠而不休眠整个程序
- javascript - 节点:TypeError:无法读取未定义的属性“替换”