π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
fix: update color for iOS toggle
Prateek Sunal947842d50f04
diff --git a/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dart b/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dartdeleted file mode 100644index d376377ae7..0000000000--- a/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dart+++ /dev/null@@ -1,151 +0,0 @@-import "dart:io";--import 'package:ente_auth/ente_theme_data.dart';-import 'package:ente_auth/models/execution_states.dart';-import 'package:ente_auth/theme/colors.dart';-import 'package:ente_auth/ui/common/loading_widget.dart';-import 'package:ente_auth/utils/debouncer.dart';-import 'package:ente_base/typedefs.dart';-import 'package:flutter/cupertino.dart';-import 'package:flutter/material.dart';--typedef OnChangedCallBack = void Function(bool);--class ToggleSwitchWidget extends StatefulWidget {- final BoolCallBack value;- final FutureVoidCallback onChanged;- const ToggleSwitchWidget({- required this.value,- required this.onChanged,- super.key,- });-- @override- State<ToggleSwitchWidget> createState() => _ToggleSwitchWidgetState();-}--class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {- bool? toggleValue;- ExecutionState executionState = ExecutionState.idle;- final _debouncer = Debouncer(const Duration(milliseconds: 300));-- @override- void initState() {- toggleValue = widget.value.call();- super.initState();- }-- @override- Widget build(BuildContext context) {- final enteColorScheme = Theme.of(context).colorScheme.enteTheme.colorScheme;- final Widget stateIcon = _stateIcon(enteColorScheme);-- return Row(- children: [- Padding(- padding: const EdgeInsets.only(right: 2),- child: AnimatedSwitcher(- duration: const Duration(milliseconds: 175),- switchInCurve: Curves.easeInExpo,- switchOutCurve: Curves.easeOutExpo,- child: stateIcon,- ),- ),- SizedBox(- height: 31,- child: FittedBox(- fit: BoxFit.contain,- child: Platform.isAndroid- ? Switch(- inactiveTrackColor: enteColorScheme.fillMuted,- activeTrackColor: enteColorScheme.primary500,- activeColor: Colors.white,- inactiveThumbColor: enteColorScheme.primary500,- trackOutlineColor: WidgetStateColor.resolveWith(- (states) => enteColorScheme.primary500,- ),- materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,- value: toggleValue ?? false,- onChanged: _handleToggleChange,- )- : CupertinoSwitch(- value: toggleValue ?? false,- onChanged: _handleToggleChange,- ),- ),- ),- ],- );- }-- Future<void> _handleToggleChange(bool negationOfToggleValue) async {- setState(() {- toggleValue = negationOfToggleValue;- //start showing inProgress statu icons if toggle takes more than debounce time- _debouncer.run(- () => Future(- () {- setState(() {- executionState = ExecutionState.inProgress;- });- },- ),- );- });- final Stopwatch stopwatch = Stopwatch()..start();- await widget.onChanged.call().onError(- (error, stackTrace) => _debouncer.cancelDebounce(),- );- //for toggle feedback on short unsuccessful onChanged- await _feedbackOnUnsuccessfulToggle(stopwatch);- //debouncer gets canceled if onChanged takes less than debounce time- _debouncer.cancelDebounce();-- final newValue = widget.value.call();- setState(() {- if (toggleValue == newValue) {- if (executionState == ExecutionState.inProgress) {- executionState = ExecutionState.successful;- Future.delayed(const Duration(seconds: 2), () {- setState(() {- executionState = ExecutionState.idle;- });- });- }- } else {- toggleValue = !toggleValue!;- executionState = ExecutionState.idle;- }- });- }-- Widget _stateIcon(EnteColorScheme enteColorScheme) {- if (executionState == ExecutionState.idle) {- return const SizedBox(width: 24);- } else if (executionState == ExecutionState.inProgress) {- return EnteLoadingWidget(- color: enteColorScheme.strokeMuted,- );- } else if (executionState == ExecutionState.successful) {- return Padding(- padding: const EdgeInsets.symmetric(horizontal: 1),- child: Icon(- Icons.check_outlined,- size: 22,- color: enteColorScheme.primary500,- ),- );- } else {- return const SizedBox(width: 24);- }- }-- Future<void> _feedbackOnUnsuccessfulToggle(Stopwatch stopwatch) async {- final timeElapsed = stopwatch.elapsedMilliseconds;- if (timeElapsed < 200) {- await Future.delayed(- Duration(milliseconds: 200 - timeElapsed),- );- }- }-}diff --git a/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart b/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dartindex 8a097e78d4..19d1cdc69f 100644--- a/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart+++ b/mobile/apps/auth/lib/ui/settings/data/local_backup_settings_page.dart@@ -4,9 +4,9 @@ import 'package:ente_auth/ui/components/captioned_text_widget.dart';import 'package:ente_auth/ui/components/menu_item_widget.dart';import 'package:ente_auth/ui/components/title_bar_title_widget.dart';import 'package:ente_auth/ui/components/title_bar_widget.dart';-import 'package:ente_auth/ui/components/toggle_switch_widget.dart';import 'package:ente_auth/ui/settings/data/local_backup/local_backup_experience.dart';import 'package:ente_ui/components/constrained_custom_scroll_view.dart';+import 'package:ente_ui/components/toggle_switch_widget.dart';import 'package:flutter/foundation.dart';import 'package:flutter/material.dart';diff --git a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart b/mobile/apps/auth/lib/ui/settings/general_section_widget.dartindex 443fd1d804..981b2b56a3 100644--- a/mobile/apps/auth/lib/ui/settings/general_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/general_section_widget.dart@@ -9,7 +9,6 @@ import 'package:ente_auth/theme/ente_theme.dart';import 'package:ente_auth/ui/components/captioned_text_widget.dart';import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';import 'package:ente_auth/ui/components/menu_item_widget.dart';-import 'package:ente_auth/ui/components/toggle_switch_widget.dart';import 'package:ente_auth/ui/settings/common_settings.dart';import 'package:ente_auth/ui/settings/language_picker.dart';import 'package:ente_auth/utils/navigation_util.dart';@@ -17,6 +16,7 @@ import 'package:ente_auth/utils/platform_util.dart';import 'package:ente_auth/utils/toast_util.dart';import 'package:ente_events/event_bus.dart';import 'package:ente_logging/logging.dart';+import 'package:ente_ui/components/toggle_switch_widget.dart';import 'package:flutter/material.dart';class AdvancedSectionWidget extends StatefulWidget {diff --git a/mobile/apps/auth/lib/ui/settings/security_section_widget.dart b/mobile/apps/auth/lib/ui/settings/security_section_widget.dartindex 5969967688..ad5bbbe1f4 100644--- a/mobile/apps/auth/lib/ui/settings/security_section_widget.dart+++ b/mobile/apps/auth/lib/ui/settings/security_section_widget.dart@@ -14,7 +14,6 @@ import 'package:ente_auth/ui/components/captioned_text_widget.dart';import 'package:ente_auth/ui/components/expandable_menu_item_widget.dart';import 'package:ente_auth/ui/components/menu_item_widget.dart';import 'package:ente_auth/ui/components/models/button_result.dart';-import 'package:ente_auth/ui/components/toggle_switch_widget.dart';import 'package:ente_auth/ui/settings/common_settings.dart';import 'package:ente_auth/utils/dialog_util.dart';import 'package:ente_auth/utils/navigation_util.dart';@@ -23,6 +22,7 @@ import 'package:ente_crypto_dart/ente_crypto_dart.dart';import 'package:ente_lock_screen/local_authentication_service.dart';import 'package:ente_lock_screen/lock_screen_settings.dart';import 'package:ente_lock_screen/ui/lock_screen_options.dart';+import 'package:ente_ui/components/toggle_switch_widget.dart';import 'package:flutter/material.dart';import 'package:logging/logging.dart';diff --git a/mobile/packages/ui/lib/components/toggle_switch_widget.dart b/mobile/packages/ui/lib/components/toggle_switch_widget.dartindex ab56cf6ff4..491a8c4177 100644--- a/mobile/packages/ui/lib/components/toggle_switch_widget.dart+++ b/mobile/packages/ui/lib/components/toggle_switch_widget.dart@@ -38,6 +38,7 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {Widget build(BuildContext context) {final enteColorScheme = getEnteColorScheme(context);final Widget stateIcon = _stateIcon(enteColorScheme);+ final isDarwin = Platform.isIOS || Platform.isMacOS;return Row(children: [@@ -54,7 +55,7 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {height: 31,child: FittedBox(fit: BoxFit.contain,- child: Platform.isAndroid+ child: !isDarwin? Switch(inactiveTrackColor: enteColorScheme.fillMuted,activeTrackColor: enteColorScheme.primary500,@@ -68,6 +69,9 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {onChanged: _handleToggleChange,): CupertinoSwitch(+ activeColor: enteColorScheme.primary500,+ trackColor: enteColorScheme.fillMuted,+ thumbColor: Colors.white,value: toggleValue ?? false,onChanged: _handleToggleChange,),