blur_menu_item_widget.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. ? Flexible(
  60. child: Padding(
  61. padding: const EdgeInsets.symmetric(horizontal: 2),
  62. child: Row(
  63. children: [
  64. Flexible(
  65. child: Text(
  66. widget.labelText!,
  67. overflow: TextOverflow.ellipsis,
  68. maxLines: 1,
  69. style: getEnteTextTheme(context)
  70. .bodyBold
  71. .copyWith(color: colorScheme.blurTextBase),
  72. ),
  73. ),
  74. ],
  75. ),
  76. ),
  77. )
  78. : const SizedBox.shrink(),
  79. ],
  80. ),
  81. ),
  82. ),
  83. );
  84. }
  85. void _onTapDown(details) {
  86. setState(() {
  87. menuItemColor = widget.pressedColor ?? widget.menuItemColor;
  88. });
  89. }
  90. void _onTapUp(details) {
  91. Future.delayed(
  92. const Duration(milliseconds: 100),
  93. () => setState(() {
  94. menuItemColor = widget.menuItemColor;
  95. }),
  96. );
  97. }
  98. void _onCancel() {
  99. setState(() {
  100. menuItemColor = widget.menuItemColor;
  101. });
  102. }
  103. }