我有一个RefreshIndicator
,希望将来会回来。该RefreshIndicator进行回调,该回调返回计时器并返回未来。计时器基本上是无限运行的(从某种意义上来说),我希望在其他地方从计时器上调用cancel时将调用超时代码completer.complete();
。
但是,当我在计时器上调用timer.cancel时,不会调用lambda completer.complete();
。计时器是否具有强制超时机制,或者我有更好的方法来解决此问题?这是我的代码
void getEmployees({bool force=false,String query="",Timer refreshTimer})
{
services.getEmployees(url:query).then((modelEmployeeCollection col){
if(refreshTimer!=null) {
refreshTimer.cancel();
}
refreshState(() {
isBusy = false;
});
});
}
Future<Null> _onRefresh() {
Completer<Null> completer = new Completer<Null>();
Timer timer = new Timer(new Duration(seconds: 500), () {
completer.complete();
});
getEmployees(force: true,query: employeeCacheNextPreviousShared,refreshTimer: timer);
return completer.future;
}
var refreshListView = new RefreshIndicator(child: emplyeeListView, onRefresh:_onRefresh);