【发布时间】:2021-02-23 11:47:32
【问题描述】:
我已经为网络应用构建了我的第一个 Flutter。这是我的相关代码:
String status='Starting...';
CPConstructor () {
downloadMenu();
}
void changeStatus ( String status) {
this.status = status;
notifyListeners();
}
void downloadMenu () async {
try {
var getRestDetailsURL = "some Api URL";
var getMenuDataURL = 'some Api URL';
changeStatus("Connecting...");
http.Response response1 = await http.post(getRestDetailsURL, body: {'res_key': resKey, 'auth_key': authKey}).timeout(Duration(seconds: 1), onTimeout: (){
changeStatus("Connection timeout...\n Please refresh the page.");
return;
});
changeStatus("Downloading latest menu..."); // Getting STUCK here
http.Response response2 = await http.post(getMenuDataURL, body: {'res_key': resKey, 'auth_key': authKey}).timeout(Duration(seconds: 1),onTimeout: (){
changeStatus("Please refresh the page...");
return;
});
debugPrint('Response status: ${response1.statusCode}');
// Sometimes throwing exception for undefined object for response1??????
debugPrint('Response body: ${response1.body}', wrapWidth:1024);
debugPrint('Response status: ${response2.statusCode}');
debugPrint('Response body: ${response2.body}', wrapWidth:1024);
dataLoaded = true;
notifyListeners();
trialCounter=0;
return;
} on TimeoutException catch(e){
print(e);
trialCounter++;
if (trialCounter<3) downloadMenu();
return;
}
}
问题
它在本地主机上运行良好。但是当我部署到 Firebase 托管时,它就卡在了
http.Response response2 = await http.post(getMenuDataURL, body...
与 有时它会在以下语句中将 response1 作为未定义对象抛出异常:
debugPrint('Response status: ${response1.statusCode}');
不确定发生了什么,需要一些帮助。
【问题讨论】:
-
对于托管站点来说,超时时间太短了 1 秒。可能在本地运行良好,但托管时可能会导致错误。
-
从 1 变成 5,还是一样的问题。
标签: firebase flutter flutter-layout firebase-hosting flutter-web