π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Align auth toggle switch with shared photos styling
Prateek Sunal6da03bcfc34c
diff --git a/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dart b/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dartindex 207bdcf905..d376377ae7 100644--- a/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dart+++ b/mobile/apps/auth/lib/ui/components/toggle_switch_widget.dart@@ -1,9 +1,12 @@+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/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);@@ -52,59 +55,70 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {height: 31,child: FittedBox(fit: BoxFit.contain,- child: Switch.adaptive(- activeColor: enteColorScheme.primary400,- activeTrackColor: enteColorScheme.primary300,- inactiveTrackColor: enteColorScheme.fillMuted,- materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,- value: toggleValue ?? false,- onChanged: (negationOfToggleValue) async {- setState(() {- toggleValue = negationOfToggleValue;- //start showing inProgress statu icons if toggle takes more than debounce time- _debouncer.run(- () => Future(- () {- setState(() {- executionState = ExecutionState.inProgress;- });- },+ child: Platform.isAndroid+ ? Switch(+ inactiveTrackColor: enteColorScheme.fillMuted,+ activeTrackColor: enteColorScheme.primary500,+ activeColor: Colors.white,+ inactiveThumbColor: enteColorScheme.primary500,+ trackOutlineColor: WidgetStateColor.resolveWith(+ (states) => enteColorScheme.primary500,),- );- });- 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;- }- });- },- ),+ 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);