颤振|图表饼 |来自数据库的信息

时间:2021-03-15 01:21:18

标签: flutter flutter-provider

我想从数据库创建数据图表。但是当我运行它返回错误 null。enter image description here

List<charts.Series<Transactions, String>> _series(BuildContext context) {

    final myTransaction = Provider.of<Transaction>(context).myTransaction;

    List<Transactions> data = List<Transactions>();
    data.add(Transactions(category: myTransaction.category, amount: myTransaction.amount, color: myTransaction.color));

    return [
      charts.Series<Transactions, String>(
          id: 'Transactions',
          domainFn: (Transactions transactions, _) => transactions.category,
          measureFn: (Transactions transactions, _) => transactions.amount,
          labelAccessorFn: (Transactions transactions, _) => '\$${transactions.amount}',
          colorFn: (Transactions transactions, _) =>
              charts.ColorUtil.fromDartColor(
                  HexColor.fromHex(transactions.color)),
          data: data
      )
    ];
  }

1 个答案:

答案 0 :(得分:0)

您需要在 myTransaction 类中初始化 Transaction

 Transactions myTransaction = Transaction() ;