伙計們!需要你幫忙。我在 AlertDialog 中有 ListView:
ListView.builder(
itemExtent: 140,
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: tasks.length,
itemBuilder: (context, index) {
var tagTwoList = tasks[index].tagTwo;
return ListTile(
visualDensity: VisualDensity.compact,
selected: index == _selectedIndex,
selectedTileColor: Colors.indigo.withOpacity(0.7),
title: Center(
child: tagTwoList),
onTap: () {
setState(() {
_selectedIndex = index;
});
},
);
}),
我嘗試使用谷歌搜索,但那里列出的提示沒有幫助或無法正常作業。示例:
如果洗掉 SizedBox,則會收到錯誤訊息:
RenderBox 未布置:RenderPhysicalShape#1564b relayoutBoundary=up2 'package:flutter/src/rendering/box.dart':斷言失敗:第 1982 行 pos 12:'hasSize'
uj5u.com熱心網友回復:
我找不到合適的解決方案,所以我稍微更正了顯示,現在代碼看起來像這樣。
SizedBox(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height -727,
child: ListView.builder(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
itemCount: tagTwoContainer.length,
itemBuilder: (context, index) {
var tagTwoList = tasks[index].tagTwo;
return SizedBox(
height: MediaQuery.of(context).size.height, width: 170,
child: ListTile(
visualDensity: VisualDensity.compact,
selected: index == _selectedIndex,
selectedTileColor: Colors.indigo.withOpacity(0.6),
title: tagTwoList,
onTap: () {
setState(() {
_selectedIndex = index;
});
},
),
);
}),
),

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/449654.html
