0

My method processData() is executing before pullAllData() is finished but I need processData() to wait until pullAllData() is completely finished before running. This is causing my isDownloadSuccessful bool to be Null when processData() is ran.

Future getCoinData() async {
    calculateNumberOfDataPoints();
    pullTimesAndPrices();
    return timesAndPrices;
  }

Future pullTimesAndPrices() async {
    for (String cryptoCurrency in cryptoAbbreviation) {
      pullAllData(cryptoCurrency);
      processData(cryptoCurrency);
    }
  }

Future pullAllData(cryptoCurrency) async {
    String historicalRequestURL =
        '$cryptoAPIURL$cryptoCurrency$currency/ohlc?periods=$periodValue&apikey=$apiKey';
    http.Response historicalResponse = await http.get(historicalRequestURL);
    isPullSuccessful = (historicalResponse.statusCode == 200);
  }

void processData(cryptoCurrency) {
    if (isPullSuccessful) {
      ...
    } else {
      throw 'Problem pulling data';
    }
  }

1 Answer 1

1

You are marking your function pullTimesAndPrices as async but not using await. Use the await keyword before calling the pullAllData function.

Sign up to request clarification or add additional context in comments.

1 Comment

Awesome thank you! I changed my code to Future<void> pullTimesAndPrices() async { for (String cryptoCurrency in cryptoAbbreviation) { await pullAllData(cryptoCurrency); processData(cryptoCurrency); } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.