Reputation:
I hope the title is enough to understand what my problem is, how do i display the value of button in TextField when it is clicked? thank you in advance whoever will help me to configure this problem.
TextEditingController _controller;
void initState() {
_controller = new TextEditingController(text: '${formatCurrency.format(totalbet)}');
}
child: TextField(
controller: _controller,
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: globals.fontsize_28,
color: Colors.black,
fontWeight: FontWeight.bold,
fontFamily: "Nunito",
),
decoration: new InputDecoration(
contentPadding: EdgeInsets.zero,
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
)
button
child: FlatButton(
child: Container(
child: RichText(
text: TextSpan(
text: "500",
style: TextStyle(
fontSize: globals.fontsize_18,
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
),
onPressed: () {
setState(() {
if (betbuttonstate[0] == false) {
betbuttonstate[0] = true;
totalbet = totalbet + betbuttonvalue[0];
totalmoney = totalmoney - betbuttonvalue[0];
} else {
betbuttonstate[0] = false;
totalbet = totalbet - betbuttonvalue[0];
totalmoney = totalmoney + betbuttonvalue[0];
}
});
},
),
Upvotes: 0
Views: 69
Reputation: 671
Change value by controller _controller.text = newValue
in button's on press setState() like this.
onTap: (){
setState((){
_controller.text=newValue
});
}
Upvotes: 1
Reputation: 2529
onPressed
method of the button setState(() {
if (betbuttonstate[0] == false) {
betbuttonstate[0] = true;
totalbet = totalbet + betbuttonvalue[0];
totalmoney = totalmoney - betbuttonvalue[0];
} else {
betbuttonstate[0] = false;
totalbet = totalbet - betbuttonvalue[0];
totalmoney = totalmoney + betbuttonvalue[0];
}
_controller.text = '${formatCurrency.format(totalbet)}';
initState
should look like this @override
void initState() {
super.initState();
_controller =
new TextEditingController(text: '${formatCurrency.format(totalbet)}');
}
Upvotes: 0