'Generate dynamic height horizontal listview nested in a vertical listview
I'm trying to generate a dynamic height HORIZONTAL listview that is nested inside a VERTICAL listview
I'm already in the point of printing my horiztonal listview, but the content of each card is cutted by the fixed height of the parent container of the horizontal list view, the dismiss animation is being cutted out as well because of the parent-container height of the horizontal list view
class TestPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Test'),
),
body: ListView(
children: <Widget>[
Container(
height: 100,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: 100,
itemBuilder: (context, index) {
return Dismissible(
direction: DismissDirection.down,
key: Key('$index'),
child: Card(
child: Container(
width: 100,
child: Text('${index}',
// here goes cutted long text
style: TextStyle(color: Colors.white),
),
),
),
);
},
),
),
],
),
);
}
}
link image, https://i.pinimg.com/564x/b7/f6/34/b7f6340dbb96212bc9c216e9bbc0d5da.jpg, stackoverflow doesn't let me post images yet :(
*Edit: What i look for is set every card height dynamically depending on the length of its child text
Solution 1:[1]
Instead of putting your nested list view inside a container, can you try wrapping it with the Expanded widget?
Solution 2:[2]
To add dynamic height horizontal list-view inside vertical list you should switch to a Row inside a SingleChildScrollview:
Example
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
itemCount: 5,
scrollDirection: Axis.vertical,
itemBuilder: (context, index) {
return SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [Text("SomeListText"), Text("SomeListText"), Text("SomeListText"), Text("SomeListText")],
),
);
},
),
);
}
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 | Can |
Solution 2 | Chheangly Prum |