I'm building a data list like this
List<String> list=[.....]; //a lot of data
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
controller: scrollController,
itemCount: list.length,
itemBuilder: (context, i) =>
ListTile(title: Text(list[i])))
It can scroll on vertical now but some long data will overflow on the right,so I want to add a horizontal scroll outside.
I tried many ways but it always return error such as "'constraints.hasBoundedWidth': is not true."
Code like this works fine but I have to set a width in Container first :
ListView(
shrinkWrap: true,
scrollDirection: Axis.horizontal,
children: [
Container(
width: 2000, //will return error if not set a value
child: ListView.builder(.....)
)])
Is there any way to add a horizontal scroll outside with unknown child width?
CodePudding user response:
Nothing wrong in vertical list. I have run code in android studio as well.
no need to use Listview in the inner of another list view. you can wrap your title with Expanded widget, if your list title overflow on right side of screen.
return ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
padding: EdgeInsets.all(10),
itemCount:100,
itemBuilder: (context, i) =>
ListTile(title: Text("{$i ===}babul dshdshfdsh dfhdhfdh hbfdshhds hdfhdsvhfdsv hdsvd hdsfhdshv dhfbhdsb hdsghshdsg hdvshvv jdsfjfdbvjfdnfjbfjbfhbfbf fhbfdhbfdhbf")));
}
CodePudding user response:
Below code will serve your purpose. Happy coding...
return Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount:10,
itemBuilder: (context, i) =>
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: new Text(
"Description that is too long in text format(Here Data is coming from API Description that is too long in text format)",
style: new TextStyle(
fontSize: 16.0, color: Colors.black87,
),
),
),
),);