The code below is a simplification of my project.
I want it make like: When you push the button, text is rebuilt and increase the number.
However, text isn't reloaded. but I detected that the number of count is actualy increased.
Why this text isn't reloaded? Some way to detect changes of other classes?
class CLS extends ChangeNotifier{
int count = 0;
void add(int i){
count += i;
notifyListeners();
}
}
....
class Main extends StatelessWidget{
Widget txt(){
return Consumer<CLS>(
builder: (context, value, _) => Text(value.count.ToString())
);
}
Widget but(int i){
return ElevatedButton(
child: Text("Button"),
onPressed: context.read<CLS>().add(i)
);
}
@override
Widget build(BuildContext context){
return Scaffold(
body: ChangeNotifierProvider(
create: (BuildContext context) => CLS(),
child: Column( children: [
txt(),
but(1)
]));
}
}