0

I extract data from the Firebase to make a list of FLSpots and try to assign it to LineChartBarData(spots: ) but the incompatibility doesn't allow it.

static Future<List<FlSpot>> _getDataFromFirestore() async {

  ...
  ...

  List<FlSpot> spots = listData.asMap().entries.map((e) {
    return FlSpot(e.key.toDouble(), e.value);
  }).toList();

  // print(spots);
  return spots;

how can I assign it to avoid the error: The argument type 'Future<List<FlSpot>>' can't be assigned to the parameter type 'List<FlSpot>'. when I try

LineChartBarData(
          spots: _getDataFromFirestore(),
Hober Mark
  • 13
  • 3
  • you should await for _getDataFromFireStore. You could use initState to load the data. And while the data is loading you show a loading indicator. That's the common approach for async data – RegularGuy Sep 30 '20 at 16:01
  • https://stackoverflow.com/questions/63017280/what-is-a-future-and-how-do-i-use-it – Doug Stevenson Sep 30 '20 at 16:09

1 Answers1

0
LineChartBarData(
          spots:await _getDataFromFirestore(),

use await keyword before calling the function.

Abhishek Ghaskata
  • 1,802
  • 2
  • 6
  • 11