英文:
How can I make my custom onChanged in a function in flutter
问题
void callThisAPI({header}) {
_dio.request(
onSendProgress(sent, total) { //这是一个根据发送的数据而变化的监听器。
double percent=1.0*sent/total;
//我想要将这个百分比值返回到调用函数的地方,并相应地更新它。
}
)
}
现在,当调用:
callThisAPI(
header: someHeader,
onChanged(percentage) {
progressPercentage=percentage
//在这里,我想要连续接收百分比值当它发生变化时。
}
)
英文:
I am using a function for API call. I used it's parameter listener for checking sent and received progress. Now, I want to add an onChanged function which listens to sent and received values and notify them when the function is called. Like:
void callThisAPI({header}) {
_dio.request(
onSendProgress(sent, total) { //This is a listener which changes according to the data sent.
double percent=1.0*sent/total;
//I want to return this percent value back to where function is called and updated accordingly.
}
)
}
Now, when calling:
callThisAPI(
header: someHeader
onChanged(percentage) {
progressPercentage=percentage
//Here I want to receive the percentage continuously when it changes.
}
)
If the question is not clear enough, please do tell me if I should paste my code for more understanding.
答案1
得分: 1
void callThisAPI({header, void Function(double)? onChanged}) {
_dio.request(
onSendProgress(sent, total) { //这是一个根据发送的数据变化的监听器。
double percent=1.0*sent/total;
//我希望将这个百分比值返回到调用该函数的地方,并相应地更新。
onChanged?.call(percent);
}
);
}
英文:
void callThisAPI({header, void Function(double)? onChanged}) {
_dio.request(
onSendProgress(sent, total) { //This is a listener which changes according to the data sent.
double percent=1.0*sent/total;
//I want to return this percent value back to where function is called and updated accordingly.
onChanged?.call(percent);
}
);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论