gradient_button.dart 2.2 KB

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