使用带有LabelAccessorFn的FutureBuilder的Flutter Charts

时间:2020-08-11 18:01:08

标签: flutter charts

我正在使用StreamBuilder来为Flutter Charts outside label pie chart创建数据。数据字段( categoryId )是另一个数据模型的整数外键,被用作域,聚合值( expenseTotal )是度量。我正在尝试使用从sqlite查找的FutureBuilder,用labelAccessorFn用其各自的描述性字符串标题替换此数据字段。正确调用了将来的函数( getCategoryTitle ),并检索了正确的标题值,但是,无论出于何种原因,它都不会返回ConnectionState.done。我得到的只是一个FutureBuilder。

我在其他地方使用FutureBuilder取得了成功,但不是这种情况。我希望有一些指示。非常感谢!

List<charts.Series<TotalByCategory, int>>
totalByCategorySeries = [
  charts.Series<TotalByCategory, int>(
  id: 'expenseByCategory',
  seriesColor: charts.ColorUtil.fromDartColor(Theme.of(context).accentColor),
  domainFn: (TotalByCategory expense, _) => expense.categoryId,
  measureFn: (TotalByCategory expense, _) => expense.expenseTotal,
  data: weeklyTotalByCategoryList,
  labelAccessorFn: (TotalByCategory row, _) => FutureBuilder<String> (
    future: getCategoryTitle(row.categoryId),
    builder: (BuildContext context, AsyncSnapshot categoryInfoSnapshot) {
      if (categoryInfoSnapshot.connectionState == ConnectionState.done){
        if(categoryInfoSnapshot.hasData) { return Text('${categoryInfoSnapshot.data.toString()}'); }
        return Text('?');
      }
      return Text('?');
    },).toString(),
  colorFn: (_, index) => charts.MaterialPalette.green.makeShades(weeklyTotalByCategoryList.length)[index],)];

0 个答案:

没有答案