Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
398 views
in Technique[技术] by (71.8m points)

flutter - type 'List<dynamic>' is not a subtype of type 'List<DataPoint<DateTime>>' of 'function result'

I want a chart which showes data of the last week. Therefore, I use bezier_chart. Everything works, but I want the displayed data to be in a list. Instead of putting the data directly in the data: (as it is in the tutorial), I gave it directly in the var datatest, but I get an error. The error is: type 'List<dynamic>' is not a subtype of type 'List<DataPoint<DateTime>>' of 'function result'.

Does anybody know a solution for this problem?

This is my code in the BezierChart:

child: BezierChart(
    fromDate: fromDate,
    bezierChartScale: BezierChartScale.WEEKLY,
    toDate: toDate,
    selectedDate: toDate,
    series: [
       BezierLine(
         label: "Duty",
         onMissingValue: (dateTime) {
           return 0.0;
         },
         data: dataTest,
       ),

This is my dataTest list:

var dataTest = [
    DataPoint<DateTime>(
        value: 10, xAxis: DateTime.now().subtract(Duration(days: 2))),
    DataPoint<DateTime>(
        value: 100, xAxis: DateTime.now().subtract(Duration(days: 3))),
  ];

Thsi is the link to the example: https://pub.dev/packages/bezier_chart

question from:https://stackoverflow.com/questions/65942493/type-listdynamic-is-not-a-subtype-of-type-listdatapointdatetime-of-fu

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

try:

List<DataPoint<DateTime>> dataTest = [
    DataPoint<DateTime>(
        value: 10, xAxis: DateTime.now().subtract(Duration(days: 2))),
    DataPoint<DateTime>(
        value: 100, xAxis: DateTime.now().subtract(Duration(days: 3))),
];

The problem is that the data parameter from the BezierChart expects a List<DataPoint<DateTime>> but since you're declaring your list as var List the compiler will complain that you're not enforcing the type of values that can go into your created list


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...