Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mobile][photos] Add reusable navigation cards

r4khul62e21af38271
diff --git a/mobile/packages/ente_components/lib/components/navigation_card_component.dart b/mobile/packages/ente_components/lib/components/navigation_card_component.dart
new file mode 100644
index 0000000000..991e75fb5d
--- /dev/null
+++ b/mobile/packages/ente_components/lib/components/navigation_card_component.dart
@@ -0,0 +1,129 @@
+import 'dart:async';
+
+import 'package:ente_components/theme/icon_sizes.dart';
+import 'package:ente_components/theme/radii.dart';
+import 'package:ente_components/theme/spacing.dart';
+import 'package:ente_components/theme/text_styles.dart';
+import 'package:ente_components/theme/theme.dart';
+import 'package:flutter/material.dart';
+import 'package:hugeicons/hugeicons.dart';
+
+class NavigationCardComponent extends StatefulWidget {
+ const NavigationCardComponent({
+ super.key,
+ required this.title,
+ required this.subtitle,
+ required this.leading,
+ required this.onTap,
+ });
+
+ static const double leadingSize = 34;
+
+ final String title;
+ final String subtitle;
+ final Widget leading;
+ final FutureOr<void> Function() onTap;
+
+ @override
+ State<NavigationCardComponent> createState() =>
+ _NavigationCardComponentState();
+}
+
+class _NavigationCardComponentState extends State<NavigationCardComponent> {
+ bool _isBusy = false;
+
+ @override
+ Widget build(BuildContext context) {
+ final colors = context.componentColors;
+ return MergeSemantics(
+ child: Semantics(
+ button: true,
+ enabled: !_isBusy,
+ child: Material(
+ color: colors.fillLight,
+ borderRadius: Radii.buttonBorder,
+ child: InkWell(
+ onTap: _isBusy ? null : _onTap,
+ borderRadius: Radii.buttonBorder,
+ child: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: 80),
+ child: Padding(
+ padding: const EdgeInsets.fromLTRB(
+ Spacing.xxl,
+ Spacing.lg,
+ Spacing.lg,
+ Spacing.lg,
+ ),
+ child: Row(
+ children: [
+ ExcludeSemantics(
+ child: SizedBox.square(
+ dimension: NavigationCardComponent.leadingSize,
+ child: widget.leading,
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ Expanded(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ widget.title,
+ style: TextStyles.bodyBold.copyWith(
+ color: colors.textBase,
+ fontSize: 15,
+ height: 20 / 15,
+ ),
+ ),
+ Text(
+ widget.subtitle,
+ style: TextStyles.mini.copyWith(
+ color: colors.textLight,
+ height: 18 / 12,
+ ),
+ ),
+ ],
+ ),
+ ),
+ const SizedBox(width: Spacing.md),
+ ExcludeSemantics(
+ child: DecoratedBox(
+ decoration: BoxDecoration(
+ color: colors.fillDark,
+ shape: BoxShape.circle,
+ ),
+ child: SizedBox.square(
+ dimension: 32,
+ child: Center(
+ child: HugeIcon(
+ icon: HugeIcons.strokeRoundedArrowRight01,
+ size: IconSizes.small,
+ color: colors.textBase,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+
+ Future<void> _onTap() async {
+ if (_isBusy) return;
+ setState(() => _isBusy = true);
+ try {
+ await widget.onTap();
+ } catch (_) {
+ return;
+ } finally {
+ if (mounted) setState(() => _isBusy = false);
+ }
+ }
+}
diff --git a/mobile/packages/ente_components/lib/ente_components.dart b/mobile/packages/ente_components/lib/ente_components.dart
index 0628bc9266..da41075aef 100644
--- a/mobile/packages/ente_components/lib/ente_components.dart
+++ b/mobile/packages/ente_components/lib/ente_components.dart
@@ -16,6 +16,7 @@ export 'components/loading/loading_dialog_component.dart';
export 'components/menu_component.dart';
export 'components/menu_group_component.dart';
export 'components/more_from_ente_section.dart';
+export 'components/navigation_card_component.dart';
export 'components/pin_input_component.dart';
export 'components/popup_menu_component.dart';
export 'components/selection_controls/checkbox_component.dart';