[英]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.