'Flutter|ListView - hasSize
guys! Need you help. I have ListView inside AlertDialog:
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;
});
},
);
}),
I tried googling, but the tips that are listed there do not help or do not work correctly. Example: Get an error `Failed assertion: line 1687 pos 12: 'hasSize'` when render ListTile inside `Row`
I tried using Expanded, Row, Expanded inside Row.
Now it works with SizedBox, but it looks just awful and when selected, the entire SizedBox is selected:

If you remove the SizedBox, you get an error:
RenderBox was not laid out: RenderPhysicalShape#1564b relayoutBoundary=up2 'package:flutter/src/rendering/box.dart': Failed assertion: line 1982 pos 12: 'hasSize'
Solution 1:[1]
I couldn't find a suitable solution, so I corrected the display a bit and now the code looks like this.
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;
});
},
),
);
}),
),
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dedserv |

