在我的 Flutter-Web 应用程序中,我试图使用 flutter_google_places 包获取地址。我正在尝试使用简单的代码来获取自动完成地址字段(MyTextField 只是一个自定义的文本字段):
final addressField = MyTextField(
controller: _addressController,
labelText: 'Indirizzo',
readOnly: true,
onTap: () async {
await PlacesAutocomplete.show(
context: context,
apiKey: kGoogleApiKey,
mode: Mode.overlay,
onError: (error){print('ERROR: $error');},
);
},
);
Run Code Online (Sandbox Code Playgroud)
当我运行应用程序并向该字段插入一些内容时,我没有得到任何结果。但是我收到此错误(从主机上的检查控制台捕获,并且我在本地也收到相同的错误):
Access to XMLHttpRequest at 'https://maps.googleapis.com/maps/api/place/autocomplete/json?input=h&key=**MY-API-KEY**' from origin 'https://**MY-HOSTING**.firebaseapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
我读到这是一个服务器端问题,我尝试像这样修改 firebase.json:
{
"hosting": {
"public": "build/web",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
],
"rewrites": [
{
"source": "**",
"destination": "/index.html"
}
], …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 setState 更改事件(例如按钮按下)上的 DropdownButtonFormField 值。但它不起作用。
注意:它适用于我使用 DropdownButton 的情况,但使用 DropdownButtonFormField 时它没有响应。
这是一个简单的代码,显示了我正在尝试实现的内容。
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Testing(),
);
}
}
class Testing extends StatefulWidget {
@override
_TestingState createState() => _TestingState();
}
class _TestingState extends State<Testing> {
String selectedValue;
@override
Widget build(BuildContext context) {
return Material(
child: Column(
children: <Widget>[
DropdownButtonFormField(
value: selectedValue,
items: ['one', 'two'].map((value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
); …Run Code Online (Sandbox Code Playgroud)