Reputation: 349
I tried to add a RaisedButton
above the ListView
. I used a Colum
but I got an error. Can anybody tell me where my mistake is? Thanks in advance!
body: Column(
children: <Widget>[
RaisedButton(
child: Text("Test"),
onPressed: null,
),
ListView.builder(
itemCount: exercises.length,
itemBuilder: (context, i) {
return Container(
child: Text(
exercises[i]["text"],
),
);
},
),
],
),
Upvotes: 1
Views: 872
Reputation: 34210
Adding to @Viren answer, You should use Flexible instead of Expanded
body: Column(
children: <Widget>[
RaisedButton(
child: Text("Test"),
onPressed: null,
),
Flexible(
child: Container(
child: ListView.builder(
itemCount: 5,
itemBuilder: (context, i) {
return Container(
child: Text(
'jitesh',
),
);
},
),
),
)
],
),
Please find diff Flutter: Expanded vs Flexible
Upvotes: 2
Reputation: 27137
You need to wrap your listview with Expanded widget.
body: Column(
children: <Widget>[
RaisedButton(
child: Text("Test"),
onPressed: null,
),
Expanded( // added widget
child: ListView.builder(
itemCount: exercises.length,
itemBuilder: (context, i) {
return Container(
child: Text(
exercises[i]["text"],
),
);
},
),
],
),
)
Upvotes: 1