[英]Widget flickers and disappears when scrolling
I'm already losing sleep over this.我已经为此失眠了。
I'm trying to display a chart inside a ListView
(for scrolling).我正在尝试在
ListView
中显示图表(用于滚动)。 For some reason the contents of the Card
flickers when scrolling and randomly completely disappears (the Card
itself stays visible though).由于某种原因,
Card
的内容在滚动时会闪烁并随机完全消失(但Card
本身仍然可见)。
Any idea why would that happen?知道为什么会这样吗?
(...) 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),
],
)
],
);
}
Things tried:尝试的事情:
chartTitles
return
with an empty Container
(ie removing the titles) does mitigate the issue.chartTitles
return
替换为空Container
(即删除标题)确实可以缓解问题。 The chart then stays displayed but also flickers slightly .ListView
with a SingleChildScrollView
doesn't change anything.SingleChildScrollView
替换ListView
不会改变任何东西。 EDIT: Code for the ValuesChart:编辑: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),
));
}
}
Note I'm using a package called 'fl_chart'.请注意,我使用的是名为“fl_chart”的 package。
_theData
just returns various parameters for the chart, I don't think it's relevant. _theData
只是返回图表的各种参数,我认为这无关紧要。
Try to replace ListView
with SingleChildScrollView
尝试用
SingleChildScrollView
替换ListView
ListView
s in flutter by default using what it is called in Android RecyclerView
to efficiently use render resources. flutter 中的
ListView
默认使用它在 Android RecyclerView
中调用的内容来有效地使用渲染资源。 If you are interested here an article https://medium.com/1mgofficial/how-recyclerview-works-internally-71290de5d2c4如果您对这里感兴趣的文章https://medium.com/1mgofficial/how-recyclerview-works-internally-71290de5d2c4
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.