gsy_flex_button.dart 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import 'package:flutter/material.dart';
  2. class GSYFlexButton extends StatelessWidget {
  3. final String? text;
  4. final Color? color;
  5. final Color textColor;
  6. final VoidCallback? onPress;
  7. final double fontSize;
  8. final int maxLines;
  9. final MainAxisAlignment mainAxisAlignment;
  10. GSYFlexButton(
  11. {Key? super.key,
  12. this.text,
  13. this.color,
  14. this.textColor = Colors.black,
  15. this.onPress,
  16. this.fontSize = 20.0,
  17. this.mainAxisAlignment = MainAxisAlignment.center,
  18. this.maxLines = 1});
  19. @override
  20. Widget build(BuildContext context) {
  21. return ElevatedButton(
  22. style: ButtonStyle(
  23. backgroundColor: MaterialStateProperty.all(color),
  24. shape: MaterialStateProperty.all(
  25. RoundedRectangleBorder(
  26. borderRadius:
  27. BorderRadius.circular(
  28. 25))),
  29. padding: MaterialStateProperty.all( const EdgeInsets.only(
  30. left: 20.0, top: 10.0, right: 20.0, bottom: 10.0))),
  31. child: Flex(
  32. mainAxisAlignment: mainAxisAlignment,
  33. direction: Axis.horizontal,
  34. children: <Widget>[
  35. Expanded(
  36. child: Text(text!,
  37. style: TextStyle(
  38. color: textColor, fontSize: fontSize, height: 1,fontWeight: FontWeight.bold,letterSpacing:2),
  39. textAlign: TextAlign.center,
  40. maxLines: maxLines,
  41. overflow: TextOverflow.ellipsis),
  42. )
  43. ],
  44. ),
  45. onPressed: () {
  46. this.onPress?.call();
  47. });
  48. }
  49. }