1

I have a RefreshIndicator which expects a future to return. That RefreshIndicator takes a callback which returns a timer and returns a future. The timer basically runs for infinity(in a sense) and I expect the timeout code completer.complete(); to be called when I call cancel on the timer from somewhere else. However when I call timer.cancel on the timer the lambda completer.complete(); does not get called. Does timer have a force timeout mechanism or is there a better way for me to approach this ? Here is my code

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);
MistyD
  • 16,373
  • 40
  • 138
  • 240

0 Answers0