2022-09-28 05:00:43 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:photos/ente_theme_data.dart';
|
|
|
|
|
2022-09-29 01:40:27 +00:00
|
|
|
enum TrailingIcon {
|
2022-09-28 05:35:17 +00:00
|
|
|
chevronRight,
|
|
|
|
check,
|
|
|
|
}
|
|
|
|
|
2022-09-28 12:10:49 +00:00
|
|
|
// trailing icon can be passed without size as default size set by flutter is what this component expects
|
2022-09-28 05:00:43 +00:00
|
|
|
class MenuItemWidget extends StatelessWidget {
|
2022-09-28 12:58:07 +00:00
|
|
|
final Widget captionedTextWidget;
|
2022-09-29 02:08:02 +00:00
|
|
|
final bool isHeaderOfExpansion;
|
2022-09-28 12:22:16 +00:00
|
|
|
final IconData? leadingIcon;
|
|
|
|
final Color? leadingIconColor;
|
2022-09-29 01:40:27 +00:00
|
|
|
final TrailingIcon? trailingIcon;
|
2022-09-28 11:51:52 +00:00
|
|
|
final Widget? trailingSwitch;
|
|
|
|
final bool trailingIconIsMuted;
|
|
|
|
final Function? onTap;
|
|
|
|
const MenuItemWidget({
|
2022-09-28 12:58:07 +00:00
|
|
|
required this.captionedTextWidget,
|
2022-09-29 02:08:02 +00:00
|
|
|
required this.isHeaderOfExpansion,
|
2022-09-28 12:22:16 +00:00
|
|
|
this.leadingIcon,
|
|
|
|
this.leadingIconColor,
|
2022-09-28 11:51:52 +00:00
|
|
|
this.trailingIcon,
|
|
|
|
this.trailingSwitch,
|
|
|
|
this.trailingIconIsMuted = false,
|
|
|
|
this.onTap,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-29 02:08:02 +00:00
|
|
|
return isHeaderOfExpansion
|
|
|
|
? menuItemWidget(context)
|
|
|
|
: GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
onTap;
|
|
|
|
},
|
|
|
|
child: menuItemWidget(context),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget menuItemWidget(BuildContext context) {
|
2022-09-28 11:51:52 +00:00
|
|
|
final enteTheme = Theme.of(context).colorScheme.enteTheme;
|
2022-09-29 02:08:02 +00:00
|
|
|
|
|
|
|
return Container(
|
|
|
|
width: double.infinity,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: 20,
|
|
|
|
width: 20,
|
|
|
|
child: FittedBox(
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
child: Icon(
|
|
|
|
leadingIcon,
|
|
|
|
color: leadingIconColor,
|
2022-09-28 12:22:16 +00:00
|
|
|
),
|
|
|
|
),
|
2022-09-29 02:08:02 +00:00
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
captionedTextWidget,
|
|
|
|
Container(
|
|
|
|
child: trailingIcon == TrailingIcon.chevronRight
|
|
|
|
? Icon(
|
|
|
|
Icons.chevron_right_rounded,
|
|
|
|
color: trailingIconIsMuted
|
|
|
|
? enteTheme.colorScheme.strokeMuted
|
|
|
|
: null,
|
|
|
|
)
|
|
|
|
: trailingIcon == TrailingIcon.check
|
|
|
|
? Icon(
|
|
|
|
Icons.check,
|
|
|
|
color: enteTheme.colorScheme.strokeMuted,
|
|
|
|
)
|
|
|
|
: trailingSwitch ?? const SizedBox.shrink(),
|
|
|
|
)
|
|
|
|
],
|
2022-09-28 11:51:52 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|