I'm trying to fix vertical overflow using the SingleChildScrollView but it gives me the error: "FlutterError (RenderFlex children have non-zero flex but incoming height constraints are unbounded. When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction. These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent. Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent. "
I have tried using Expanded and MainAxisSize.min to no avail.
This is my code:
Widget build(BuildContext context) {
double altezza = MediaQuery.of(context).size.height;
return SingleChildScrollView(
child: Column(
children: <Widget>[
Column(
children: <Widget>[
altezza > 750 && valoreCheckAbbuonoOre == false
? SizedBox(height: altezza / 9)
: altezza > 750 && valoreCheckAbbuonoOre == true
? SizedBox(height: altezza / 11)
: SizedBox(height: altezza / 15),
Text("Rapporto di $meseAttuale $annoAttuale",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 21)),
SizedBox(height: 20),
GestureDetector(
onTap: () {
click(1);
},
child: Text("Visualizza rapporto precedente",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16,
color: Colors.blue[900])),
),
SizedBox(height: 20),
TabellaStatica(visualizzaRapporto, "attuale"),
SizedBox(height: 20),
obiettivo != 0 && obiettivo != null
? Text("$testoObiettivo",
style: plus != null
? TextStyle(
color: Colors.green,
fontSize: 15,
fontWeight: FontWeight.bold)
: deficit != null
? TextStyle(
color: Colors.red,
fontSize: 15,
fontWeight: FontWeight.bold)
: TextStyle(
color: Colors.green,
fontSize: 15,
fontWeight: FontWeight.bold))
: SizedBox(),
SizedBox(height: 10),
IconButton(
icon: new Icon(
Icons.whatsapp,
color: Colors.green,
size: 30,
),
onPressed: () async {
inviaWhatsapp();
},
),
],
),
Spacer(),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
MaterialButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
AggiungiServizio(visualizzaRapporto)),
);
},
shape: CircleBorder(),
color: Colors.blue[900],
padding: EdgeInsets.all(10),
child: const Icon(
Icons.add,
size: 30,
color: Colors.white,
),
),
],
),
SizedBox(height: 20),
],
),
);
}
}
CodePudding user response:
Remove Spacer and try again, Spacer can't be used with SingleChildScrollView