I was trying to make a button that adds new widget to my screen .
I'm putting my Builder
inside an Expanded
widget and a FloatingactionButton
below that called the method _addCardWidget()
This is my Statefull screen :
/* Import */
class ajouterUnDocument extends StatefulWidget {
@override
State<ajouterUnDocument> createState() => _ajouterUnDocumentState();
}
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
class _ajouterUnDocumentState extends State<ajouterUnDocument> {
List<Widget> _cardList = [(InputRefNomProduit()), (InputRefNomProduit())];
void _addCardWidget() {
setState(() {
_cardList.add(InputRefNomProduit());
_cardList.add(InputQuntitePrixProduit());
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xFF2A2D3E),
body: Form(
key: _formKey,
child: Card(
shadowColor: Color.fromARGB(255, 255, 255, 255),
color: Color(0xFF2A2D3E),
shape:
RoundedRectangleBorder(borderRadius: BorderRadius.circular(40.0)),
elevation: 10.0,
child: Container(
width: 1800,
child: Column(
children: <Widget>[
Center(
child: Container(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text(
"AJOUTER UN DOCUMENT",
style: TextStyle(
fontSize: 30, fontWeight: FontWeight.bold),
),
Divider(
thickness: 3,
),
Row(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Column(
children: [
SizedBox(height: 20.0),
ListView.builder(
itemCount: _cardList.length,
itemBuilder: (context, index) {
return _cardList[index];
}),
SizedBox(height: 20.0),
],
),
),
Row(
children: <Widget>[
SizedBox(
width: 370.0,
),
MaterialButton(
color: Colors.grey[200],
onPressed: () {},
child: Text(
"Annuler",
style: TextStyle(color: Colors.black),
),
),
SizedBox(
width: 20.0,
),
MaterialButton(
color: Color.fromARGB(255, 75, 100, 211),
onPressed: () {
_addCardWidget();
},
child: Text(
"Ajouter une nouvelle ligne",
style: TextStyle(color: Colors.white),
),
),
SizedBox(
width: 20.0,
),
);
}
},
),
],
),
],
),
),
),
],
),
),
),
),
floatingActionButton: FloatingActionButton(
onPressed: _addCardWidget,
tooltip: 'Add',
child: Icon(Icons.add),
),
);
}
}
Now , all i'm getting is a blank screen and my Debug Console
is showing these error :
`Scaffold
lib\…\Screen\ajouterunDct.dart:61
════════════════════════════════════════════════════════════════════════════════
════════ Exception caught by rendering library ═════════════════════════════════
Assertion failed:
D:\…\rendering\box.dart:1982
hasSize
"RenderBox was not laid out: RenderPhysicalShape#6d64a relayoutBoundary=up8"
The relevant error-causing widget was
Card
lib\…\Screen\ajouterunDct.dart:65
═════`
Assertion failed:
D:\…\rendering\box.dart:1982
hasSize
"RenderBox was not laid out: RenderSemanticsAnnotations#95d37 relayoutBoundary=up6 NEEDS-PAINT"
The relevant error-causing widget was
Scaffold
lib\…\Screen\ajouterunDct.dart:61
════════════════════════════════════════════════════════════════════════════════
CodePudding user response:
Wrap the form with SafeArea() then it should display unter the noth of the phone. Or wrap the Form with Expanded()
CodePudding user response:
Surround your listview.builder with expanded widget and add the flex property of the expanded widget to 1. This will solve the problem with the listview.
CodePudding user response:
Wrap it inside the Container or Sized box, Assign certain height and it should work!