π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mobile] Add grouped menu and async selection controls
aman-pilot53daa9612c06
diff --git a/mobile/packages/ente_components/example/lib/main.dart b/mobile/packages/ente_components/example/lib/main.dartindex 903d3df03d..d4bced756e 100644--- a/mobile/packages/ente_components/example/lib/main.dart+++ b/mobile/packages/ente_components/example/lib/main.dart@@ -590,40 +590,48 @@ class _SettingsMainContent extends StatelessWidget {return Column(crossAxisAlignment: CrossAxisAlignment.start,children: [- const _SettingsNavigationItem(- title: 'Account',- icon: HugeIcons.strokeRoundedUser,- page: _SettingsAccountPage(),- ),- const SizedBox(height: Spacing.md),- const _SettingsNavigationItem(- title: 'Security',- icon: HugeIcons.strokeRoundedSecurityCheck,- page: _SettingsSecurityPage(),- ),- const SizedBox(height: Spacing.md),- const _SettingsNavigationItem(- title: 'Appearance',- icon: HugeIcons.strokeRoundedPaintBoard,- page: _SettingsAppearancePage(),+ MenuGroupComponent(+ items: [+ _settingsNavigationItem(+ context,+ title: 'Account',+ icon: HugeIcons.strokeRoundedUser,+ page: const _SettingsAccountPage(),+ ),+ _settingsNavigationItem(+ context,+ title: 'Security',+ icon: HugeIcons.strokeRoundedSecurityCheck,+ page: const _SettingsSecurityPage(),+ ),+ _settingsNavigationItem(+ context,+ title: 'Appearance',+ icon: HugeIcons.strokeRoundedPaintBoard,+ page: const _SettingsAppearancePage(),+ ),+ ],),const SizedBox(height: Spacing.md),- const _SettingsNavigationItem(+ _settingsNavigationItem(+ context,title: 'General',icon: HugeIcons.strokeRoundedSettings01,- page: _SettingsGeneralPage(),+ page: const _SettingsGeneralPage(),),const SizedBox(height: Spacing.md),- const _SettingsNavigationItem(+ _settingsNavigationItem(+ context,title: 'Help and support',icon: HugeIcons.strokeRoundedHelpCircle,- page: _SettingsSupportPage(),+ page: const _SettingsSupportPage(),),const SizedBox(height: Spacing.md),- const _SettingsNavigationItem(+ _settingsNavigationItem(+ context,title: 'About',icon: HugeIcons.strokeRoundedInformationCircle,- page: _SettingsAboutPage(),+ page: const _SettingsAboutPage(),),const SizedBox(height: Spacing.xl),MenuComponent(@@ -644,21 +652,13 @@ class _SettingsMainContent extends StatelessWidget {],);}-}--class _SettingsNavigationItem extends StatelessWidget {- const _SettingsNavigationItem({- required this.title,- required this.icon,- required this.page,- });-- final String title;- final HugeIconData icon;- final Widget page;- @override- Widget build(BuildContext context) {+ MenuComponent _settingsNavigationItem(+ BuildContext context, {+ required String title,+ required HugeIconData icon,+ required Widget page,+ }) {return MenuComponent(title: title,leading: _CatalogHugeIcon(icon),@@ -2557,6 +2557,7 @@ class _MenuItemInteractionStatesPreview extends StatelessWidget {subtitle: 'Execution loading, then success',leading: _CatalogHugeIcon(HugeIcons.strokeRoundedCloudUpload),trailing: _CatalogTrailingIcon(HugeIcons.strokeRoundedArrowRight01),+ shouldSurfaceExecutionStates: true,onTap: _completeSlowly,),const SizedBox(height: Spacing.md),@@ -2565,6 +2566,7 @@ class _MenuItemInteractionStatesPreview extends StatelessWidget {subtitle: 'Fast success confirmation',leading: _CatalogHugeIcon(HugeIcons.strokeRoundedCopy01),trailing: _CatalogTrailingIcon(HugeIcons.strokeRoundedArrowRight01),+ shouldSurfaceExecutionStates: true,shouldShowSuccessConfirmation: true,onTap: _completeQuickly,),@@ -2578,6 +2580,7 @@ class _MenuItemInteractionStatesPreview extends StatelessWidget {),titleColor: context.componentColors.warning,iconColor: context.componentColors.warning,+ shouldSurfaceExecutionStates: true,onTap: () => _failAfterDelay(context),),const SizedBox(height: Spacing.md),@@ -2725,24 +2728,6 @@ class _BottomSheetPreview extends StatelessWidget {],),),- const _CatalogPreviewGroup(- title: 'Header',- child: _InlineSheetFrame(- child: Column(- mainAxisSize: MainAxisSize.min,- children: [- BottomSheetHeaderComponent(title: 'Title'),- SizedBox(height: Spacing.xl),- BottomSheetHeaderComponent(),- SizedBox(height: Spacing.xl),- BottomSheetHeaderComponent(- title: 'Title',- illustration: _WarningIllustration(),- ),- ],- ),- ),- ),const _CatalogPreviewGroup(title: 'Default sheet',child: _InlineSheetFrame(child: _DefaultBottomSheetContent()),@@ -2951,10 +2936,10 @@ class _CustomBottomSheetContent extends StatelessWidget {Container(width: double.infinity,padding: const EdgeInsets.fromLTRB(- Spacing.xl,- Spacing.xl,- 56,- Spacing.xl,+ Spacing.md,+ Spacing.md,+ 48,+ Spacing.md,),decoration: BoxDecoration(color: colors.fillDark,diff --git a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dartindex 046cfa479f..54ac0757a2 100644--- a/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart+++ b/mobile/packages/ente_components/lib/components/bottom_sheet/bottom_sheet_component.dart@@ -12,9 +12,8 @@ import 'package:hugeicons/hugeicons.dart';/// Section: Bottom sheet / Bottom Sheet Header/// Specs: H2 title, optional 36px circular close action, and optional centered/// illustration slot for warning and error sheets.-class BottomSheetHeaderComponent extends StatelessWidget {- const BottomSheetHeaderComponent({- super.key,+class _BottomSheetHeaderComponent extends StatelessWidget {+ const _BottomSheetHeaderComponent({this.title,this.illustration,this.onClose,@@ -139,7 +138,7 @@ class BottomSheetComponent extends StatelessWidget {final effectiveHeader =header ??((title != null || showCloseButton || usesCenteredLayout)- ? BottomSheetHeaderComponent(+ ? _BottomSheetHeaderComponent(title: title,illustration: illustration,onClose: onClose,diff --git a/mobile/packages/ente_components/lib/components/menu_component.dart b/mobile/packages/ente_components/lib/components/menu_component.dartindex 0cd2f2fe43..6e08bc1fc4 100644--- a/mobile/packages/ente_components/lib/components/menu_component.dart+++ b/mobile/packages/ente_components/lib/components/menu_component.dart@@ -1,6 +1,7 @@import 'dart:async';import 'package:ente_components/models/component_execution_state.dart';+import 'package:ente_components/src/components/menu_component_surface_style.dart';import 'package:ente_components/theme/colors.dart';import 'package:ente_components/theme/motion.dart';import 'package:ente_components/theme/radii.dart';@@ -29,7 +30,7 @@ class MenuComponent extends StatefulWidget {this.onTap,this.isDisabled = false,this.showOnlyLoadingState = false,- this.shouldSurfaceExecutionStates = true,+ this.shouldSurfaceExecutionStates = false,this.shouldShowSuccessConfirmation = false,this.titleMaxLines = 2,this.subtitleMaxLines = 1,@@ -69,6 +70,9 @@ class _MenuComponentState extends State<MenuComponent> {final enabled = _canHandleGestures;final trailing = _trailing(colors);final shouldReserveTrailingSlot = _shouldReserveTrailingSlot;+ final surfaceStyle = MenuComponentSurfaceStyle.maybeOf(context);+ final borderRadius =+ surfaceStyle?.borderRadius ?? BorderRadius.circular(Radii.button);return UnconstrainedBox(alignment: Alignment.topLeft,constrainedAxis: Axis.horizontal,@@ -81,18 +85,22 @@ class _MenuComponentState extends State<MenuComponent> {child: InkWell(onTap: enabled ? _handleTap : null,onHighlightChanged: enabled ? _setPressed : null,- borderRadius: BorderRadius.circular(Radii.button),+ borderRadius: borderRadius,child: AnimatedContainer(key: const ValueKey('menu-item-surface'),duration: Motion.quick,decoration: BoxDecoration(- color: _backgroundColor(colors, enabled),+ color: _backgroundColor(+ colors,+ enabled,+ surfaceStyle?.backgroundColor,+ ),border: Border.all(color: widget.selected? colors.primaryStroke: Colors.transparent,),- borderRadius: BorderRadius.circular(Radii.button),+ borderRadius: borderRadius,),child: ConstrainedBox(constraints: BoxConstraints(minHeight: _minimumHeight()),@@ -208,14 +216,18 @@ class _MenuComponentState extends State<MenuComponent> {_shouldSurfaceExecutionState);}- Color _backgroundColor(ColorTokens colors, bool enabled) {+ Color _backgroundColor(+ ColorTokens colors,+ bool enabled,+ Color? backgroundColor,+ ) {if (_isPressed) {return colors.fillDarker;}if (_isHovered && enabled) {return colors.fillDark;}- return colors.fillLight;+ return backgroundColor ?? colors.fillLight;}Widget? _trailing(ColorTokens colors) {diff --git a/mobile/packages/ente_components/lib/components/menu_group_component.dart b/mobile/packages/ente_components/lib/components/menu_group_component.dartnew file mode 100644index 0000000000..aa8d276e5b--- /dev/null+++ b/mobile/packages/ente_components/lib/components/menu_group_component.dart@@ -0,0 +1,91 @@+import 'package:ente_components/components/menu_component.dart';+import 'package:ente_components/src/components/menu_component_surface_style.dart';+import 'package:ente_components/theme/radii.dart';+import 'package:ente_components/theme/theme.dart';+import 'package:flutter/material.dart';++/// Groups related menu rows into one rounded surface.+///+/// The group owns the shared surface and applies first/middle/last row shapes,+/// while each item remains responsible for its own content and interaction.+class MenuGroupComponent extends StatelessWidget {+ const MenuGroupComponent({+ super.key,+ required this.items,+ this.backgroundColor,+ this.borderRadius = const BorderRadius.all(Radius.circular(Radii.button)),+ this.clipBehavior = Clip.hardEdge,+ });++ final List<MenuComponent> items;+ final Color? backgroundColor;+ final BorderRadius borderRadius;+ final Clip clipBehavior;++ static BorderRadius itemBorderRadius({+ required int index,+ required int itemCount,+ BorderRadius borderRadius = const BorderRadius.all(+ Radius.circular(Radii.button),+ ),+ }) {+ assert(index >= 0);+ assert(itemCount > 0);+ assert(index < itemCount);++ return BorderRadius.only(+ topLeft: index == 0 ? borderRadius.topLeft : Radius.zero,+ topRight: index == 0 ? borderRadius.topRight : Radius.zero,+ bottomLeft: index == itemCount - 1+ ? borderRadius.bottomLeft+ : Radius.zero,+ bottomRight: index == itemCount - 1+ ? borderRadius.bottomRight+ : Radius.zero,+ );+ }++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;++ return Container(+ key: const ValueKey('menu-group-surface'),+ width: double.infinity,+ clipBehavior: clipBehavior,+ decoration: BoxDecoration(+ color: backgroundColor ?? colors.fillLight,+ borderRadius: borderRadius,+ ),+ child: Column(+ mainAxisSize: MainAxisSize.min,+ children: [+ for (var index = 0; index < items.length; index++)+ _groupedItem(+ items[index],+ index: index,+ itemCount: items.length,+ backgroundColor: backgroundColor ?? colors.fillLight,+ ),+ ],+ ),+ );+ }++ Widget _groupedItem(+ MenuComponent item, {+ required int index,+ required int itemCount,+ required Color backgroundColor,+ }) {+ return MenuComponentSurfaceStyle(+ borderRadius: itemBorderRadius(+ index: index,+ itemCount: itemCount,+ borderRadius: borderRadius,+ ),+ backgroundColor: backgroundColor,+ child: item,+ );+ }+}diff --git a/mobile/packages/ente_components/lib/components/selection_control_components.dart b/mobile/packages/ente_components/lib/components/selection_control_components.dartdeleted file mode 100644index c6ef7a0a5c..0000000000--- a/mobile/packages/ente_components/lib/components/selection_control_components.dart+++ /dev/null@@ -1,175 +0,0 @@-import 'package:ente_components/theme/motion.dart';-import 'package:ente_components/theme/spacing.dart';-import 'package:ente_components/theme/theme.dart';-import 'package:flutter/material.dart';--/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2513-47857&m=dev-/// Section: Radio buttons, toggles and checkboxes / CheckboxComponent-/// Specs: 16px checkbox, selected and disabled variants.-class CheckboxComponent extends StatelessWidget {- const CheckboxComponent({- super.key,- required this.selected,- required this.onChanged,- });-- final bool selected;- final ValueChanged<bool>? onChanged;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- final enabled = onChanged != null;- final fill = selected- ? (enabled ? colors.primary : colors.fillDarkest)- : Colors.transparent;- final stroke = enabled ? colors.strokeDark : colors.strokeFaint;-- return InkWell(- onTap: enabled ? () => onChanged!(!selected) : null,- borderRadius: BorderRadius.circular(4),- child: AnimatedContainer(- duration: Motion.quick,- width: 16,- height: 16,- decoration: BoxDecoration(- color: fill,- borderRadius: BorderRadius.circular(4),- border: Border.all(color: selected ? fill : stroke),- ),- child: selected- ? Icon(Icons.check_rounded, size: 12, color: colors.specialWhite)- : null,- ),- );- }-}--/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2513-47857&m=dev-/// Section: Radio buttons, toggles and checkboxes / Radio Button-/// Specs: 16px radio, selected and disabled variants.-class RadioComponent extends StatelessWidget {- const RadioComponent({- super.key,- required this.selected,- required this.onChanged,- });-- final bool selected;- final ValueChanged<bool>? onChanged;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- final enabled = onChanged != null;- final active = enabled ? colors.primary : colors.fillDarkest;-- return InkWell(- onTap: enabled ? () => onChanged!(!selected) : null,- customBorder: const CircleBorder(),- child: AnimatedContainer(- duration: Motion.quick,- width: 16,- height: 16,- padding: const EdgeInsets.all(3),- decoration: BoxDecoration(- shape: BoxShape.circle,- border: Border.all(- color: selected ? active : colors.strokeDark,- width: selected ? 2 : 1,- ),- ),- child: selected- ? DecoratedBox(- decoration:- BoxDecoration(shape: BoxShape.circle, color: active),- )- : null,- ),- );- }-}--/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2482-6644&m=dev-/// Section: Radio buttons, toggles and checkboxes / Toggle Switch-/// Specs: 31px by 18px switch with selected and unselected states.-class ToggleSwitchComponent extends StatelessWidget {- const ToggleSwitchComponent({- super.key,- required this.selected,- required this.onChanged,- });-- final bool selected;- final ValueChanged<bool>? onChanged;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- final enabled = onChanged != null;- final track = selected- ? (enabled ? colors.primary : colors.fillDarkest)- : colors.strokeDark;-- return InkWell(- onTap: enabled ? () => onChanged!(!selected) : null,- borderRadius: BorderRadius.circular(9),- child: AnimatedContainer(- duration: Motion.quick,- width: 31,- height: 18,- padding: const EdgeInsets.all(2),- decoration: BoxDecoration(- color: track,- borderRadius: BorderRadius.circular(9),- ),- child: AnimatedAlign(- duration: Motion.quick,- alignment: selected ? Alignment.centerRight : Alignment.centerLeft,- child: Container(- width: 14,- height: 14,- decoration: BoxDecoration(- color: colors.specialWhite,- shape: BoxShape.circle,- ),- ),- ),- ),- );- }-}--class LabeledControlComponent extends StatelessWidget {- const LabeledControlComponent({- super.key,- required this.control,- required this.label,- this.subtitle,- });-- final Widget control;- final String label;- final String? subtitle;-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- return Row(- children: [- control,- const SizedBox(width: Spacing.md),- Expanded(- child: Column(- crossAxisAlignment: CrossAxisAlignment.start,- children: [- Text(label, style: TextStyle(color: colors.textBase)),- if (subtitle != null)- Text(subtitle!, style: TextStyle(color: colors.textLight)),- ],- ),- ),- ],- );- }-}diff --git a/mobile/packages/ente_components/lib/components/selection_controls/checkbox_component.dart b/mobile/packages/ente_components/lib/components/selection_controls/checkbox_component.dartnew file mode 100644index 0000000000..048874feff--- /dev/null+++ b/mobile/packages/ente_components/lib/components/selection_controls/checkbox_component.dart@@ -0,0 +1,45 @@+import 'package:ente_components/theme/motion.dart';+import 'package:ente_components/theme/theme.dart';+import 'package:flutter/material.dart';++/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2513-47857&m=dev+/// Section: Radio buttons, toggles and checkboxes / CheckboxComponent+/// Specs: 16px checkbox, selected and disabled variants.+class CheckboxComponent extends StatelessWidget {+ const CheckboxComponent({+ super.key,+ required this.selected,+ required this.onChanged,+ });++ final bool selected;+ final ValueChanged<bool>? onChanged;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final enabled = onChanged != null;+ final fill = selected+ ? (enabled ? colors.primary : colors.fillDarkest)+ : Colors.transparent;+ final stroke = enabled ? colors.strokeDark : colors.strokeFaint;++ return InkWell(+ onTap: enabled ? () => onChanged!(!selected) : null,+ borderRadius: BorderRadius.circular(4),+ child: AnimatedContainer(+ duration: Motion.quick,+ width: 16,+ height: 16,+ decoration: BoxDecoration(+ color: fill,+ borderRadius: BorderRadius.circular(4),+ border: Border.all(color: selected ? fill : stroke),+ ),+ child: selected+ ? Icon(Icons.check_rounded, size: 12, color: colors.specialWhite)+ : null,+ ),+ );+ }+}diff --git a/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dart b/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dartnew file mode 100644index 0000000000..66e3dfe8ef--- /dev/null+++ b/mobile/packages/ente_components/lib/components/selection_controls/labeled_control_component.dart@@ -0,0 +1,37 @@+import 'package:ente_components/theme/spacing.dart';+import 'package:ente_components/theme/theme.dart';+import 'package:flutter/material.dart';++class LabeledControlComponent extends StatelessWidget {+ const LabeledControlComponent({+ super.key,+ required this.control,+ required this.label,+ this.subtitle,+ });++ final Widget control;+ final String label;+ final String? subtitle;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return Row(+ children: [+ control,+ const SizedBox(width: Spacing.md),+ Expanded(+ child: Column(+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ Text(label, style: TextStyle(color: colors.textBase)),+ if (subtitle != null)+ Text(subtitle!, style: TextStyle(color: colors.textLight)),+ ],+ ),+ ),+ ],+ );+ }+}diff --git a/mobile/packages/ente_components/lib/components/selection_controls/radio_component.dart b/mobile/packages/ente_components/lib/components/selection_controls/radio_component.dartnew file mode 100644index 0000000000..4efc7a55c2--- /dev/null+++ b/mobile/packages/ente_components/lib/components/selection_controls/radio_component.dart@@ -0,0 +1,50 @@+import 'package:ente_components/theme/motion.dart';+import 'package:ente_components/theme/theme.dart';+import 'package:flutter/material.dart';++/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2513-47857&m=dev+/// Section: Radio buttons, toggles and checkboxes / Radio Button+/// Specs: 16px radio, selected and disabled variants.+class RadioComponent extends StatelessWidget {+ const RadioComponent({+ super.key,+ required this.selected,+ required this.onChanged,+ });++ final bool selected;+ final ValueChanged<bool>? onChanged;++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final enabled = onChanged != null;+ final active = enabled ? colors.primary : colors.fillDarkest;++ return InkWell(+ onTap: enabled ? () => onChanged!(!selected) : null,+ customBorder: const CircleBorder(),+ child: AnimatedContainer(+ duration: Motion.quick,+ width: 16,+ height: 16,+ padding: const EdgeInsets.all(3),+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ border: Border.all(+ color: selected ? active : colors.strokeDark,+ width: selected ? 2 : 1,+ ),+ ),+ child: selected+ ? DecoratedBox(+ decoration: BoxDecoration(+ shape: BoxShape.circle,+ color: active,+ ),+ )+ : null,+ ),+ );+ }+}diff --git a/mobile/packages/ente_components/lib/components/selection_controls/toggle_switch_component.dart b/mobile/packages/ente_components/lib/components/selection_controls/toggle_switch_component.dartnew file mode 100644index 0000000000..9e464a4e9c--- /dev/null+++ b/mobile/packages/ente_components/lib/components/selection_controls/toggle_switch_component.dart@@ -0,0 +1,233 @@+import 'dart:async';++import 'package:ente_components/theme/colors.dart';+import 'package:ente_components/theme/motion.dart';+import 'package:ente_components/theme/theme.dart';+import 'package:flutter/cupertino.dart';+import 'package:flutter/material.dart';++/// Figma: https://www.figma.com/design/BuBNPPytxlVnqfmCUW0mgz/Ente-Visual-Design?node-id=2482-6644&m=dev+/// Section: Radio buttons, toggles and checkboxes / Toggle Switch+/// Specs: 31px by 18px switch with selected and unselected states.+class ToggleSwitchComponent extends StatefulWidget {+ const ToggleSwitchComponent({+ super.key,+ required this.selected,+ required this.onChanged,+ this.showStateIcon = false,+ this.loadingDelay = const Duration(milliseconds: 300),+ this.minimumFeedbackDuration = const Duration(milliseconds: 200),+ this.successDuration = const Duration(seconds: 2),+ }) : _value = null;++ ToggleSwitchComponent.async({+ super.key,+ required ValueGetter<bool> value,+ required FutureOr<void> Function() onChanged,+ this.showStateIcon = true,+ this.loadingDelay = const Duration(milliseconds: 300),+ this.minimumFeedbackDuration = const Duration(milliseconds: 200),+ this.successDuration = const Duration(seconds: 2),+ }) : selected = value(),+ _value = value,+ onChanged = ((_) => onChanged());++ final bool selected;+ final FutureOr<void> Function(bool selected)? onChanged;+ final bool showStateIcon;+ final Duration loadingDelay;+ final Duration minimumFeedbackDuration;+ final Duration successDuration;+ final ValueGetter<bool>? _value;++ @override+ State<ToggleSwitchComponent> createState() => _ToggleSwitchComponentState();+}++class _ToggleSwitchComponentState extends State<ToggleSwitchComponent> {+ bool? _selected;+ _ToggleSwitchExecutionState _executionState =+ _ToggleSwitchExecutionState.idle;+ Timer? _loadingTimer;+ Timer? _successTimer;+ bool _isUpdating = false;++ @override+ void initState() {+ super.initState();+ _selected = _currentValue();+ }++ @override+ void didUpdateWidget(covariant ToggleSwitchComponent oldWidget) {+ super.didUpdateWidget(oldWidget);+ final newValue = _currentValue();+ if (_selected != newValue && !_isUpdating) {+ _selected = newValue;+ }+ }++ @override+ void dispose() {+ _loadingTimer?.cancel();+ _successTimer?.cancel();+ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ final enabled = widget.onChanged != null && !_isUpdating;+ final selected = _selected ?? widget.selected;+ final platform = Theme.of(context).platform;+ final isDarwin =+ platform == TargetPlatform.iOS || platform == TargetPlatform.macOS;++ return Row(+ mainAxisSize: MainAxisSize.min,+ children: [+ if (widget.showStateIcon) ...[+ Padding(+ padding: const EdgeInsets.only(right: 2),+ child: AnimatedSwitcher(+ duration: Motion.standard,+ switchInCurve: Curves.easeInExpo,+ switchOutCurve: Curves.easeOutExpo,+ child: ExcludeSemantics(child: _stateIcon(colors)),+ ),+ ),+ ],+ SizedBox(+ height: 31,+ child: FittedBox(+ fit: BoxFit.contain,+ child: isDarwin+ ? CupertinoSwitch(+ activeTrackColor: colors.primary,+ inactiveTrackColor: colors.fillDark,+ thumbColor: colors.specialWhite,+ value: selected,+ onChanged: enabled ? _handleChanged : null,+ )+ : Switch(+ inactiveTrackColor: colors.fillDark,+ activeTrackColor: colors.primary,+ activeColor: colors.specialWhite,+ inactiveThumbColor: colors.primary,+ trackOutlineColor: WidgetStateColor.resolveWith(+ (_) => enabled ? colors.primary : colors.strokeFaint,+ ),+ materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,+ value: selected,+ onChanged: enabled ? _handleChanged : null,+ ),+ ),+ ),+ ],+ );+ }++ bool _currentValue() => widget._value?.call() ?? widget.selected;++ Widget _stateIcon(ColorTokens colors) {+ return switch (_executionState) {+ _ToggleSwitchExecutionState.idle => const SizedBox(+ key: ValueKey('toggle-state-idle'),+ width: 24,+ ),+ _ToggleSwitchExecutionState.inProgress => SizedBox.square(+ key: const ValueKey('toggle-state-loading'),+ dimension: 22,+ child: CircularProgressIndicator(+ strokeWidth: 2,+ color: colors.strokeDark,+ ),+ ),+ _ToggleSwitchExecutionState.successful => Padding(+ key: const ValueKey('toggle-state-success'),+ padding: const EdgeInsets.symmetric(horizontal: 1),+ child: Icon(Icons.check_outlined, size: 22, color: colors.primary),+ ),+ };+ }++ Future<void> _handleChanged(bool nextValue) async {+ if (!mounted || widget.onChanged == null) {+ return;+ }++ _loadingTimer?.cancel();+ _successTimer?.cancel();+ setState(() {+ _isUpdating = true;+ _selected = nextValue;+ _executionState = _ToggleSwitchExecutionState.idle;+ });++ _loadingTimer = Timer(widget.loadingDelay, () {+ if (!mounted) {+ return;+ }+ setState(() {+ _executionState = _ToggleSwitchExecutionState.inProgress;+ });+ });++ final stopwatch = Stopwatch()..start();+ try {+ await widget.onChanged!(nextValue);+ } catch (_) {+ await _waitForMinimumFeedback(stopwatch);+ _loadingTimer?.cancel();+ if (!mounted) {+ return;+ }+ setState(() {+ _selected = _currentValue();+ _executionState = _ToggleSwitchExecutionState.idle;+ _isUpdating = false;+ });+ return;+ }++ await _waitForMinimumFeedback(stopwatch);+ _loadingTimer?.cancel();+ if (!mounted) {+ return;+ }++ final confirmedValue = _currentValue();+ setState(() {+ if (_selected == confirmedValue) {+ if (_executionState == _ToggleSwitchExecutionState.inProgress) {+ _executionState = _ToggleSwitchExecutionState.successful;+ _successTimer = Timer(widget.successDuration, () {+ if (!mounted) {+ return;+ }+ setState(() {+ _executionState = _ToggleSwitchExecutionState.idle;+ });+ });+ } else {+ _executionState = _ToggleSwitchExecutionState.idle;+ }+ } else {+ _selected = confirmedValue;+ _executionState = _ToggleSwitchExecutionState.idle;+ }+ _isUpdating = false;+ });+ }++ Future<void> _waitForMinimumFeedback(Stopwatch stopwatch) async {+ final remaining =+ widget.minimumFeedbackDuration -+ Duration(milliseconds: stopwatch.elapsedMilliseconds);+ if (remaining > Duration.zero) {+ await Future<void>.delayed(remaining);+ }+ }+}++enum _ToggleSwitchExecutionState { idle, inProgress, successful }diff --git a/mobile/packages/ente_components/lib/ente_components.dart b/mobile/packages/ente_components/lib/ente_components.dartindex 82e9c73d7a..218b435e37 100644--- a/mobile/packages/ente_components/lib/ente_components.dart+++ b/mobile/packages/ente_components/lib/ente_components.dart@@ -6,7 +6,11 @@ export 'components/buttons/button_component.dart';export 'components/buttons/icon_button_component.dart';export 'components/filter_chip_component.dart';export 'components/menu_component.dart';-export 'components/selection_control_components.dart';+export 'components/menu_group_component.dart';+export 'components/selection_controls/checkbox_component.dart';+export 'components/selection_controls/labeled_control_component.dart';+export 'components/selection_controls/radio_component.dart';+export 'components/selection_controls/toggle_switch_component.dart';export 'components/slider_component.dart';export 'components/stepper_component.dart';export 'components/text_input_component.dart';diff --git a/mobile/packages/ente_components/lib/src/components/menu_component_surface_style.dart b/mobile/packages/ente_components/lib/src/components/menu_component_surface_style.dartnew file mode 100644index 0000000000..c066944ef4--- /dev/null+++ b/mobile/packages/ente_components/lib/src/components/menu_component_surface_style.dart@@ -0,0 +1,24 @@+import 'package:flutter/material.dart';++class MenuComponentSurfaceStyle extends InheritedWidget {+ const MenuComponentSurfaceStyle({+ super.key,+ required super.child,+ this.borderRadius,+ this.backgroundColor,+ });++ final BorderRadius? borderRadius;+ final Color? backgroundColor;++ static MenuComponentSurfaceStyle? maybeOf(BuildContext context) {+ return context+ .dependOnInheritedWidgetOfExactType<MenuComponentSurfaceStyle>();+ }++ @override+ bool updateShouldNotify(covariant MenuComponentSurfaceStyle oldWidget) {+ return oldWidget.borderRadius != borderRadius ||+ oldWidget.backgroundColor != backgroundColor;+ }+}diff --git a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dartindex 931f4fee47..aebf5d19c7 100644--- a/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart+++ b/mobile/packages/ente_components/test/components/app_surface_widgets_test.dart@@ -2,6 +2,7 @@ import 'dart:async';import 'package:ente_components/components/app_bar_component.dart';import 'package:ente_components/components/menu_component.dart';+import 'package:ente_components/components/menu_group_component.dart';import 'package:ente_components/theme/colors.dart';import 'package:ente_components/theme/theme.dart';import 'package:flutter/material.dart';@@ -97,6 +98,7 @@ void main() {MenuComponent(title: 'Sync now',trailing: const Icon(Icons.chevron_right),+ shouldSurfaceExecutionStates: true,onTap: () {tapCount += 1;return completer.future;@@ -157,6 +159,7 @@ void main() {tester,MenuComponent(title: 'Copy',+ shouldSurfaceExecutionStates: true,shouldShowSuccessConfirmation: true,onTap: () async {},),@@ -179,6 +182,7 @@ void main() {MenuComponent(title: 'Fail',trailing: const Icon(Icons.chevron_right),+ shouldSurfaceExecutionStates: true,onTap: () async {await Future<void>.delayed(const Duration(milliseconds: 400));throw StateError('failed');@@ -220,6 +224,82 @@ void main() {expect(tapCount, 0);});+ testWidgets('MenuGroupComponent shapes a list of menu items', (tester) async {+ var tapped = false;+ var disabledTapped = false;++ await pumpComponent(+ tester,+ MenuGroupComponent(+ backgroundColor: Colors.orange,+ items: [+ MenuComponent(+ title: 'Account',+ leading: const Icon(Icons.person_outline),+ selected: true,+ titleColor: ColorTokens.light.warning,+ trailing: const Icon(Icons.chevron_right),+ onTap: () => tapped = true,+ ),+ MenuComponent(+ title: 'Security',+ leading: const Icon(Icons.lock_outline),+ isDisabled: true,+ onTap: () => disabledTapped = true,+ ),+ const MenuComponent(+ title: 'Appearance',+ leading: Icon(Icons.palette_outlined),+ ),+ ],+ ),+ height: 180,+ );++ expect(find.text('Account'), findsOneWidget);+ expect(find.text('Security'), findsOneWidget);+ expect(find.text('Appearance'), findsOneWidget);+ expect(find.byIcon(Icons.chevron_right), findsOneWidget);+ expect(+ tester.widget<Text>(find.text('Account')).style?.color,+ ColorTokens.light.warning,+ );++ final groupSurface = tester.widget<Container>(+ find.byKey(const ValueKey('menu-group-surface')),+ );+ final groupDecoration = groupSurface.decoration! as BoxDecoration;+ expect(+ groupDecoration.borderRadius,+ const BorderRadius.all(Radius.circular(20)),+ );++ final itemSurfaces = tester.widgetList<AnimatedContainer>(+ find.byKey(const ValueKey('menu-item-surface')),+ );+ final itemRadii = itemSurfaces+ .map((surface) => (surface.decoration! as BoxDecoration).borderRadius)+ .toList();+ final itemColors = itemSurfaces+ .map((surface) => (surface.decoration! as BoxDecoration).color)+ .toList();++ expect(itemRadii[0], const BorderRadius.vertical(top: Radius.circular(20)));+ expect(itemRadii[1], BorderRadius.zero);+ expect(+ itemRadii[2],+ const BorderRadius.vertical(bottom: Radius.circular(20)),+ );+ expect(itemColors, everyElement(Colors.orange));++ await tester.tap(find.text('Account'));+ await tester.tap(find.text('Security'));+ await tester.pump();++ expect(tapped, isTrue);+ expect(disabledTapped, isFalse);+ });+testWidgets('MenuComponent supports pressed and execution visuals', (tester,) async {@@ -239,11 +319,13 @@ void main() {title: 'Loading row',trailing: const Icon(Icons.chevron_right),showOnlyLoadingState: true,+ shouldSurfaceExecutionStates: true,onTap: () => loadingCompleter.future,),MenuComponent(title: 'Success row',trailing: const Icon(Icons.chevron_right),+ shouldSurfaceExecutionStates: true,shouldShowSuccessConfirmation: true,onTap: () async {},),diff --git a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dartindex 17fbb085d4..474fed3e0e 100644--- a/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart+++ b/mobile/packages/ente_components/test/components/bottom_sheet_component_test.dart@@ -5,21 +5,23 @@ import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';void main() {- testWidgets('BottomSheetHeaderComponent renders title and close action', (+ testWidgets('BottomSheetComponent renders title and close action', (tester,) async {var closeCount = 0;await tester.pumpWidget(_wrap(- BottomSheetHeaderComponent(+ BottomSheetComponent(title: 'Title',+ content: const Text('Body copy'),onClose: () => closeCount += 1,),),);expect(find.text('Title'), findsOneWidget);+ expect(find.text('Body copy'), findsOneWidget);expect(find.byTooltip('Close'), findsOneWidget);await tester.tap(find.byTooltip('Close'));diff --git a/mobile/packages/ente_components/test/components/selection_controls_test.dart b/mobile/packages/ente_components/test/components/selection_controls_test.dartindex e7de1f7daa..79cc10e126 100644--- a/mobile/packages/ente_components/test/components/selection_controls_test.dart+++ b/mobile/packages/ente_components/test/components/selection_controls_test.dart@@ -1,4 +1,7 @@+import "dart:async";+import "package:ente_components/ente_components.dart";+import "package:flutter/cupertino.dart";import "package:flutter/material.dart";import "package:flutter_test/flutter_test.dart";@@ -23,8 +26,9 @@ void main() {expect(nextValue, isTrue);});- testWidgets("RadioComponent toggles to the next selected value",- (tester) async {+ testWidgets("RadioComponent toggles to the next selected value", (+ tester,+ ) async {bool? nextValue;await tester.pumpWidget(@@ -42,8 +46,9 @@ void main() {expect(nextValue, isTrue);});- testWidgets("ToggleSwitchComponent toggles to the next selected value",- (tester) async {+ testWidgets("ToggleSwitchComponent toggles to the next selected value", (+ tester,+ ) async {bool? nextValue;await tester.pumpWidget(@@ -55,21 +60,166 @@ void main() {),);- await tester.tap(find.byType(InkWell));+ await tester.tap(find.byType(Switch));+ await tester.pump();++ expect(nextValue, isTrue);+ await tester.pump(const Duration(milliseconds: 200));+ });++ testWidgets("ToggleSwitchComponent shows async loading and success", (+ tester,+ ) async {+ var selected = false;+ final completer = Completer<void>();++ await tester.pumpWidget(+ _wrap(+ StatefulBuilder(+ builder: (context, setState) {+ return ToggleSwitchComponent.async(+ value: () => selected,+ onChanged: () async {+ await completer.future;+ setState(() => selected = !selected);+ },+ );+ },+ ),+ ),+ );++ await tester.tap(find.byType(Switch));+ await tester.pump(const Duration(milliseconds: 299));+ expect(find.byKey(const ValueKey('toggle-state-loading')), findsNothing);++ await tester.pump(const Duration(milliseconds: 1));+ expect(find.byKey(const ValueKey('toggle-state-loading')), findsOneWidget);++ completer.complete();+ await tester.pump(const Duration(milliseconds: 200));+ expect(find.byKey(const ValueKey('toggle-state-success')), findsOneWidget);++ await tester.pump(const Duration(seconds: 2));+ expect(find.byKey(const ValueKey('toggle-state-idle')), findsOneWidget);+ });++ testWidgets("ToggleSwitchComponent blocks repeat taps while updating", (+ tester,+ ) async {+ var selected = false;+ var changeCount = 0;+ final completer = Completer<void>();++ await tester.pumpWidget(+ _wrap(+ StatefulBuilder(+ builder: (context, setState) {+ return ToggleSwitchComponent.async(+ value: () => selected,+ onChanged: () async {+ changeCount += 1;+ await completer.future;+ setState(() => selected = !selected);+ },+ );+ },+ ),+ ),+ );++ await tester.tap(find.byType(Switch));+ await tester.pump();+ await tester.tap(find.byType(Switch));+ await tester.pump();++ expect(changeCount, 1);++ completer.complete();+ await tester.pump(const Duration(milliseconds: 200));+ });++ testWidgets("ToggleSwitchComponent rolls back when value is not confirmed", (+ tester,+ ) async {+ const selected = false;++ await tester.pumpWidget(+ _wrap(+ ToggleSwitchComponent.async(+ value: () => selected,+ onChanged: () async {},+ ),+ ),+ );++ await tester.tap(find.byType(Switch));+ await tester.pump();+ expect(tester.widget<Switch>(find.byType(Switch)).value, isTrue);++ await tester.pump(const Duration(milliseconds: 200));+ expect(tester.widget<Switch>(find.byType(Switch)).value, isFalse);+ });++ testWidgets("ToggleSwitchComponent rolls back after async errors", (+ tester,+ ) async {+ const selected = false;+ final completer = Completer<void>();++ await tester.pumpWidget(+ _wrap(+ ToggleSwitchComponent.async(+ value: () => selected,+ loadingDelay: const Duration(milliseconds: 1),+ onChanged: () => completer.future,+ ),+ ),+ );++ await tester.tap(find.byType(Switch));+ await tester.pump();+ expect(tester.widget<Switch>(find.byType(Switch)).value, isTrue);+ await tester.pump(const Duration(milliseconds: 1));+ expect(find.byKey(const ValueKey('toggle-state-loading')), findsOneWidget);++ completer.completeError(StateError('failed'));+ await tester.pump(const Duration(milliseconds: 200));++ expect(tester.widget<Switch>(find.byType(Switch)).value, isFalse);+ expect(find.byKey(const ValueKey('toggle-state-idle')), findsOneWidget);+ });++ testWidgets("ToggleSwitchComponent uses Cupertino switch on iOS", (+ tester,+ ) async {+ bool? nextValue;++ await tester.pumpWidget(+ _wrap(+ ToggleSwitchComponent(+ selected: false,+ onChanged: (value) => nextValue = value,+ ),+ platform: TargetPlatform.iOS,+ ),+ );++ await tester.tap(find.byType(CupertinoSwitch));await tester.pump();expect(nextValue, isTrue);+ expect(find.byType(Switch), findsNothing);+ await tester.pump(const Duration(milliseconds: 200));});- testWidgets("LabeledControlComponent renders label and subtitle",- (tester) async {+ testWidgets("LabeledControlComponent renders label and subtitle", (+ tester,+ ) async {await tester.pumpWidget(_wrap(const LabeledControlComponent(- control: CheckboxComponent(- selected: true,- onChanged: null,- ),+ control: CheckboxComponent(selected: true, onChanged: null),label: "Back up automatically",subtitle: "Includes new photos",),@@ -154,11 +304,9 @@ void main() {});}-Widget _wrap(Widget child) {+Widget _wrap(Widget child, {TargetPlatform platform = TargetPlatform.android}) {return MaterialApp(- theme: ComponentTheme.lightTheme(),- home: Scaffold(- body: Center(child: child),- ),+ theme: ComponentTheme.lightTheme().copyWith(platform: platform),+ home: Scaffold(body: Center(child: child)),);}