我需要使用await in字符串函数。我需要将一些字符串附加到简单的字符串,我一直在尝试,但没有用。SImilar场景如下所示:
String url = appendUrl();
appendUrl(){
String a = 'www.google.com';
String b = await getDeviceId(); // it gets device id from other packages
String c = a + '/?abc=' + b;
return c; // expected result => www.google.com/?abc=somedeviceid
}由于字符串将被返回,所以我不能将异步添加到appendUrl中,因此等待不能用于获取设备id。有什么办法可以做到这一点吗?
发布于 2021-02-03 17:41:52
您可以尝试使用then()代替async/await
appendUrl() {
String a = 'www.google.com';
getDeviceId().then((value) {
setState(() {
url = a + '/?abc=' + value;
});
});
}https://stackoverflow.com/questions/66024636
复制相似问题