Home > Back-end >  How does flutter update state when it's in the build method versus when it's a field varia
How does flutter update state when it's in the build method versus when it's a field varia

Time:05-12

i have a stateless Widget and in it a textfield, now I am storing the onChanged value of the textfield in a variable String? newValue; because it's a stateless widget, I must mark it as final, however, if it's marked final, then I can't use it as a setter, to do,

onChanged: (value) {
  newValue = value;
}  

what I did was I put it in the build() method, so

Widget build(BuildContext context) {
  String? newValue;
return Container();
}  

now I can use it as a setter, OR SO I THOUGHTTTT

  • Related