button_primary.dart 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import 'dart:ui';
  2. import 'package:flutter/material.dart';
  3. import 'package:sport/widgets/misc.dart';
  4. class PrimaryButton extends StatelessWidget {
  5. final VoidCallback? callback;
  6. final String content;
  7. final double width;
  8. final double height;
  9. final double? fontSize;
  10. final Widget? child;
  11. final bool shadow;
  12. final bool bold;
  13. final Color? buttonColor;
  14. final Key? key;
  15. PrimaryButton({
  16. required this.callback,
  17. required this.content,
  18. this.child,
  19. this.width = double.infinity,
  20. this.height = 35,
  21. this.fontSize,
  22. this.shadow = true,
  23. this.bold = false,
  24. this.buttonColor, this.key,
  25. });
  26. @override
  27. Widget build(BuildContext context) {
  28. final height = this.height;
  29. return Container(
  30. width: width,
  31. height: height,
  32. decoration: callback == null
  33. ? BoxDecoration(
  34. color: Color(0xffdcdcdc),
  35. shape: BoxShape.rectangle,
  36. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  37. )
  38. : shadow
  39. ? BoxDecoration(
  40. shape: BoxShape.rectangle,
  41. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  42. boxShadow: [BoxShadow(offset: Offset(0.0, 3), blurRadius: 3, spreadRadius: 0, color: Color(0x82FF9100))],
  43. gradient: LinearGradient(
  44. begin: Alignment.topCenter,
  45. end: Alignment.bottomCenter,
  46. colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
  47. ),
  48. )
  49. : buttonColor != null
  50. ? BoxDecoration(
  51. color: buttonColor,
  52. shape: BoxShape.rectangle,
  53. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  54. )
  55. : BoxDecoration(
  56. shape: BoxShape.rectangle,
  57. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  58. gradient: LinearGradient(
  59. begin: Alignment.topCenter,
  60. end: Alignment.bottomCenter,
  61. colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
  62. ),
  63. ),
  64. child: ElevatedButton(
  65. onPressed: () {
  66. this.callback?.call();
  67. },
  68. child: content.isNotEmpty == true
  69. ? Text(
  70. content,
  71. style: Theme.of(context).textTheme.subtitle1!.copyWith(
  72. color: Colors.white,
  73. fontSize: fontSize != null
  74. ? fontSize
  75. : height >= 40
  76. ? callback == null
  77. ? 14.0
  78. : 16.0
  79. : 14.0,
  80. fontWeight: bold ? FontWeight.w600 : FontWeight.normal,),
  81. )
  82. : child,
  83. style: ButtonStyle(
  84. padding: MaterialStateProperty.all(EdgeInsets.zero),
  85. elevation: MaterialStateProperty.all(0),
  86. shape: MaterialStateProperty.all(StadiumBorder()),
  87. backgroundColor: MaterialStateProperty.all(Colors.transparent),
  88. ),
  89. ));
  90. }
  91. }
  92. class MainButton extends StatelessWidget {
  93. final VoidCallback callback;
  94. final String content;
  95. final double width;
  96. final double height;
  97. final double? fontSize;
  98. final Widget? child;
  99. final bool shadow;
  100. final bool bold;
  101. final Color? buttonColor;
  102. final Color? textColor;
  103. final String type; // cancel or confirm
  104. MainButton({
  105. required this.callback,
  106. required this.content,
  107. required this.type,
  108. this.child,
  109. this.width = double.infinity,
  110. this.height = 44,
  111. this.fontSize,
  112. this.shadow = true,
  113. this.bold = false,
  114. this.buttonColor,
  115. this.textColor,
  116. });
  117. @override
  118. Widget build(BuildContext context) {
  119. BoxDecoration cancelDecoration = BoxDecoration(
  120. color: buttonColor,
  121. shape: BoxShape.rectangle,
  122. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  123. boxShadow: [BoxShadow(offset: Offset(0.0, 3), blurRadius: 3, spreadRadius: 0, color: Color(0xffF1F1F1))],
  124. gradient: LinearGradient(
  125. begin: Alignment.topCenter,
  126. end: Alignment.bottomCenter,
  127. colors: <Color>[Color(0xffF0F0F0), Color(0xffF6F6F6)],
  128. ),
  129. );
  130. BoxDecoration confirmDecoration = BoxDecoration(
  131. color: buttonColor,
  132. shape: BoxShape.rectangle,
  133. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  134. boxShadow: buttonColor == null ? [BoxShadow(offset: Offset(0.0, 3), blurRadius: 3, spreadRadius: 0, color: Color(0x82FF9100))] : null,
  135. gradient: buttonColor == null
  136. ? LinearGradient(
  137. begin: Alignment.topCenter,
  138. end: Alignment.bottomCenter,
  139. colors: <Color>[Color(0xffFFC400), Color(0xffFFAA00)],
  140. )
  141. : null,
  142. );
  143. var map = {
  144. "cancel": cancelDecoration,
  145. "confirm": confirmDecoration,
  146. };
  147. return InkWell(
  148. onTap: callback,
  149. borderRadius: BorderRadius.all(Radius.circular(height / 2)),
  150. child: Container(
  151. width: width,
  152. height: height,
  153. alignment: Alignment.center,
  154. decoration: map['$type'],
  155. child: content.isNotEmpty == true
  156. ? Text(
  157. content,
  158. style: Theme.of(context).textTheme.subtitle1!.copyWith(
  159. color: textColor != null ? textColor : Colors.white,
  160. fontSize: fontSize != null
  161. ? fontSize
  162. : height >= 40
  163. ? callback == null
  164. ? 14.0
  165. : 16.0
  166. : 14.0,
  167. fontWeight: bold ? FontWeight.w600 : FontWeight.normal,
  168. height: 1.1),
  169. )
  170. : child,
  171. ),
  172. );
  173. }
  174. }