0

I was going though GSkinner's flutter_vignattes codebase, in one of the functions there was an empty await for a Future

  Future<void> _reset() async {
    // Wait until next event loop to advance animation and call setState or flutter will yell at you
    await Future<void>.value();

    _controller.forward(from: 1.0 - _percentage * 0.83);
    if (_isLoading) {
      setState(() {
        _model = BasketballGameModel.randomize();
      });
    }
    _isLoading = false;
  }

I understand how promises are sent to micro-task queue in JS (assuming same happens in Dart), but not quite able to understand the reason provided in the comment here i.e.,

    // Wait until next event loop to advance animation and call setState or flutter will yell at you

Really appreciate if someone can provide a deeper insight into this. This is the particular line in codebase i am referring to. https://github.com/gskinnerTeam/flutter_vignettes/blob/0ccc72c5b87b5ab6ba2dee9eff76f48ce2fadec8/vignettes/basketball_ptr/lib/demo.dart#L149

Sanketh B. K
  • 759
  • 8
  • 22

0 Answers0