blur_menu_item_widget.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. bool isDisabled = false;
  23. @override
  24. void initState() {
  25. menuItemColor = widget.menuItemColor;
  26. isDisabled = (widget.onTap == null);
  27. super.initState();
  28. }
  29. @override
  30. void didChangeDependencies() {
  31. menuItemColor = widget.menuItemColor;
  32. super.didChangeDependencies();
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. isDisabled = (widget.onTap == null);
  37. final colorScheme = getEnteColorScheme(context);
  38. return GestureDetector(
  39. onTap: widget.onTap,
  40. onTapDown: _onTapDown,
  41. onTapUp: _onTapUp,
  42. onTapCancel: _onCancel,
  43. child: AnimatedContainer(
  44. duration: const Duration(milliseconds: 20),
  45. color: isDisabled ? colorScheme.fillFaint : menuItemColor,
  46. padding: const EdgeInsets.only(left: 16, right: 12),
  47. child: Padding(
  48. padding: const EdgeInsets.symmetric(vertical: 14),
  49. child: Row(
  50. children: [
  51. widget.leadingIcon != null
  52. ? Padding(
  53. padding: const EdgeInsets.only(right: 10),
  54. child: Icon(
  55. widget.leadingIcon,
  56. size: 20,
  57. color: isDisabled
  58. ? colorScheme.strokeMuted
  59. : colorScheme.blurStrokeBase,
  60. ),
  61. )
  62. : const SizedBox.shrink(),
  63. widget.labelText != null
  64. ? Flexible(
  65. child: Padding(
  66. padding: const EdgeInsets.symmetric(horizontal: 2),
  67. child: Row(
  68. children: [
  69. Flexible(
  70. child: Text(
  71. widget.labelText!,
  72. overflow: TextOverflow.ellipsis,
  73. maxLines: 1,
  74. style:
  75. getEnteTextTheme(context).bodyBold.copyWith(
  76. color: isDisabled
  77. ? colorScheme.textFaint
  78. : colorScheme.blurTextBase,
  79. ),
  80. ),
  81. ),
  82. ],
  83. ),
  84. ),
  85. )
  86. : const SizedBox.shrink(),
  87. ],
  88. ),
  89. ),
  90. ),
  91. );
  92. }
  93. void _onTapDown(details) {
  94. setState(() {
  95. menuItemColor = widget.pressedColor ?? widget.menuItemColor;
  96. });
  97. }
  98. void _onTapUp(details) {
  99. Future.delayed(
  100. const Duration(milliseconds: 100),
  101. () => setState(() {
  102. menuItemColor = widget.menuItemColor;
  103. }),
  104. );
  105. }
  106. void _onCancel() {
  107. setState(() {
  108. menuItemColor = widget.menuItemColor;
  109. });
  110. }
  111. }