ente/lib/ui/components/menu_item_widget.dart

132 lines
3.9 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';
enum LeadingIcon {
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 {
final Widget leadingWidget;
final LeadingIcon? trailingIcon;
final Widget? trailingSwitch;
final bool trailingIconIsMuted;
final Function? onTap;
const MenuItemWidget({
required this.leadingWidget,
this.trailingIcon,
this.trailingSwitch,
this.trailingIconIsMuted = false,
this.onTap,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final enteTheme = Theme.of(context).colorScheme.enteTheme;
return GestureDetector(
onTap: () {
onTap;
},
child: Container(
width: double.infinity,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
leadingWidget,
Container(
child: trailingIcon == LeadingIcon.chevronRight
? Icon(
Icons.chevron_right_rounded,
color: trailingIconIsMuted
? enteTheme.colorScheme.strokeMuted
: null,
)
: trailingIcon == LeadingIcon.check
? Icon(
Icons.check,
color: enteTheme.colorScheme.strokeMuted,
)
: trailingSwitch ?? const SizedBox.shrink(),
)
],
),
),
);
}
}
2022-09-28 12:10:49 +00:00
// leading icon can be passed without specifing size, this component set size to 20x20
class LeadingWidget extends StatelessWidget {
2022-09-28 05:00:43 +00:00
final String text;
final IconData? leadingIcon;
final Color? leadingIconColor;
2022-09-28 05:00:43 +00:00
final String? subText;
final TextStyle? textStyle;
const LeadingWidget({
2022-09-28 05:00:43 +00:00
required this.text,
this.leadingIcon,
this.leadingIconColor,
2022-09-28 05:00:43 +00:00
this.subText,
this.textStyle,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
final enteTheme = Theme.of(context).colorScheme.enteTheme;
return Flexible(
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 12),
child: Row(
children: [
SizedBox(
height: 20,
width: 20,
child: FittedBox(
fit: BoxFit.contain,
child: Icon(
leadingIcon ?? Icons.add_outlined,
color: leadingIconColor ?? enteTheme.colorScheme.strokeBase,
),
),
),
const SizedBox(width: 12),
Flexible(
child: RichText(
text: TextSpan(
2022-09-28 07:24:22 +00:00
style: textStyle ?? enteTheme.textTheme.bodyBold,
children: [
TextSpan(
text: text,
),
subText != null
? TextSpan(
text: ' \u2022 ',
style: enteTheme.textTheme.small.copyWith(
color: enteTheme.colorScheme.textMuted,
2022-09-28 05:00:43 +00:00
),
)
: const TextSpan(text: ''),
subText != null
? TextSpan(
text: subText,
2022-09-28 07:24:22 +00:00
style: enteTheme.textTheme.small.copyWith(
2022-09-28 08:37:31 +00:00
color: enteTheme.colorScheme.textMuted,
),
)
: const TextSpan(text: ''),
],
),
),
)
],
),
2022-09-28 05:00:43 +00:00
),
);
}
}