ente/lib/ui/components/blur_menu_item_widget.dart

121 lines
3.5 KiB
Dart
Raw Normal View History

2022-11-28 12:59:33 +00:00
import 'package:flutter/material.dart';
import 'package:photos/theme/ente_theme.dart';
class BlurMenuItemWidget extends StatefulWidget {
final IconData? leadingIcon;
final String? labelText;
final Color? menuItemColor;
final Color? pressedColor;
final VoidCallback? onTap;
const BlurMenuItemWidget({
this.leadingIcon,
this.labelText,
this.menuItemColor,
this.pressedColor,
this.onTap,
super.key,
});
@override
State<BlurMenuItemWidget> createState() => _BlurMenuItemWidgetState();
}
class _BlurMenuItemWidgetState extends State<BlurMenuItemWidget> {
Color? menuItemColor;
2022-12-15 16:53:06 +00:00
bool isDisabled = false;
2022-12-15 16:24:39 +00:00
2022-11-28 12:59:33 +00:00
@override
void initState() {
menuItemColor = widget.menuItemColor;
2022-12-15 16:53:06 +00:00
isDisabled = (widget.onTap == null);
2022-11-28 12:59:33 +00:00
super.initState();
}
@override
void didChangeDependencies() {
menuItemColor = widget.menuItemColor;
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
2022-12-15 16:53:06 +00:00
isDisabled = (widget.onTap == null);
2022-11-28 12:59:33 +00:00
final colorScheme = getEnteColorScheme(context);
return GestureDetector(
onTap: widget.onTap,
onTapDown: _onTapDown,
onTapUp: _onTapUp,
onTapCancel: _onCancel,
child: AnimatedContainer(
duration: const Duration(milliseconds: 20),
2022-12-15 16:24:39 +00:00
color: isDisabled ? colorScheme.fillFaint : menuItemColor,
2022-11-28 12:59:33 +00:00
padding: const EdgeInsets.only(left: 16, right: 12),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 14),
child: Row(
children: [
widget.leadingIcon != null
? Padding(
padding: const EdgeInsets.only(right: 10),
child: Icon(
widget.leadingIcon,
size: 20,
2022-12-15 16:24:39 +00:00
color: isDisabled
? colorScheme.strokeMuted
: colorScheme.blurStrokeBase,
2022-11-28 12:59:33 +00:00
),
)
: const SizedBox.shrink(),
widget.labelText != null
2022-12-05 10:20:33 +00:00
? Flexible(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 2),
child: Row(
children: [
Flexible(
child: Text(
widget.labelText!,
overflow: TextOverflow.ellipsis,
maxLines: 1,
2022-12-15 16:24:39 +00:00
style:
getEnteTextTheme(context).bodyBold.copyWith(
color: isDisabled
? colorScheme.textFaint
: colorScheme.blurTextBase,
),
2022-12-05 10:20:33 +00:00
),
),
],
),
2022-11-28 12:59:33 +00:00
),
)
: const SizedBox.shrink(),
],
),
),
),
);
}
void _onTapDown(details) {
setState(() {
menuItemColor = widget.pressedColor ?? widget.menuItemColor;
});
}
void _onTapUp(details) {
Future.delayed(
const Duration(milliseconds: 100),
() => setState(() {
menuItemColor = widget.menuItemColor;
}),
);
}
void _onCancel() {
setState(() {
menuItemColor = widget.menuItemColor;
});
}
}