[英]Circular progress indicator not showing while using future builder
我是 flutter.i 的菜鳥。我試圖在單擊按鈕時顯示從 api 加載數據的循環進度。 我收到來自 api 的響應。 但我沒有進入未來建造者的快照公寓......
_onPressed(){
setState(() {
_textCCodeValues=myCCodeController.text;
_textPhoneNumberValues=myPhoneNumberController.text;
_textPasswordValues=myPasswordController.text;
log("mobile",name: _textCCodeValues+" "+_textPhoneNumberValues);
log("Password",name: _textPasswordValues);
requestMap={
'ccode':_textCCodeValues,
'mobile':_textPhoneNumberValues,
'password':_textPasswordValues,
'app_Version':"1.1",
};
//_isOtpFieldVisible =!_isOtpFieldVisible;
requestJson=json.encode(requestMap);
//StringWidget(future: makeLoginRequest(requestJson));
//makeLoginRequest(requestJson);
});
FutureBuilder(
future: makeLoginRequest(requestJson),
builder: (BuildContext context,AsyncSnapshot snapshot){
_logData(snapshot.connectionState.toString());
if(snapshot.connectionState == ConnectionState.waiting){
_logData("in waiting");
return SpinKitRotatingCircle(
color: Colors.blue,
size: 50.0,
);
}
return null;
},
);
}
我正在使用的未來是
Future<String> makeLoginRequest(String requestJson) async{
final uri = url;
final headers = {
'Content-Type': 'application/json',
"Accept": "application/json",
};
var response=await post(
uri,
headers:headers,
body: requestJson,
);
print("${response.body}");
return response.toString();
}
我不知道出了什么問題。 請有人幫助我。
只需嘗試更改您的代碼,例如,
FutureBuilder(
future: makeLoginRequest(requestJson),
builder: (BuildContext context,AsyncSnapshot snapshot){
if (snapshot.hasData) {
return Text("Data");
} else if(snapshot.hasError) {
return Text("Error");
} else {
return SpinKitRotatingCircle(
color: Colors.blue,
size: 50.0,
);
}
},
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.