gradient_button.dart 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/theme/ente_theme.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 as void Function()?,
  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: onTap != null
  68. ? linearGradientColors
  69. : [
  70. getEnteColorScheme(context).fillMuted,
  71. getEnteColorScheme(context).fillMuted
  72. ],
  73. ),
  74. borderRadius: BorderRadius.circular(8),
  75. ),
  76. child: Center(child: buttonContent),
  77. ),
  78. );
  79. }
  80. }