I have a nested ItemList that is made as follows:
SafeArea(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
ListTile(
title: Text('Placeholder'),
),
ListView.builder(
shrinkWrap: true,
itemCount: itemList.length,
itemBuilder: (BuildContext context, int index) {
final itemData = itemList[index];
return Card(
child: ListTile(
title: Container(
width: MediaQuery.of(context).size.width,
child: Text(
itemData.text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.headline5,
),
),
),
);
},
),
],
),
),
I can scroll up and down when holding the items directly placed in the first list, doing so also moves the items from the nested list. (wanted behavior)
When holding items in the sublist (the one with the builder), nothing moves anywhere.
I want to make so that all items move when any of them are held to scroll, how can I do that?
Is there a way to build a list without ListView.builder or did I miss some ListView parameters?
You could use the physics parameter of Listview to achive the intended result.
SafeArea(
child: ListView(
physics: AlwaysScrollableScrollPhysics(), // add this
padding: EdgeInsets.zero,
children: <Widget>[
ListTile(
title: Text('Placeholder'),
),
ListView.builder(
physics: NeverScrollableScrollPhysics(), // and this
shrinkWrap: true,
itemCount: itemList.length,
itemBuilder: (BuildContext context, int index) {
final itemData = itemList[index];
return Card(
child: ListTile(
title: Container(
width: MediaQuery.of(context).size.width,
child: Text(
itemData.text,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: Theme.of(context).textTheme.headline5,
),
),
),
);
},
),
],
),
)
Now your list should be scrollable.
Related
Is it possible to configure a ExpansationTile to have 2 actions:
Expand when clicking on the trailing icon
Going to another screen when clicking anywhere else?
Also, is it possible to omit the trailing icon IF the children of the item doesn't have information to display (eg, sublist is empty)?
Here's what I have ATM:
Expanded(
child: ListView.builder(
itemBuilder: (context, index) {
return Card(
child: ExpansionTile(
leading: Image.asset('images'),
title: Text('Text'),
subtitle: Text('Text'),
children: [
ListView.builder(
itemBuilder: (context, index2) {
return Card(
child: ListTile(
onTap: () => print('test'),
leading: Image.asset('images'),
title: Text('Text'),
subtitle: Text('Text'),
);
},
itemCount: list[index].sublist.length,
shrinkWrap: true,
padding: EdgeInsets.all(5),
scrollDirection: Axis.vertical,
),
],
),
);
},
itemCount: list.length,
shrinkWrap: true,
padding: EdgeInsets.all(5),
scrollDirection: Axis.vertical,
),
)
You can achieve it by adding IconButton to the trailing part of the ExpansionTile.
Here's an example code snippet for the same.
ExpansionTile(
title: const Text('Hello'),
trailing: IconButton(
onPressed: () => log('Hello');
icon: const Icon(Icons.arrow_drop_down),
),
children: const [Text('World')],
),
I can see 6 list items in my listview widget and I can not scroll the listview although 3 more items are there.
Actually I want to keep this workouts page pretty simple that means I want to avoid using many rows/columns...
I have just a text label at the top left corner and below listview.
What do I have to change to make the listview scrolling?
I already use physics: AlwaysScrollableScrollPhysics(),
appBar: AppBar(
title: Text(title),
),
body: Container(
color: Colors.green,
margin: const EdgeInsets.all(5.0),
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Text("Workouts", style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25)),
),
Expanded(
child: ListView.builder(
physics: AlwaysScrollableScrollPhysics(),
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: workouts.length,
itemBuilder: (context, index) {
var workout = workouts[index];
return WorkoutWidget(key: Key(workout.id.toString()), workout: workout);
}),
),
],
),
),
Change physics to NeverScrollableScrollPhysics(), then wrap your Container with SingleChildScrollView widget. You could also omit scrollDirection, because Axis.vertical is already the default value.
appBar: AppBar(
title: Text(title),
),
body: SingleChildScrollView(
child: Container(
color: Colors.green,
margin: const EdgeInsets.all(5.0),
child: Column(
children: [
Align(
alignment: Alignment.topLeft,
child: Text(
"Workouts",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 25),
),
),
Expanded(
child: ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: workouts.length,
itemBuilder: (context, index) {
var workout = workouts[index];
return WorkoutWidget(
key: Key(workout.id.toString()),
workout: workout,
);
}),
),
],
),
),
I am trying to wrap some list items in an Expansion panel But the contents are overflowing.
ExpansionTile(
title: Text('Client'),
children: <Widget>[
ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: upComingCompliancesList.length,
itemBuilder: (BuildContext context,int index){
return Container(
margin: EdgeInsets.symmetric(vertical: 10.0),
color: buttonColor,
child: ListTile(
title: Text(upComingCompliancesList[index].name==null? upComingCompliancesList[index].name==null : ' '),
subtitle: Text(
'${upComingCompliancesList[index].label} at ${upComingCompliancesList[index].date}'),
),
);
},
),
],
),
],
),
It is showing the following error:
The following assertion was thrown during layout:
A RenderFlex overflowed by 277 pixels on the bottom.
the following error is shown on the screen:
Try wrapping your ExpansionTile in a scrollable Widget to compensate for its content when the ExpansionTile is in an expanded state. Use 'SingleChildScrollView' like so:
SingleChildScrollView(
child: ExpansionTile(
title: Text('Client'),
children: <Widget>[
ListView(
scrollDirection: Axis.vertical,
shrinkWrap: true,
children: <Widget>[
ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: upComingCompliancesList.length,
itemBuilder: (BuildContext context,int index){
return Container(
margin: EdgeInsets.symmetric(vertical: 10.0),
color: buttonColor,
child: ListTile(
title: Text(upComingCompliancesList[index].name==null? upComingCompliancesList[index].name==null : ' '),
subtitle: Text(
'${upComingCompliancesList[index].label} at ${upComingCompliancesList[index].date}'),
),
);
},
),
],
),
],
),
),
I need to add a ListViewBuilder in ExpansionTile. The expansion tile in the left side drawer. Im new in flutter, i dont know how to add this ? Please help me to fix this ?
drawer: Drawer(
child: Container(
child: ListView(
padding: EdgeInsets.zero,
children: <Widget>[
ListTile(......),
ListTile(......),
ListTile(......),
ExpansionTile(
title: Text(
'Game Rules',
style: TextStyle(color: Colors.white),
),
leading: new IconButton(
icon: new Icon(
Icons.wb_iridescent,
color: Colors.white,
),
),
children: <Widget>[
ListView.builder(
itemCount: _rules.length,
itemBuilder: (context, index) {
return Text(_rules[index]['category']);
})
],
),
]
In your ListView.builder - add - shrinkWrap: true,
ListView.builder(
shrinkWrap: true, // Add this
itemCount: _rules.length,
// itemCount: 10,
itemBuilder: (context, index) {
return Text(_rules[index]['category']);
// return Text('$index');
})
Hello there i am making a flutter application in which inside ScrollView in need to put Expandable list view.First of all here is my build method.
return Scaffold(
appBar: AppBar(
backgroundColor: app_color,
iconTheme: IconThemeData(
color: Colors.white, //change your color here
)),
//debugShowCheckedModeBanner: false,
//key: scaffoldKey,
backgroundColor: app_color,
body: SingleChildScrollView(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children:<Widget>[
Text("Header"),
new ListView.builder(
itemCount: datas.length,
shrinkWrap: true,
itemBuilder: (context, i) {
return new ExpansionTile(
title: new Text(datas[i].title, style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),),
children: <Widget>[
new Column(
children: _buildExpandableContent(datas[i]),
),
],
);
},
),
Text("Footer"),
],
),
)
)
);
}
Now the problem is that without SingleScrollChidView this works fine But after using SingleScrollChidView it does not shows anything and gives error RenderBox was not laid out.What is wrong here ? How can i use Expandable list view inside Singlechildscroll view in flutter.
I was able to achieve Expanded ListView within ScrollView with text by
- Use of Wrap inside SingleChildScrollView, provided you make all ListView using shrinkWrap: true
SingleChildScrollView(
child: Wrap(
direction: Axis.horizontal,
children: <Widget>[
_textBody, // text body, with 1000+ words
Padding(
padding: const EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
ListViewOne(_genericListDataOne()),
],
),
),
Column(
children: <Widget>[
ListViewTwo(_genericListDataTwo())
],
)
],
),
),
part of the Code for ListViewOne
ListViewOne(
shrinkWrap: true,
padding: new EdgeInsets.symmetric(vertical: 8.0),
children: // build list here,
);
Give your ListView a fixed height using SizedBox or similar
SingleChildScrollView(
child: Column(
children: <Widget>[
Text("Header"),// tested with 20 of these for scrolling
SizedBox(
height: MediaQuery.of(context).size.height / 2,
child: new ListView.builder(
itemCount: 20,
shrinkWrap: true,
itemBuilder: (context, i) {
return new ExpansionTile(/* whatever */ );
},
),
),
Text("Footer"),// tested with 20 of these for scrolling
],
),
)
Use SizedBox.expand for this problem,
SizedBox.expand(
child : ListView.builder(
itemCount: datas.length,
shrinkWrap: true,
itemBuilder: (context, i) {
return new ExpansionTile(
title: new Text(datas[i].title, style: new TextStyle(fontSize: 20.0, fontWeight: FontWeight.bold, fontStyle: FontStyle.italic),),
children: <Widget>[
new Column(
children: _buildExpandableContent(datas[i]),
),
],
);
},
),
);
Edited answer
Try this, you should get the desired output you are looking for.
You can find the output here.
Column(
children: <Widget>[
Text(),
ListView(
shrinkWrap: true,
physics: ScrollPhysics(),
children:[]),
Text()
]
)
adding below shown code in ListView will allow smooth scrolling of widget
shrinkWrap: true,
physics: ScrollPhysics(),