_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,
)),
);
}
这是我在android studio中收到的错误消息。我认为这与 _generatePieChartSectionData 函数有关,或者可能与 StreamBuilder
有关另外,请提供有关任何可帮助我理解抖动错误消息的资源的建议
>/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
答案 0 :(得分:2)
int len = recievedData.length();
而不是上面的我应该使用
int len = recievedData.length;
发生错误是因为飞镖将“ receivedData.length”评估为一个整数(int),您尝试将其作为函数执行。 Dart可以在内部使用对象中定义的“调用”方法来执行它,因此这就是为什么错误如此
答案 1 :(得分:0)
如果您使用 api 并尝试不正确地序列化/反序列化 json,那么我们也可能会面临这些错误,具体取决于您的数据类型。
所以尝试为json生成正确的Model文件。
您可以使用 this link 生成它们并使用适当的方法,例如 fromMap/fromJson 和 toMap/toJson(在上述站点中生成)来正确序列化/反序列化 json。
我确实遇到过同样的错误,在生成模型文件后,我能够克服它。