[英]Widget flickers and disappears when scrolling
我已经为此失眠了。
我正在尝试在ListView
中显示图表(用于滚动)。 由于某种原因, Card
的内容在滚动时会闪烁并随机完全消失(但Card
本身仍然可见)。
知道为什么会这样吗?
(...) ListView (...)
children: [Row ( children: [buildChartBox()] )] (...)
Expanded buildChartBox() {
return Expanded(
child: Card(
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
Column(
mainAxisSize: MainAxisSize.min,
children: [
chartTitles(
title: 'Items',
subtitle: 'by value'),
SizedBox(
height: 300,
child: ValuesChart(data: calculateValues(items)))
],
),
],
),
),
),
);
}
Row chartTitles({String title = '', String subtitle = ''}) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(title, style: text_charttitle),
Text(subtitle, style: text_chartsubtitle),
],
)
],
);
}
尝试的事情:
chartTitles
return
替换为空Container
(即删除标题)确实可以缓解问题。 然后图表会保持显示状态,但也会轻微闪烁。SingleChildScrollView
替换ListView
不会改变任何东西。编辑:ValuesChart 的代码:
import 'package:fl_chart/fl_chart.dart';
class ValuesChart extends StatelessWidget {
final Map<String, int> data;
const ValuesChart({required this.data});
@override
Widget build(BuildContext context) {
return Container(
child: PieChart(
_theData(data),
));
}
}
请注意,我使用的是名为“fl_chart”的 package。 _theData
只是返回图表的各种参数,我认为这无关紧要。
尝试用SingleChildScrollView
替换ListView
flutter 中的ListView
默认使用它在 Android RecyclerView
中调用的内容来有效地使用渲染资源。 如果您对这里感兴趣的文章https://medium.com/1mgofficial/how-recyclerview-works-internally-71290de5d2c4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.