gsy_flex_button.dart 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 new ElevatedButton(
  22. style: TextButton.styleFrom(
  23. backgroundColor: color,
  24. padding: new EdgeInsets.only(
  25. left: 20.0, top: 10.0, right: 20.0, bottom: 10.0)),
  26. child: new Flex(
  27. mainAxisAlignment: mainAxisAlignment,
  28. direction: Axis.horizontal,
  29. children: <Widget>[
  30. new Expanded(
  31. child: new Text(text!,
  32. style: new TextStyle(
  33. color: textColor, fontSize: fontSize, height: 1),
  34. textAlign: TextAlign.center,
  35. maxLines: maxLines,
  36. overflow: TextOverflow.ellipsis),
  37. )
  38. ],
  39. ),
  40. onPressed: () {
  41. this.onPress?.call();
  42. });
  43. }
  44. }