I constantly get this error: " RenderBox was not laid out: RenderViewport#a3518 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE 'package:flutter/src/rendering/box.dart': Failed assertion: line 1785 pos 12: 'hasSize' " when I run this code:
(What I need is to have the 'Container' before the 'FutureBuilder', and the 'RaisedButton' after it because the 'FutureBuilder' can run multiple times, and I need just ONE container and ONE RaisedButton).
Please help me out!
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text(
'OrderLunch',
style: TextStyle(
fontSize: 26.0,
fontWeight: FontWeight.bold,
),
),
centerTitle: true,
),
body: Container(
height: 595,
width: 800,///not accurate
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/portocale.jpg'),
),
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
child: Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
width: 3.5,
color: Colors.blue[400],
),
borderRadius: BorderRadius.all(
Radius.circular(20),
),
color: Colors.white,
),
//padding: EdgeInsets.all(8),
//color: Colors.white,
child: Text(
'copil/copii:',
style: TextStyle(
color: Colors.black.withOpacity(1),
fontWeight: FontWeight.bold,
fontSize: 23.0,
),
),
),
FutureBuilder(
future: getMethod(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
List snap = snapshot.data;
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
if (snapshot.hasError) {
return Center(
child: Text('Error fatching Data'),
);
}
return ListView.builder(
itemCount: snap.length,
itemBuilder: (context, index) {
return ListTile(
title: Column(
children: [
SizedBox(height: 50.0),
Row(
children: [
Text(' '),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(4),
),
color: Colors.white,
),
child: Text(
"${snap[index]['elevNume']} ${snap[index]['elevPrenume']}:",
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.black,
fontSize: 22.0,
),
),
),
],
),
Row(
children: [
Text(' '),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(4),
),
color: Colors.white,
),
child: Text(
'Ii se va comanda maine mancare:',
style: TextStyle(
color: Colors.black,
fontSize: 17.0,
),
),
),
Text(' '),
_buildFirstDate(),
],
),
SizedBox(height: 300.0),
],
),
);
},
);
},
),
RaisedButton(
color: Colors.blue[400],
child: Text(
'Save changes',
style: TextStyle(
fontSize: 19.0,
),
),
onPressed: (){
updateMethod();
if(b==1){
Text(
'Changes have been successfully saved!!',
style: TextStyle(
fontSize: 20.0,
),
);
print(':)');
b=0;
}
},
),
],
),
),
);
}
}
But when I run this one I get no errors:
(But like I've said before, this is not what I need because the 'FutureBuilder' can run multiple times, but I don't want my 'Container', and my 'RaisedButton' to be shown more then one time)
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text(
'OrderLunch',
style: TextStyle(
fontSize: 26.0,
fontWeight: FontWeight.bold,
),
),
centerTitle: true,
),
body: Container(
height: 595,
width: 800,///not accurate
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/portocale.jpg'),
),
borderRadius: BorderRadius.all(Radius.circular(8.0)),
),
child: FutureBuilder(
future: getMethod(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
List snap = snapshot.data;
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: CircularProgressIndicator(),
);
}
if (snapshot.hasError) {
return Center(
child: Text('Error fatching Data'),
);
}
return ListView.builder(
itemCount: snap.length,
itemBuilder: (context, index) {
return ListTile(
title: Column(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
width: 3.5,
color: Colors.blue[400],
),
borderRadius: BorderRadius.all(
Radius.circular(20),
),
color: Colors.white,
),
//padding: EdgeInsets.all(8),
//color: Colors.white,
child: Text(
'copil/copii:',
style: TextStyle(
color: Colors.black.withOpacity(1),
fontWeight: FontWeight.bold,
fontSize: 23.0,
),
),
),
SizedBox(height: 50.0),
Row(
children: [
Text(' '),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(4),
),
color: Colors.white,
),
child: Text(
"${snap[index]['elevNume']} ${snap[index]['elevPrenume']}:",
style: TextStyle(
decoration: TextDecoration.underline,
color: Colors.black,
fontSize: 22.0,
),
),
),
],
),
Row(
children: [
Text(' '),
Container(
decoration: BoxDecoration(
border: Border.all(
width: 4,
color: Colors.white,
),
borderRadius: BorderRadius.all(
Radius.circular(4),
),
color: Colors.white,
),
child: Text(
'Ii se va comanda maine mancare:',
style: TextStyle(
color: Colors.black,
fontSize: 17.0,
),
),
),
Text(' '),
_buildFirstDate(),
],
),
SizedBox(height: 300.0),
RaisedButton(
color: Colors.blue[400],
child: Text(
'Save changes',
style: TextStyle(
fontSize: 19.0,
),
),
onPressed: (){
updateMethod();
if(b==1){
Text(
'Changes have been successfully saved!!',
style: TextStyle(
fontSize: 20.0,
),
);
print(':)');
b=0;
}
},
),
],
),
);
},
);
},
),
),
);
}
}
You're trying to use ListView.builder
in a FutureBuilder
which has no sizes in a Column
, so you need to constrain it somehow – either with SizedBox(height: 300, child: ListView.builder())
or with Expanded
widget
Check out this article https://flutter.dev/docs/development/ui/layout/constraints
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With