[英].then code is ignored(not executing )in flutter
I have 3 functions我有3个功能
I have to execute these functions in the same order I have a code using.then after every function but.then part is not executing我必须按照我有一个代码使用的相同顺序执行这些函数。然后在每个 function 之后但是。然后部分不执行
after executing first function it avoids then part and goes to last line在执行第一个 function 之后,它避免了然后部分并转到最后一行
here is my function这是我的 function
void startElectionComplete() {
// the code to start election from adhar verification,register election and create election at blockchain
if (kDebugMode) {print('verifying adhar');}
getAdharVerified(adharTextController.text).then((value) => (){ //ADHAR VERIFICATION FUNCTION
showSnackBar(snackbarshow().succesAdharSnack);
if (kDebugMode) {print('adhar verified');}
if (_adharage > 18 && privateKeyTextController.text.isNotEmpty) { // CHECKING AGE FROM ADHAR
if (kDebugMode) {print('adhar verification complete');} // CHECKING WEATHER ELECTION DATES ARE GIVEN
if(unixlast != null &&unixlast.isNotEmpty){
if(unix !=null && unix.isNotEmpty){
if (kDebugMode) {print('unix not nulll');}
try{
if (kDebugMode) {print('registering');}
registerElec(unix,unixlast).then((value) => () {// REGISTERING THE ELECTION IN FIREBASE
if (kDebugMode) {print('creating blockchain');}
//AFTER REGISTRATION CREATING ELECTION ON BLOCKCHAN
createElection(electionNameTextController.text, ethclient!, privateKeyTextController.text, contractAdressConst);
showSnackBar(snackbarshow().succesAdharSnack);
});
gotoPickElec();
}catch(e){
if (kDebugMode) {
print(e);
}
showSnackBar(errorAdharSnack);
}if (kDebugMode) {print('there is a problemmm');}
}showSnackBar(errorSnack);
}showSnackBar(errorSnack);
}showSnackBar(errorSnack);
});print('i am now out of then part');
}
log output for better understanding记录 output 以便更好地理解
I/flutter ( 6105): the unix time stamp is 1672770600
I/flutter ( 6105): the unix time stamp is 1672857000
I/flutter ( 6105): verifying adhar
I/flutter ( 6105): i am now out of then part
I don't understand what wrong happened here is there any way to do this in less time and more faster way?我不明白这里发生了什么错误,有没有办法在更短的时间内更快地做到这一点? please explain what happened so that I can understand what is going on here,thankyou
请解释发生了什么,以便我能理解这里发生了什么,谢谢
Your calls to Firebase are futures.您拨打 Firebase 的电话是期货。 The.then statement says that when the future returns something, it executes that code.
The.then 语句表示当 future 返回某些内容时,它会执行该代码。 So far so good,.
到目前为止,一切都很好,。 However, the code doesn't stop, waiting for the future to complete, it continues to the next line of code after the.then.
但是,代码并没有停止,等待future 完成,它继续执行.then 之后的下一行代码。 In this scenario, I recommend you use asymc await, rather than.then clauses.
在这种情况下,我建议您使用 asymc await,而不是 .then 子句。 The.then has its uses but probably not in this case.
The.then 有它的用途,但在这种情况下可能没有。
Also, your try catch seems too low down.另外,您的 try catch 似乎太低了。 It needs to be able to catch an error from all of the firebase calls.
它需要能够从所有 firebase 调用中捕获错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.