I have TextFild and ElevatedButton, by default TextFild is empty and ElevatedButton has one color set, when entering some text, I would like to change the color of ElevatedButton to another. I tried to write a condition for this, where the variable would change depending on the state, but MaterialStateProperty does not work with Color, and declaring it Final I cannot change it. How do I declare a variable to work with MaterialStateProperty ?
final _textController = TextEditingController();
void _login (){
final worldColor = _textController.text;
if (worldColor == null){
} else {
setState(() {
});
}
}
@override
Widget build(BuildContext context) {
final colorButton = MaterialStateProperty.all (Color.fromARGB(255, 157, 186, 219));
final decorationRow = const InputDecoration(border: OutlineInputBorder(), contentPadding: EdgeInsets.symmetric(horizontal: 10, vertical: 10), isCollapsed: true, hintText: "Email",filled: true, fillColor: Color.fromARGB(255, 236, 236, 236), hintStyle: TextStyle(fontSize: 15, color: Color.fromARGB(255, 145, 144, 144)), );
final richBotton = const TextStyle(color: Color.fromARGB(255, 117, 117, 117), fontSize: 11,); // textAlign: TextAlign.center;
final text = const TextStyle(color: Colors.grey, fontSize: 11);
return Padding(
padding: const EdgeInsets.symmetric(vertical: 15),
child: Column(
children: [
TextField(controller: _textController,decoration: decorationRow,),
SizedBox(height: 15),
ElevatedButton(
onPressed: () {
setState(() {
colorButton = MaterialStateProperty.all (Color.fromARGB(255, 157, 186, 219));
});
},
style: ButtonStyle(backgroundColor: colorButton, minimumSize: MaterialStateProperty.all (Size.fromHeight(1)),
foregroundColor: MaterialStateProperty.all (Colors.white),
textStyle: MaterialStateProperty.all (
TextStyle(
fontSize: 16, fontWeight: FontWeight.w500)),
padding: MaterialStateProperty.all (EdgeInsets.symmetric(horizontal: 10, vertical: 10))),
child: Text ('Next')),