Flutter|ListView-hasSize
Flutter|ListView - hasSize
伙计们!
需要你帮忙。
我在 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;
});
},
);
}),
我尝试使用谷歌搜索,但那里列出的提示没有帮助或无法正常工作。示例:
我尝试使用 Expanded、Row、Expanded inside Row。
现在它可以与 SizedBox 一起使用,但它看起来很糟糕,当被选中时,整个 SizedBox 都被选中:
如果删除 SizedBox,则会出现错误:
RenderBox was not laid out: RenderPhysicalShape#1564b relayoutBoundary=up2
'package:flutter/src/rendering/box.dart':
Failed assertion: line 1982 pos 12: 'hasSize'
我找不到合适的解决方案,所以我稍微修正了显示,现在代码如下所示。
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;
});
},
),
);
}),
),
伙计们! 需要你帮忙。 我在 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 was not laid out: RenderPhysicalShape#1564b relayoutBoundary=up2 'package:flutter/src/rendering/box.dart': Failed assertion: line 1982 pos 12: 'hasSize'
我找不到合适的解决方案,所以我稍微修正了显示,现在代码如下所示。
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;
});
},
),
);
}),
),