【发布时间】:2021-12-24 20:17:39
【问题描述】:
我正在从 codecanyon 定制 Flutter 电子商务移动应用。 如何将 onPressed 命令更改为一次自动工作的一次功能
onPressed: () async {
Position position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
await Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Map(
latitude: latitude == null
? position.latitude
: double.parse(latitude),
longitude: longitude == null
? position.longitude
: double.parse(longitude),
from: getTranslated(context, 'ADDADDRESS'),
)));
if (mounted) setState(() {});
List<Placemark> placemark = await placemarkFromCoordinates(
double.parse(latitude), double.parse(longitude));
state = placemark[0].administrativeArea;
country = placemark[0].country;
pincode = placemark[0].postalCode;
// address = placemark[0].name;
if (mounted)
setState(() {
countryC.text = country;
stateC.text = state;
pincodeC.text = pincode;
// addressC.text = address;
});
},
【问题讨论】:
-
“将自动工作一次”是什么意思?请你添加完整的代码吗?
-
你是想说它只能点击一次吗?
-
代码通过单击图标选择位置打开 google mab。而不是点击图标,我希望 mab 自动打开一次
-
只需将其设为函数并在 initState 中调用即可。