how fetch data async in initstate and then create build method and pass data?
i want get data async from API in initstate and then create build method this is my code:
Future<void> getCurrency() async {
NetworkHelper networkHelper = await NetworkHelper(
url: 'https://rest.coinapi.io/v1/exchangerate/BTC/USD?apikey=$kApiKey');
var currencyData = await networkHelper.getData();
currencyrate = currencyData['rate'];
}
late double rate;
@override Widget build(BuildContext context) { return Scaffold( body: SafeArea( child: Center( child: Text( '1 BTC = $rate USD', style: TextStyle(fontSize: 20, color: Colors.black), ), ), )); } }