(Dart / flutter)使用Charts_flutter在测验应用中生成统计图

时间:2019-07-10 14:11:26

标签: list charts flutter dart

我还是很扑朔迷离。 我想将统计信息添加到Charts_flutter可以读取的可增长列表中,但是我不了解我的代码有什么问题以及如何解决它。

我使用了Charts_flutter 0.6.0:https://pub.dev/packages/charts_flutter#

问题屏幕关闭时,我想向列表中添加正确的答案和尝试次数以进行统计,以便Charts_flutter可以生成包含信息的图表。但是,当我尝试这样做时,存在类型问题。我不明白如何解决这个问题。我在“ @override”中遇到问题   void dispose()”

//in question_screen.dart
  // score variables
  int easyTries = 0;
  int tempScore = 0;
  int totalQuestionsAnswered = 0;
  int percentTotal;

  @override
  void dispose() {
    super.dispose();
    percentTotal = (tempScore / totalQuestionsAnswered * 100).round();
    print(percentTotal);
    if (selectedDifficulty == Difficulty.easy &&
        StatWidget.easyData().length == 1) {
      StatWidget.easyData().removeAt(0);
      StatWidget.easyData().add(LinearImprovement(easyTries, percentTotal));
    }
  }

//in stat_widget.dart
import 'package:charts_flutter/flutter.dart' as charts;
import 'package:flutter/material.dart';

class StatWidget extends StatelessWidget {
  final List<charts.Series> seriesList;
  final bool animate;

  StatWidget(this.seriesList, {this.animate});

  factory StatWidget.withSampleData() {
    return new StatWidget(
      easyData(),
      // Disable animations for image tests.
      animate: false,
    );
  }

  @override
  Widget build(BuildContext context) {
    return new charts.LineChart(
      seriesList,
      animate: animate,
      primaryMeasureAxis: new charts.NumericAxisSpec(
        viewport: new charts.NumericExtents(0.0, 100.0),
      ),
      domainAxis: new charts.NumericAxisSpec(
        viewport: new charts.NumericExtents(0.0, 30.0),
      ),
    );
  }

  static List<charts.Series<LinearImprovement, int>> easyData() {
    final data = [
      new LinearImprovement(0, 0),
    ];

    return [
      new charts.Series<LinearImprovement, int>(
        id: 'Points over time',
        colorFn: (_, __) => charts.MaterialPalette.pink.shadeDefault,
        domainFn: (LinearImprovement improvementTries, _) =>
            improvementTries.tries,
        measureFn: (LinearImprovement improvementPercent, _) =>
            improvementPercent.percent,
        data: data,
      )
    ];
  }
}

class LinearImprovement {
  final int tries;
  final int percent;

  LinearImprovement(this.tries, this.percent);
}

我收到错误消息:“参数类型'LinearImprovment'不能分配给参数类型'Series'”

我知道类型错误,但是我不知道如何解决。我以为这样可以,但是显然不行,我该如何解决?

0 个答案:

没有答案