icon_button_widget.dart 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import 'package:flutter/material.dart';
  2. import 'package:photos/theme/ente_theme.dart';
  3. class IconButtonWidget extends StatefulWidget {
  4. final bool isPrimary;
  5. final bool isSecondary;
  6. final bool isRounded;
  7. final IconData icon;
  8. final VoidCallback? onTap;
  9. const IconButtonWidget({
  10. required this.icon,
  11. this.isPrimary = true,
  12. this.isSecondary = false,
  13. this.isRounded = false,
  14. this.onTap,
  15. super.key,
  16. });
  17. @override
  18. State<IconButtonWidget> createState() => _IconButtonWidgetState();
  19. }
  20. class _IconButtonWidgetState extends State<IconButtonWidget> {
  21. Color? iconStateColor;
  22. @override
  23. void didChangeDependencies() {
  24. setState(() {
  25. iconStateColor = null;
  26. });
  27. super.didChangeDependencies();
  28. }
  29. @override
  30. Widget build(BuildContext context) {
  31. final colorTheme = getEnteColorScheme(context);
  32. iconStateColor ??
  33. (iconStateColor = (widget.isRounded ? colorTheme.fillFaint : null));
  34. return GestureDetector(
  35. onTapDown: _onTapDown,
  36. onTapUp: _onTapUp,
  37. onTapCancel: _onTapCancel,
  38. onTap: widget.onTap,
  39. child: AnimatedContainer(
  40. duration: const Duration(milliseconds: 20),
  41. padding: const EdgeInsets.all(8),
  42. decoration: BoxDecoration(
  43. borderRadius: BorderRadius.circular(20),
  44. color: iconStateColor,
  45. ),
  46. child: Icon(
  47. Icons.close_outlined,
  48. color: widget.isSecondary
  49. ? colorTheme.strokeMuted
  50. : colorTheme.strokeBase,
  51. size: 24,
  52. ),
  53. ),
  54. );
  55. }
  56. _onTapDown(details) {
  57. final colorTheme = getEnteColorScheme(context);
  58. setState(() {
  59. iconStateColor =
  60. widget.isRounded ? colorTheme.fillMuted : colorTheme.fillFaint;
  61. });
  62. }
  63. _onTapUp(details) {
  64. Future.delayed(const Duration(milliseconds: 100), () {
  65. setState(() {
  66. iconStateColor = null;
  67. });
  68. });
  69. }
  70. _onTapCancel() {
  71. setState(() {
  72. iconStateColor = null;
  73. });
  74. }
  75. }