我想从数据库创建数据图表。但是当我运行它返回错误 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
)
];
}
答案 0 :(得分:0)
您需要在 myTransaction
类中初始化 Transaction
。
Transactions myTransaction = Transaction() ;