Skip to content

armgit / ente

Public Imported from GitHub
0

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

Add SecuritySectionWidget to settings page and refactor ToggleSwitchWidget logic

AmanRajSinghMourya9cd48277bc85
diff --git a/mobile/apps/locker/lib/ui/pages/settings_page.dart b/mobile/apps/locker/lib/ui/pages/settings_page.dart
index decba12607..fdd3ed7745 100644
--- a/mobile/apps/locker/lib/ui/pages/settings_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/settings_page.dart
@@ -10,6 +10,7 @@ import "package:locker/ui/components/usage_card_widget.dart";
import "package:locker/ui/settings/about_section_widget.dart";
import 'package:locker/ui/settings/account_section_widget.dart';
import "package:locker/ui/settings/app_version_widget.dart";
+import "package:locker/ui/settings/security_section_widget.dart";
import "package:locker/ui/settings/settings_title_bar_widget.dart";
import "package:locker/ui/settings/social_section_widget.dart";
import "package:locker/ui/settings/support_section_widget.dart";
@@ -77,11 +78,10 @@ class SettingsPage extends StatelessWidget {
sectionSpacing,
]);
- // TODO(aman): Re-add after app-lock is implemented w/ Locker designs
- // contents.addAll([
- // const SecuritySectionWidget(),
- // sectionSpacing,
- // ]);
+ contents.addAll([
+ const SecuritySectionWidget(),
+ sectionSpacing,
+ ]);
if (Platform.isAndroid ||
Platform.isWindows ||
diff --git a/mobile/apps/locker/lib/ui/settings/security_section_widget.dart b/mobile/apps/locker/lib/ui/settings/security_section_widget.dart
index f3a893041b..00111c32fe 100644
--- a/mobile/apps/locker/lib/ui/settings/security_section_widget.dart
+++ b/mobile/apps/locker/lib/ui/settings/security_section_widget.dart
@@ -12,7 +12,6 @@ import "package:ente_lock_screen/lock_screen_settings.dart";
import "package:ente_lock_screen/ui/lock_screen_options.dart";
import "package:ente_ui/components/captioned_text_widget.dart";
import "package:ente_ui/components/menu_item_widget.dart";
-import "package:ente_ui/components/toggle_switch_widget.dart";
import "package:ente_ui/utils/dialog_util.dart";
import "package:ente_ui/utils/toast_util.dart";
import "package:ente_utils/navigation_util.dart";
@@ -60,56 +59,56 @@ class _SecuritySectionWidgetState extends State<SecuritySectionWidget> {
Widget _getSectionOptions(BuildContext context) {
final l10n = context.l10n;
final List<Widget> children = [];
- if (_hasLoggedIn) {
- children.addAll(
- [
- sectionOptionSpacing,
- MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: l10n.emailVerificationToggle,
- makeTextBold: true,
- ),
- trailingWidget: ToggleSwitchWidget(
- value: () => UserService.instance.hasEmailMFAEnabled(),
- onChanged: () async {
- final hasAuthenticated = await LocalAuthenticationService
- .instance
- .requestLocalAuthentication(
- context,
- l10n.authToChangeEmailVerificationSetting,
- );
- final isEmailMFAEnabled =
- UserService.instance.hasEmailMFAEnabled();
- if (hasAuthenticated) {
- await updateEmailMFA(!isEmailMFAEnabled);
- }
- },
- ),
- ),
- sectionOptionSpacing,
- MenuItemWidget(
- captionedTextWidget: CaptionedTextWidget(
- title: context.l10n.passkey,
- makeTextBold: true,
- ),
- trailingIcon: Icons.chevron_right_outlined,
- onTap: () async {
- final hasAuthenticated = await LocalAuthenticationService.instance
- .requestLocalAuthentication(
- context,
- l10n.authToViewPasskey,
- );
- if (hasAuthenticated) {
- await onPasskeyClick(context);
- }
- },
- ),
- sectionOptionSpacing,
- ],
- );
- } else {
- children.add(sectionOptionSpacing);
- }
+ // if (_hasLoggedIn) {
+ // children.addAll(
+ // [
+ // sectionOptionSpacing,
+ // MenuItemWidget(
+ // captionedTextWidget: CaptionedTextWidget(
+ // title: l10n.emailVerificationToggle,
+ // makeTextBold: true,
+ // ),
+ // trailingWidget: ToggleSwitchWidget(
+ // value: () => UserService.instance.hasEmailMFAEnabled(),
+ // onChanged: () async {
+ // final hasAuthenticated = await LocalAuthenticationService
+ // .instance
+ // .requestLocalAuthentication(
+ // context,
+ // l10n.authToChangeEmailVerificationSetting,
+ // );
+ // final isEmailMFAEnabled =
+ // UserService.instance.hasEmailMFAEnabled();
+ // if (hasAuthenticated) {
+ // await updateEmailMFA(!isEmailMFAEnabled);
+ // }
+ // },
+ // ),
+ // ),
+ // sectionOptionSpacing,
+ // MenuItemWidget(
+ // captionedTextWidget: CaptionedTextWidget(
+ // title: context.l10n.passkey,
+ // makeTextBold: true,
+ // ),
+ // trailingIcon: Icons.chevron_right_outlined,
+ // onTap: () async {
+ // final hasAuthenticated = await LocalAuthenticationService.instance
+ // .requestLocalAuthentication(
+ // context,
+ // l10n.authToViewPasskey,
+ // );
+ // if (hasAuthenticated) {
+ // await onPasskeyClick(context);
+ // }
+ // },
+ // ),
+ // sectionOptionSpacing,
+ // ],
+ // );
+ // } else {
+ // children.add(sectionOptionSpacing);
+ // }
children.addAll([
sectionOptionSpacing,
MenuItemWidget(
diff --git a/mobile/packages/ui/lib/components/toggle_switch_widget.dart b/mobile/packages/ui/lib/components/toggle_switch_widget.dart
index 438bcf177f..c9886f8a90 100644
--- a/mobile/packages/ui/lib/components/toggle_switch_widget.dart
+++ b/mobile/packages/ui/lib/components/toggle_switch_widget.dart
@@ -1,8 +1,11 @@
+import 'dart:io';
+
import 'package:ente_base/typedefs.dart';
import 'package:ente_ui/components/loading_widget.dart';
import 'package:ente_ui/models/execution_states.dart';
import 'package:ente_ui/theme/ente_theme.dart';
import 'package:ente_utils/debouncer.dart';
+import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
typedef OnChangedCallBack = void Function(bool);
@@ -51,53 +54,23 @@ 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: Colors.transparent,
+ 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: _onChanged,
+ )
+ : CupertinoSwitch(
+ value: toggleValue ?? false,
+ onChanged: _onChanged,
+ ),
),
),
],
@@ -125,6 +98,51 @@ class _ToggleSwitchWidgetState extends State<ToggleSwitchWidget> {
}
}
+ Future<void> _onChanged(bool negationOfToggleValue) async {
+ if (!mounted) return;
+ setState(() {
+ toggleValue = negationOfToggleValue;
+ //start showing inProgress statu icons if toggle takes more than debounce time
+ _debouncer.run(
+ () => Future(
+ () {
+ if (!mounted) return;
+ 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();
+ if (!mounted) return;
+ setState(() {
+ if (toggleValue == newValue) {
+ if (executionState == ExecutionState.inProgress) {
+ executionState = ExecutionState.successful;
+ Future.delayed(const Duration(seconds: 2), () {
+ if (!mounted) return;
+ setState(() {
+ executionState = ExecutionState.idle;
+ });
+ });
+ }
+ } else {
+ toggleValue = !toggleValue!;
+ executionState = ExecutionState.idle;
+ }
+ });
+ }
+
Future<void> _feedbackOnUnsuccessfulToggle(Stopwatch stopwatch) async {
final timeElapsed = stopwatch.elapsedMilliseconds;
if (timeElapsed < 200) {