BZButton constructor

BZButton({
  1. Key? key,
  2. required String text,
  3. bool enabled = true,
  4. VoidCallback? onPressed,
  5. Color? enabledColor,
  6. Color? disabledColor,
  7. Color? enabledTextColor,
  8. Color? disabledTextColor,
  9. ButtonStyle style = const ButtonStyle(),
})

Implementation

BZButton({
  Key? key,
  required String text,
  this.enabled = true,
  this.onPressed,
  this.enabledColor,
  this.disabledColor,
  this.enabledTextColor,
  this.disabledTextColor,
  ButtonStyle style = const ButtonStyle(),
}) : super(
        key: key,
        onPressed: enabled ? onPressed : null,
        style: style.copyWith(
          backgroundColor: MaterialStateProperty.resolveWith<Color>(
            (states) {
              if (states.contains(MaterialState.disabled)) {
                return disabledColor ?? Colors.grey;
              }
              return enabledColor ?? Colors.purple;
            },
          ),
          foregroundColor: MaterialStateProperty.resolveWith<Color>(
            (states) {
              if (states.contains(MaterialState.disabled)) {
                return disabledTextColor ?? Colors.white54;
              }
              return enabledTextColor ?? Colors.white;
            },
          ),
        ),
        child: Text(
          text,
          style: TextStyle(
            color: enabled
                ? (enabledTextColor ?? Colors.white)
                : (disabledTextColor ?? Colors.white54),
            fontSize: 16,
          ),
        ),
      );