【发布时间】:2021-12-22 10:01:51
【问题描述】:
我试图让我的 PieChart 标签可见,但是在设置 arcRenderDecorators 之后它就出现了
- RenderBox 未布置:ChartContainerRenderObject#1bf0d NEEDS-PAINT 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize'
- RenderBox 未布置:RenderPointerListener#5ff88 需要-绘制需要-合成-位-更新 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize'
- RenderBox 未布置:RenderSemanticsGestureHandler#4a473 需要-绘制需要-合成-位-更新 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize'
- RenderBox 未布置:ChartContainerRenderObject#1bf0d 'package:flutter/src/rendering/box.dart': 断言失败:第 1927 行第 12 行:'hasSize' 问题。
我必须使用什么样的小部件才能做到这一点。请帮忙。
final List<DeveloperSeries> data = [
DeveloperSeries(
year: "2017",
developers: 40000,
barColor: charts.ColorUtil.fromDartColor(Colors.blue),
),
DeveloperSeries(
year: "2019",
developers: 40000,
barColor: charts.ColorUtil.fromDartColor(Colors.blue),
),
DeveloperSeries(
year: "2020",
developers: 35000,
barColor: charts.ColorUtil.fromDartColor(Colors.blue),
),
DeveloperSeries(
year: "2021",
developers: 45000,
barColor: charts.ColorUtil.fromDartColor(Colors.blue),
),
];
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: DeveloperChart(
data: data,
)
),
);
}
}
class DeveloperChart extends StatelessWidget {
final List<DeveloperSeries> data;
DeveloperChart({required this.data});
@override
Widget build(BuildContext context) {
List<charts.Series<DeveloperSeries, String>> series = [
charts.Series(
id: "developers",
data: data,
domainFn: (DeveloperSeries series, _) => series.year,
measureFn: (DeveloperSeries series, _) => series.developers,
colorFn: (DeveloperSeries series, _) => series.barColor,
labelAccessorFn: (DeveloperSeries row, _) => row.year,
)
];
return Container(
height: 500,
width: 500,
child: Card(
child: Padding(
padding: const EdgeInsets.all(9.0),
child: Column(
children: <Widget>[
Text(
"Yearly Growth in the Flutter Community",
style: Theme
.of(context)
.textTheme
.bodyText2,
),
Expanded(
child: charts.PieChart(series, animate: true,
defaultRenderer: charts.ArcRendererConfig(
arcRendererDecorators: [
charts.ArcLabelDecorator(
labelPosition: charts.ArcLabelPosition
.outside)
])
)
)
]
),
),
)
);
}
}```
【问题讨论】: