flutterstream-builderfl-chart

Class 'int' has no instance method 'call' ERROR FLUTTER


_generatePieChartSectionData(recievedData) {
  print(recievedData);
  int len = recievedData.length();
  for (int i = 0; i < len; i++) {
    _pieChartdata.add(charts.PieChartSectionData(
       color: Color(int.parse(recievedData[i].color)),
      title: recievedData[i].name,
      value: double.parse(recievedData[i].value),
    ));
  }

Widget _bodyBuild(context) {
  return StreamBuilder<QuerySnapshot>(
    stream: Firestore.instance.collection('pieChart').snapshots(),
    builder: (context, snapshot) {
      if (!snapshot.hasData) {
        return LinearProgressIndicator();
      } else {
        List<ManHours> man = snapshot.data.documents
            .map((documentSnapshot) => ManHours.from(documentSnapshot.data))
            .toList();
        return _buildPie(context, man);
      }
    },
  );
}

Widget _buildPie(BuildContext context, List<ManHours> man) {
  recievedData = man;
  print('ghfghfghfhgfghfhgfhfghfghfgfhfh');
  print(recievedData.toString());
  _generatePieChartSectionData(recievedData);
  print('kk');
  return Center(
    child: charts.PieChart(charts.PieChartData(
      sections: _pieChartdata,
      sectionsSpace: 5.0,
      centerSpaceRadius: 40.0,
    )),
  );
}

This is the error message i got in android studio. I think this is related to the _generatePieChartSectionData function or it may be something to do with the StreamBuilder

Also, please provide suggestion regarding any resource that will help me understand flutter error messages

>/flutter ( 8961): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY>╞═══════════════════════════════════════════════════════════
>I/flutter ( 8961): The following NoSuchMethodError was thrown building StreamBuilder<QuerySnapshot (dirty, state:
>I/flutter ( 8961): _StreamBuilderBaseState<QuerySnapshot, AsyncSnapshot<QuerySnapshot>>#19026): >I/flutter ( 8961): Class 'int' has no instance method 'call'.
>I/flutter ( 8961): Receiver: 6
>I/flutter ( 8961): Tried calling: call()
>I/flutter ( 8961):
>I/flutter ( 8961): The relevant error-causing widget was:
>I/flutter ( 8961):   StreamBuilder<QuerySnapshot>
>I/flutter ( 8961):   >file:///G:/FLUTTER_PROJECTS/charts_unergia/lib/activities/pieChartActivity.dart:40:12

Solution

  •  int len = recievedData.length();
    

    instead of the above i should be using

     int len = recievedData.length;
    

    The error happens because the dart evaluates "receivedData.length" to an integer (int), that you try to execute as a function. Dart internally can use the "call" method defined in the object to execute it, so this is why the error is like this