gradient_button.dart 2.0 KB

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