Set the background color of the button according to the content of the text box.
var _amountChanged = false;
TextButton(
  style: ButtonStyle(backgroundColor: createTextBtnBgColor()),
  autofocus: false,
  onPressed: _amountChanged ? () {} : null,
  child: const Text(
    "Confirmed withdrawal",
    style: TextStyle(
      color: Colors.white,
    ),
  ),
)
Copy the code

/// Handles click button background color
/// When setting the current button to unclickable, set the onPressed callback to NULL.
MaterialStateProperty<Color> createTextBtnBgColor() {
  return MaterialStateProperty.resolveWith((states) {
// If the button is pressed, return green, otherwise blue
    if (states.contains(MaterialState.pressed)) { 
      return "#ff063c91".toColor();
    } else if (states.contains(MaterialState.disabled)) {
      return "#509cf6".toColor();
    }
    return "#FF208FF9".toColor(); ///Extension String function
  });
}
Copy the code
Extension String function
extension String2Color on String {
  Color toColor() {
    final buffer = StringBuffer(a);if (length == 6 || length == 7) buffer.write('ff');
    buffer.write(replaceFirst(The '#'.' '));
    return Color(int.parse(buffer.toString(), radix: 16)); }}Copy the code