【发布时间】:2022-11-25 05:44:12
【问题描述】:
我正在尝试每 250 毫秒对一个体育 api 进行连续的 api 调用,以获取板球的最新分数。我正在使用 Getx 模式及其状态管理来在 flutter 中实现相同的功能。能否请您指定一种方法来实现相同的功能。我的代码版本随附。
控制器代码如下
final liveData = {}.obs;
liveApiContinuousCall() async {
liveData.value = {};
Timer.periodic(const Duration(seconds: 1), (timer) async {
http.Response liveResponse = await http.post(
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.liveMatchByMatchIdUrl}'),
body: {'match_id': matchIdController.matchID.value},
);
var decodedData = jsonDecode(liveResponse.body);
liveData.value = decodedData['data'];
});
}
The live data variable is then being used by me in view to render the UI.
【问题讨论】:
标签: flutter api flutter-getx