gradient_button.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @dart=2.9
  2. import 'package:flutter/material.dart';
  3. class GradientButton extends StatelessWidget {
  4. final List<Color> linearGradientColors;
  5. final Function onTap;
  6. // text is ignored if child is specified
  7. final String text;
  8. // nullable
  9. final IconData iconData;
  10. // padding between the text and icon
  11. final double paddingValue;
  12. const GradientButton({
  13. Key key,
  14. this.linearGradientColors = const [
  15. Color(0xFF2CD267),
  16. Color(0xFF1DB954),
  17. ],
  18. this.onTap,
  19. this.text = '',
  20. this.iconData,
  21. this.paddingValue = 0.0,
  22. }) : super(key: key);
  23. @override
  24. Widget build(BuildContext context) {
  25. Widget buttonContent;
  26. if (iconData == null) {
  27. buttonContent = Text(
  28. text,
  29. style: const TextStyle(
  30. color: Colors.white,
  31. fontWeight: FontWeight.w600,
  32. fontFamily: 'Inter-SemiBold',
  33. fontSize: 18,
  34. ),
  35. );
  36. } else {
  37. buttonContent = Row(
  38. mainAxisAlignment: MainAxisAlignment.center,
  39. crossAxisAlignment: CrossAxisAlignment.center,
  40. children: [
  41. Icon(
  42. iconData,
  43. size: 20,
  44. color: Colors.white,
  45. ),
  46. const Padding(padding: EdgeInsets.symmetric(horizontal: 6)),
  47. Text(
  48. text,
  49. style: const TextStyle(
  50. color: Colors.white,
  51. fontWeight: FontWeight.w600,
  52. fontFamily: 'Inter-SemiBold',
  53. fontSize: 18,
  54. ),
  55. ),
  56. ],
  57. );
  58. }
  59. return InkWell(
  60. onTap: onTap,
  61. child: Container(
  62. height: 56,
  63. decoration: BoxDecoration(
  64. gradient: LinearGradient(
  65. begin: const Alignment(0.1, -0.9),
  66. end: const Alignment(-0.6, 0.9),
  67. colors: linearGradientColors,
  68. ),
  69. borderRadius: BorderRadius.circular(8),
  70. ),
  71. child: Center(child: buttonContent),
  72. ),
  73. );
  74. }
  75. }