I have a simple widget, using Provider and trying to understand why it will not rebuild.
From my understanding (obviously wrong) because my widget is 'watching' postCode on the AddressViewModel, when changing the value as below, my widgets build method should be called and the widget rebuilt. What am I missing here? Why does context.watch not do as i expect and rebuild?
@override
Widget build(BuildContext context) {
var addressViewModel = Provider.of<AddressViewModel>(context);
return Container(
child: Column(
children: [
Text(context.watch<AddressViewModel>().postCode),
TextFormField(
onChanged: (value) {
//should this trigger rebuild? If not, why not as I am watching this above.
addressViewModel.postCode = "a new value";
//if I do setState(){} here, then it does rebuild, but should this rebuild without
//this as I am watching the postCode value above?
},
),
],
),
);
}
}