I'm using Provider and trying to make buttons disable without StatfulWidgets. But I can't find the way to do it.
What I did:
class CLS with ChangeNotifier {
bool pressed = false;
bool detect(return pressed;);
void pressed(pressed = true;)
}
....
//StatelessWidget
ElevatedButton(
...
onPressed: Provider.of<CLS>(context, listen: false).detect()
? null : context.read<CLS>().pressed(),
...
)
I know buttons are disabled when onPressed
is null. So I want to make it dynamicaly, but buttons color is not changed. CLS.pressed
becomes true
when button is pressed.
What sohould I do?