Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter 颤振贝塞尔图数据问题_Flutter_Dynamic - Fatal编程技术网

Flutter 颤振贝塞尔图数据问题

Flutter 颤振贝塞尔图数据问题,flutter,dynamic,Flutter,Dynamic,我正试图在Flatter中创建一个图表,该图表的坐标或点会根据数组动态更改,但目前,在使用bezierChart包进行此操作时,我遇到以下问题,即“元素类型‘Set>’无法分配给列表类型‘DataPoint’。”这个错误是直接从for循环行内部数据中派生出来的,您可以从下面链接的代码片段中看到该数据。是否有任何方法可以动态地将数据点传递给这个数据部分,这样我就可以拥有X个数据点,而不是预定数量的数据点 Container( height: MediaQuery

我正试图在Flatter中创建一个图表,该图表的坐标或点会根据数组动态更改,但目前,在使用bezierChart包进行此操作时,我遇到以下问题,即“元素类型‘Set>’无法分配给列表类型‘DataPoint’。”这个错误是直接从for循环行内部数据中派生出来的,您可以从下面链接的代码片段中看到该数据。是否有任何方法可以动态地将数据点传递给这个数据部分,这样我就可以拥有X个数据点,而不是预定数量的数据点

Container(
                  height: MediaQuery.of(context).size.height / 2,
                  width: MediaQuery.of(context).size.width * 0.9,
                  child: BezierChart(
                  bezierChartScale: BezierChartScale.MONTHLY,
                  fromDate: fromDate,
                  toDate: toDate,
                  selectedDate: toDate,
                  series: [
                    BezierLine(
                      label: "Weight Monthly Comparison",
                      onMissingValue: (dateTime) {
                        if (dateTime.month.isEven) {
                          return 0.0;
                        }
                        return 0.0;
                      },
                      data: [
                        //ERROR OCCURS INSIDE HERE
                          for (var i = 0; i < progressionList[index].weight.length; i++) 
                          {
                            DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: progressionList[index].timeupdate[0]),
                          }
                        //DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: progressionList[index].timeupdate[0]),
                        // DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: date1),
                        // DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: date2),
                        // DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: date3),
                        // DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: date4),
                        // DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: date5),
                        // DataPoint<DateTime>(value: (progressionList[index].weight[0]).toDouble(), xAxis: date6),
                      ],
                    ),
                  ],
                  config: BezierChartConfig(
                    verticalIndicatorStrokeWidth: 3.0,
                    verticalIndicatorColor: Colors.black26,
                    showVerticalIndicator: true,
                    verticalIndicatorFixedPosition: false,
                    backgroundColor: Colors.red,
                    footerHeight: 30.0,
                  ),
                ),
              )
容器(
高度:MediaQuery.of(context).size.height/2,
宽度:MediaQuery.of(context).size.width*0.9,
孩子:贝塞尔图表(
bezierChartScale:bezierChartScale.MONTHLY,
fromDate:fromDate,
托德:托德,
选择日期:toDate,
系列:[
贝塞尔线(
标签:“重量每月比较”,
onMissingValue:(日期时间){
如果(dateTime.month.isEven){
返回0.0;
}
返回0.0;
},
数据:[
//错误发生在这里
对于(var i=0;i
您可以复制粘贴运行下面的完整代码
您可以在
构建中执行for循环,并使用
数据点列表。添加

代码片段

@override
  Widget build(BuildContext context) {
    List<DataPoint<DateTime>> dataPointList = [];
    for (var i = 0; i < progressionList.length; i++) {
      dataPointList.add(DataPoint<DateTime>(
          value: progressionList[i].weight.toDouble(),
          xAxis: progressionList[i].timeupdate));
    }
... 
BezierLine(
                  label: "Weight Monthly Comparison",
                  onMissingValue: (dateTime) {
                    if (dateTime.month.isEven) {
                      return 0.0;
                    }
                    return 0.0;
                  },
                  data: dataPointList), 
@覆盖
小部件构建(构建上下文){
列表数据点列表=[];
对于(变量i=0;i
工作演示

完整代码

import 'package:flutter/material.dart';
import 'package:bezier_chart/bezier_chart.dart';

void main() {
  runApp(MyApp());
}

class Progression {
  int weight;
  DateTime timeupdate;

  Progression({this.weight, this.timeupdate});
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final fromDate = DateTime.now().subtract(Duration(days: 300));
  final toDate = DateTime.now();

  List<Progression> progressionList = [
    Progression(
        weight: 50, timeupdate: DateTime.now().subtract(Duration(days: 2))),
    Progression(
        weight: 60, timeupdate: DateTime.now().subtract(Duration(days: 30))),
    Progression(
        weight: 70, timeupdate: DateTime.now().subtract(Duration(days: 50))),
    Progression(
        weight: 80, timeupdate: DateTime.now().subtract(Duration(days: 60)))
  ];

  @override
  Widget build(BuildContext context) {
    List<DataPoint<DateTime>> dataPointList = [];
    for (var i = 0; i < progressionList.length; i++) {
      dataPointList.add(DataPoint<DateTime>(
          value: progressionList[i].weight.toDouble(),
          xAxis: progressionList[i].timeupdate));
    }

    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              height: MediaQuery.of(context).size.height / 2,
              width: MediaQuery.of(context).size.width * 0.9,
              child: BezierChart(
                bezierChartScale: BezierChartScale.MONTHLY,
                fromDate: fromDate,
                toDate: toDate,
                selectedDate: toDate,
                series: [
                  BezierLine(
                      label: "Weight Monthly Comparison",
                      onMissingValue: (dateTime) {
                        if (dateTime.month.isEven) {
                          return 0.0;
                        }
                        return 0.0;
                      },
                      data: dataPointList),
                ],
                config: BezierChartConfig(
                  verticalIndicatorStrokeWidth: 3.0,
                  verticalIndicatorColor: Colors.black26,
                  showVerticalIndicator: true,
                  verticalIndicatorFixedPosition: false,
                  backgroundColor: Colors.red,
                  footerHeight: 30.0,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“package:bezier_chart/bezier_chart.dart”;
void main(){
runApp(MyApp());
}
阶级进步{
整数权重;
日期时间更新;
前进({this.weight,this.timeupdate});
}
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回材料PP(
标题:“颤振演示”,
主题:主题数据(
主样本:颜色。蓝色,
视觉密度:视觉密度。自适应平台密度,
),
主页:MyHomePage(标题:“颤振演示主页”),
);
}
}
类MyHomePage扩展StatefulWidget{
MyHomePage({Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_MyHomePageState createState()=>\u MyHomePageState();
}
类_MyHomePageState扩展状态{
final fromDate=DateTime.now().subtract(持续时间:300天);
final toDate=DateTime.now();
列表进度列表=[
进展(
权重:50,时间更新:DateTime.now().subtract(持续时间(天数:2)),
进展(
权重:60,时间更新:DateTime.now().subtract(持续时间(天:30)),
进展(
权重:70,时间更新:DateTime.now().subtract(持续时间(天数:50)),
进展(
权重:80,时间更新:DateTime.now().subtract(持续时间(天:60)))
];
@凌驾
小部件构建(构建上下文){
列表数据点列表=[];
对于(变量i=0;iList<DataPoint> makeDataPoints() {
 List<DataPoint> dataPointList = [];
 for (int i = 1; i < 10; i++) {
   dataPointList.add(DataPoint<DateTime>(
      value: i, xAxis: DateTime(2020, 10, 01, i, 00)));
 }
return dataPointList;
}
series: [
  BezierLine(
    label: "Line Name",
    data: makeDataPoints(),
  ),
],