button_primary.dart 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import 'package:flutter/material.dart';
  2. import 'package:sport/widgets/misc.dart';
  3. class PrimaryButton extends StatelessWidget {
  4. final VoidCallback callback;
  5. final String content;
  6. final double width;
  7. final double height;
  8. final double fontSize;
  9. final Widget child;
  10. final bool shadow;
  11. final bool bold;
  12. final Color buttonColor;
  13. PrimaryButton({
  14. @required this.callback,
  15. @required this.content,
  16. this.child,
  17. this.width = double.infinity,
  18. this.height = 44,
  19. this.fontSize = 28,
  20. this.shadow = true,
  21. this.bold = false,
  22. this.buttonColor,
  23. });
  24. @override
  25. Widget build(BuildContext context) {
  26. return InkWell(
  27. onTap: callback,
  28. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  29. child: Container(
  30. width: width,
  31. height: height,
  32. alignment: Alignment.center,
  33. decoration: callback == null
  34. ? BoxDecoration(
  35. color: Color(0xffdcdcdc),
  36. shape: BoxShape.rectangle,
  37. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  38. )
  39. : shadow
  40. ? BoxDecoration(
  41. shape: BoxShape.rectangle,
  42. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  43. boxShadow: [
  44. BoxShadow(
  45. offset: Offset(0.0, 3),
  46. blurRadius: 3,
  47. spreadRadius: 0,
  48. color: Color(0x82FF9100))
  49. ],
  50. gradient: LinearGradient(
  51. begin: Alignment.topCenter,
  52. end: Alignment.bottomCenter,
  53. colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
  54. ),
  55. )
  56. : buttonColor != null
  57. ? BoxDecoration(
  58. color: buttonColor,
  59. shape: BoxShape.rectangle,
  60. borderRadius:
  61. BorderRadius.all(Radius.circular(height / 2)),
  62. )
  63. : BoxDecoration(
  64. shape: BoxShape.rectangle,
  65. borderRadius:
  66. BorderRadius.all(Radius.circular(height / 2)),
  67. gradient: LinearGradient(
  68. begin: Alignment.topCenter,
  69. end: Alignment.bottomCenter,
  70. colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
  71. ),
  72. ),
  73. child: content?.isNotEmpty == true
  74. ? Text(
  75. content,
  76. style: TextStyle(
  77. color: Colors.white,
  78. fontSize:
  79. height > 40 ? callback == null ? 14.0 : 16.0 : 14.0,
  80. fontWeight: bold ? FontWeight.w600 : FontWeight.normal),
  81. strutStyle: fixedLine,
  82. )
  83. : child,
  84. ),
  85. );
  86. }
  87. }