blur_menu_item_widget.dart 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/theme/ente_theme.dart';
  3. class BlurMenuItemWidget extends StatefulWidget {
  4. final IconData? leadingIcon;
  5. final String? labelText;
  6. final Color? menuItemColor;
  7. final Color? pressedColor;
  8. final VoidCallback? onTap;
  9. const BlurMenuItemWidget({
  10. this.leadingIcon,
  11. this.labelText,
  12. this.menuItemColor,
  13. this.pressedColor,
  14. this.onTap,
  15. super.key,
  16. });
  17. @override
  18. State<BlurMenuItemWidget> createState() => _BlurMenuItemWidgetState();
  19. }
  20. class _BlurMenuItemWidgetState extends State<BlurMenuItemWidget> {
  21. Color? menuItemColor;
  22. @override
  23. void initState() {
  24. menuItemColor = widget.menuItemColor;
  25. super.initState();
  26. }
  27. @override
  28. void didChangeDependencies() {
  29. menuItemColor = widget.menuItemColor;
  30. super.didChangeDependencies();
  31. }
  32. @override
  33. Widget build(BuildContext context) {
  34. final colorScheme = getEnteColorScheme(context);
  35. return GestureDetector(
  36. onTap: widget.onTap,
  37. onTapDown: _onTapDown,
  38. onTapUp: _onTapUp,
  39. onTapCancel: _onCancel,
  40. child: AnimatedContainer(
  41. duration: const Duration(milliseconds: 20),
  42. color: menuItemColor,
  43. padding: const EdgeInsets.only(left: 16, right: 12),
  44. child: Padding(
  45. padding: const EdgeInsets.symmetric(vertical: 14),
  46. child: Row(
  47. children: [
  48. widget.leadingIcon != null
  49. ? Padding(
  50. padding: const EdgeInsets.only(right: 10),
  51. child: Icon(
  52. widget.leadingIcon,
  53. size: 20,
  54. color: colorScheme.blurStrokeBase,
  55. ),
  56. )
  57. : const SizedBox.shrink(),
  58. widget.labelText != null
  59. ? Padding(
  60. padding: const EdgeInsets.symmetric(horizontal: 2),
  61. child: Text(
  62. widget.labelText!,
  63. style: getEnteTextTheme(context)
  64. .bodyBold
  65. .copyWith(color: colorScheme.blurTextBase),
  66. ),
  67. )
  68. : const SizedBox.shrink(),
  69. ],
  70. ),
  71. ),
  72. ),
  73. );
  74. }
  75. void _onTapDown(details) {
  76. setState(() {
  77. menuItemColor = widget.pressedColor ?? widget.menuItemColor;
  78. });
  79. }
  80. void _onTapUp(details) {
  81. Future.delayed(
  82. const Duration(milliseconds: 100),
  83. () => setState(() {
  84. menuItemColor = widget.menuItemColor;
  85. }),
  86. );
  87. }
  88. void _onCancel() {
  89. setState(() {
  90. menuItemColor = widget.menuItemColor;
  91. });
  92. }
  93. }