Reputation: 1838
I want to update the value of text widget on click on button.
here is my code
Widget text(){
if(workinghours=="0" || gettimeinworkinghours=="0"){
if(gettimeinworkinghours=="0"){
totalWorkingHours();
setState(() { //here i am using setstate
return Text(gettimeoutworkinghours,style: TextStyle(
color: fontcolor,
fontSize: remainingtextfontsize,
fontFamily: fontFamily));
});
}
else if(workinghours=="0"){
totalWorkingHours();
return Text(totalTime,style: TextStyle(
color: fontcolor,
fontSize: remainingtextfontsize,
fontFamily: fontFamily)); }
}
else{
return Text(workinghours,style: TextStyle(
color: fontcolor,
fontSize: remainingtextfontsize,
fontFamily: fontFamily));
}
return Text(gettimeoutworkinghours,style: TextStyle(
color: fontcolor,
fontSize: remainingtextfontsize,
fontFamily: fontFamily));
}
i want to update the text widget value to gettimeoutworkinghours
value, it is working when i press ctrl+s (save), it updates the value but i want to update it automatically, i used setState fo this but that is not working, i call the text() in initState() but it is not working, kindly please help how to do this.
Upvotes: 0
Views: 654
Reputation: 332
So you are calling the text() in initState(). initState() is only called one time when the widget is loaded for the first time. setState doesn't invoke initState() again
Upvotes: 1
Reputation: 379
Upvotes: 2