I want to hide/show TextField
. If TextField
show, Text
hide…
I’ve code like bellow. But it not working and no any error…
Bellow is my reference code
AlertDialog alert = AlertDialog(
title: Container(
color: Color.fromARGB(255, 8, 8, 8),
child: Text('Submit',
textAlign: TextAlign.center,
style: TextStyle(color: Color.fromARGB(255, 250, 251, 250))),
padding: const EdgeInsets.all(17),
margin: const EdgeInsets.all(0),
),
titlePadding: const EdgeInsets.all(0),
content: Container(
child: Column(mainAxisSize: MainAxisSize.min, children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
ElevatedButton(
onPressed: () {
setState(() {
isRevert = !isRevert;
});
print(isRevert);
},
child: Text('Show Comment'),
style: ElevatedButton.styleFrom(
primary: Colors.grey.shade100,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
Text("*please click here to write comment."),
],
),
Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
!isRevert ?
Text("Would you like to submit?") :
Container(
padding: EdgeInsets.all(0),
child: Column(
children: [
TextField(
decoration: new InputDecoration(
border: OutlineInputBorder(),
),
controller: TextEditingController(text: "test comment"),
textAlign: TextAlign.left,
maxLines: 6,
style: TextStyle(fontSize: 15, fontWeight: FontWeight.normal),
),
],
),
),
],
),
])),
actions: [
yesButton,
noButton,
],
);
2
Answers
Try below code and Wrap your AlertDialog inside
StatefulBuilder
Result before button click->
Result after button click->
Check this code