π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Migrate Auth session dialog components
Neeraj Guptaf6c604bd5253
diff --git a/mobile/apps/auth/lib/ui/account/logout_dialog.dart b/mobile/apps/auth/lib/ui/account/logout_dialog.dartindex 4f55a0a699..c8cfac958f 100644--- a/mobile/apps/auth/lib/ui/account/logout_dialog.dart+++ b/mobile/apps/auth/lib/ui/account/logout_dialog.dart@@ -14,48 +14,35 @@ Future<void> autoLogoutAlert(BuildContext context) async {try {showingLogoutDialog = true;final l10n = context.l10n;- final AlertDialog alert = AlertDialog(- title: Text(l10n.sessionExpired),- content: Text(l10n.pleaseLoginAgain),- actions: [- TextButton(- child: Text(- l10n.ok,- style: TextStyle(color: Theme.of(context).colorScheme.primary),- ),- onPressed: () async {- Navigator.of(context, rootNavigator: true).pop('dialog');- Navigator.of(context).popUntil((route) => route.isFirst);- int pendingSyncCount = await AuthenticatorDB.instance- .getNeedSyncCount();- if (pendingSyncCount > 0) {- if (!context.mounted) return;- // ignore: unawaited_futures- showChoiceActionSheet(- context,- title: l10n.pendingSyncs,- body: l10n.pendingSyncsWarningBody,- firstButtonLabel: context.l10n.yesLogout,- isCritical: true,- firstButtonOnTap: () async {- await _logout(context, l10n);- },- );- } else {- if (!context.mounted) return;- await _logout(context, l10n);- }- },- ),- ],- );- await showDialog(- context: context,- barrierDismissible: false,- builder: (BuildContext context) {- return alert;- },+ await showErrorDialog(+ context,+ l10n.sessionExpired,+ l10n.pleaseLoginAgain,+ isDismissable: false,+ showContactSupport: false,+ dismissButtonLabel: l10n.ok,+ useRootNavigator: true,);+ if (!context.mounted) return;++ Navigator.of(context).popUntil((route) => route.isFirst);+ final pendingSyncCount = await AuthenticatorDB.instance.getNeedSyncCount();+ if (!context.mounted) return;+ if (pendingSyncCount > 0) {+ // ignore: unawaited_futures+ showChoiceActionSheet(+ context,+ title: l10n.pendingSyncs,+ body: l10n.pendingSyncsWarningBody,+ firstButtonLabel: context.l10n.yesLogout,+ isCritical: true,+ firstButtonOnTap: () async {+ await _logout(context, l10n);+ },+ );+ } else {+ await _logout(context, l10n);+ }} catch (e) {Logger("LogoutDialog").severe('failed to process sign out action', e);} finally {diff --git a/mobile/apps/auth/lib/ui/common/dialogs.dart b/mobile/apps/auth/lib/ui/common/dialogs.dartdeleted file mode 100644index 46dec2a681..0000000000--- a/mobile/apps/auth/lib/ui/common/dialogs.dart+++ /dev/null@@ -1,122 +0,0 @@-import 'package:ente_auth/ente_theme_data.dart';-import 'package:ente_auth/ui/components/buttons/button_widget.dart';-import 'package:ente_auth/ui/components/dialog_widget.dart';-import 'package:ente_auth/ui/components/models/button_result.dart';-import 'package:ente_auth/ui/components/models/button_type.dart';-import 'package:ente_base/typedefs.dart';-import 'package:flutter/material.dart';--enum DialogUserChoice { firstChoice, secondChoice }--enum ActionType { confirm, critical }--// if dialog is dismissed by tapping outside, this will return null-Future<DialogUserChoice?> showChoiceDialogOld<T>(- BuildContext context,- String title,- String content, {- String firstAction = 'Ok',- Color? firstActionColor,- String secondAction = 'Cancel',- Color? secondActionColor,- ActionType actionType = ActionType.confirm,-}) {- final AlertDialog alert = AlertDialog(- title: Text(- title,- style: TextStyle(- color: actionType == ActionType.critical- ? Colors.red- : Theme.of(context).colorScheme.primary,- ),- ),- content: Text(content, style: const TextStyle(height: 1.4)),- actions: [- TextButton(- child: Text(- firstAction,- style: TextStyle(- color:- firstActionColor ??- (actionType == ActionType.critical- ? Colors.red- : Theme.of(context).colorScheme.onSurface),- ),- ),- onPressed: () {- Navigator.of(- context,- rootNavigator: true,- ).pop(DialogUserChoice.firstChoice);- },- ),- TextButton(- child: Text(- secondAction,- style: TextStyle(- color:- secondActionColor ??- Theme.of(context).colorScheme.alternativeColor,- ),- ),- onPressed: () {- Navigator.of(- context,- rootNavigator: true,- ).pop(DialogUserChoice.secondChoice);- },- ),- ],- );-- return showDialog<DialogUserChoice>(- context: context,- builder: (BuildContext context) {- return alert;- },- barrierColor: Colors.black87,- );-}--///Will return null if dismissed by tapping outside-Future<ButtonResult?> showChoiceDialog(- BuildContext context, {- required String title,- String? body,- required String firstButtonLabel,- String secondButtonLabel = "Cancel",- ButtonType firstButtonType = ButtonType.neutral,- ButtonType secondButtonType = ButtonType.secondary,- ButtonAction firstButtonAction = ButtonAction.first,- ButtonAction secondButtonAction = ButtonAction.cancel,- FutureVoidCallback? firstButtonOnTap,- FutureVoidCallback? secondButtonOnTap,- bool isCritical = false,- IconData? icon,- bool isDismissible = true,-}) async {- final buttons = [- ButtonWidget(- buttonType: isCritical ? ButtonType.critical : firstButtonType,- labelText: firstButtonLabel,- isInAlert: true,- onTap: firstButtonOnTap,- buttonAction: firstButtonAction,- ),- ButtonWidget(- buttonType: secondButtonType,- labelText: secondButtonLabel,- isInAlert: true,- onTap: secondButtonOnTap,- buttonAction: secondButtonAction,- ),- ];- return showDialogWidget(- context: context,- title: title,- body: body,- buttons: buttons,- icon: icon,- isDismissible: isDismissible,- );-}diff --git a/mobile/apps/auth/lib/ui/common/dynamic_fab.dart b/mobile/apps/auth/lib/ui/common/dynamic_fab.dartdeleted file mode 100644index 449f729e48..0000000000--- a/mobile/apps/auth/lib/ui/common/dynamic_fab.dart+++ /dev/null@@ -1,97 +0,0 @@-import 'dart:math' as math;--import 'package:ente_auth/ente_theme_data.dart';-import 'package:flutter/material.dart';--class DynamicFAB extends StatelessWidget {- final bool? isKeypadOpen;- final bool? isFormValid;- final String? buttonText;- final Function? onPressedFunction;-- const DynamicFAB({- super.key,- this.isKeypadOpen,- this.buttonText,- this.isFormValid,- this.onPressedFunction,- });-- @override- Widget build(BuildContext context) {- if (isKeypadOpen!) {- return Container(- decoration: BoxDecoration(- boxShadow: [- BoxShadow(- color: Theme.of(context).colorScheme.surface,- spreadRadius: 200,- blurRadius: 100,- offset: const Offset(0, 230),- ),- ],- ),- width: double.infinity,- child: Row(- mainAxisAlignment: MainAxisAlignment.end,- children: [- Semantics(- button: true,- container: true,- excludeSemantics: true,- identifier: 'auth_dynamic_fab',- label: buttonText,- child: FloatingActionButton(- heroTag: 'FAB',- backgroundColor: Theme.of(- context,- ).colorScheme.dynamicFABBackgroundColor,- foregroundColor: Theme.of(- context,- ).colorScheme.dynamicFABTextColor,- onPressed: isFormValid!- ? onPressedFunction as void Function()?- : () {- FocusScope.of(context).unfocus();- },- child: Transform.rotate(- angle: isFormValid! ? 0 : math.pi / 2,- child: const Icon(Icons.chevron_right, size: 36),- ), //keypad down here- ),- ),- ],- ),- );- } else {- return Container(- width: double.infinity,- height: 56,- padding: const EdgeInsets.symmetric(horizontal: 20),- child: OutlinedButton(- onPressed: isFormValid!- ? onPressedFunction as void Function()?- : null,- child: Text(buttonText!),- ),- );- }- }-}--class NoScalingAnimation extends FloatingActionButtonAnimator {- @override- Offset getOffset({Offset? begin, required Offset end, double? progress}) {- return end;- }-- @override- Animation<double> getRotationAnimation({required Animation<double> parent}) {- return Tween<double>(begin: 1.0, end: 1.0).animate(parent);- }-- @override- Animation<double> getScaleAnimation({required Animation<double> parent}) {- return Tween<double>(begin: 1.0, end: 1.0).animate(parent);- }-}diff --git a/mobile/apps/auth/lib/utils/dialog_util.dart b/mobile/apps/auth/lib/utils/dialog_util.dartindex b95cef4f8b..61f953c226 100644--- a/mobile/apps/auth/lib/utils/dialog_util.dart+++ b/mobile/apps/auth/lib/utils/dialog_util.dart@@ -28,12 +28,15 @@ Future<ButtonResult?> showErrorDialog(String? body, {bool isDismissable = true,bool showContactSupport = true,+ String dismissButtonLabel = "OK",+ bool useRootNavigator = false,}) async {return showDialogWidget(context: context,title: title,body: body,isDismissible: isDismissable,+ useRootNavigator: useRootNavigator,buttons: [if (showContactSupport)ButtonWidget(@@ -45,9 +48,9 @@ Future<ButtonResult?> showErrorDialog(await sendEmail(context, to: "[email protected]", body: body);},),- const ButtonWidget(+ ButtonWidget(buttonType: ButtonType.secondary,- labelText: "OK",+ labelText: dismissButtonLabel,isInAlert: true,buttonAction: ButtonAction.second,),