ente/lib/ui/components/menu_item_widget.dart

85 lines
2.3 KiB
Dart
Raw Normal View History

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 {
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;
final bool isHeaderOfExpansion;
final IconData? leadingIcon;
final Color? leadingIconColor;
2022-09-29 01:40:27 +00:00
final TrailingIcon? trailingIcon;
final Widget? trailingSwitch;
final bool trailingIconIsMuted;
final Function? onTap;
const MenuItemWidget({
2022-09-28 12:58:07 +00:00
required this.captionedTextWidget,
required this.isHeaderOfExpansion,
this.leadingIcon,
this.leadingIconColor,
this.trailingIcon,
this.trailingSwitch,
this.trailingIconIsMuted = false,
this.onTap,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return isHeaderOfExpansion
? menuItemWidget(context)
: GestureDetector(
onTap: () {
onTap;
},
child: menuItemWidget(context),
);
}
Widget menuItemWidget(BuildContext context) {
final enteTheme = Theme.of(context).colorScheme.enteTheme;
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,
),
),
),
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(),
)
],
),
);
}
}