Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor: update UI components for Passkey and Two-Factor Recovery pages with GradientButton and improved theming

AmanRajSinghMourya02066230f1b4
diff --git a/mobile/packages/accounts/lib/pages/passkey_page.dart b/mobile/packages/accounts/lib/pages/passkey_page.dart
index 57b9f06afd..f92bddf87e 100644
--- a/mobile/packages/accounts/lib/pages/passkey_page.dart
+++ b/mobile/packages/accounts/lib/pages/passkey_page.dart
@@ -5,8 +5,8 @@ import 'package:ente_accounts/ente_accounts.dart';
import 'package:ente_accounts/models/errors.dart';
import 'package:ente_configuration/base_configuration.dart';
import 'package:ente_strings/ente_strings.dart';
-import 'package:ente_ui/components/buttons/button_widget.dart';
-import 'package:ente_ui/components/buttons/models/button_type.dart';
+import 'package:ente_ui/components/buttons/gradient_button.dart';
+import 'package:ente_ui/theme/ente_theme.dart';
import 'package:ente_ui/utils/dialog_util.dart';
import 'package:ente_ui/utils/toast_util.dart';
import 'package:ente_utils/navigation_util.dart';
@@ -140,10 +140,24 @@ class _PasskeyPageState extends State<PasskeyPage> {
@override
Widget build(BuildContext context) {
+ final colorScheme = getEnteColorScheme(context);
+
return Scaffold(
+ backgroundColor: colorScheme.backgroundBase,
appBar: AppBar(
- title: Text(
- context.strings.passkeyAuthTitle,
+ elevation: 0,
+ backgroundColor: colorScheme.backgroundBase,
+ centerTitle: true,
+ title: Image.asset(
+ 'assets/locker-logo-blue.png',
+ height: 24,
+ ),
+ leading: IconButton(
+ icon: const Icon(Icons.arrow_back),
+ color: colorScheme.primary700,
+ onPressed: () {
+ Navigator.of(context).pop();
+ },
),
),
body: _getBody(),
@@ -151,29 +165,37 @@ class _PasskeyPageState extends State<PasskeyPage> {
}
Widget _getBody() {
- return Center(
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return SafeArea(
child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 32),
+ padding: const EdgeInsets.symmetric(horizontal: 16),
child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.start,
children: [
+ const SizedBox(height: 12),
+ Text(
+ context.strings.passkeyAuthTitle,
+ style: textTheme.h3Bold.copyWith(
+ color: colorScheme.textBase,
+ ),
+ ),
Text(
context.strings.waitingForVerification,
- style: const TextStyle(
- height: 1.4,
- fontSize: 16,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textMuted,
),
),
- const SizedBox(height: 16),
- ButtonWidget(
- buttonType: ButtonType.primary,
- labelText: context.strings.tryAgain,
+ const SizedBox(height: 24),
+ GradientButton(
+ text: context.strings.tryAgain,
onTap: () => launchPasskey(),
),
const SizedBox(height: 16),
- ButtonWidget(
- buttonType: ButtonType.secondary,
- labelText: context.strings.checkStatus,
+ GradientButton(
+ text: context.strings.checkStatus,
+ buttonType: GradientButtonType.secondary,
onTap: () async {
try {
await checkStatus();
@@ -182,54 +204,51 @@ class _PasskeyPageState extends State<PasskeyPage> {
showGenericErrorDialog(context: context, error: e).ignore();
}
},
- shouldSurfaceExecutionStates: true,
),
- const Padding(padding: EdgeInsets.all(30)),
- if (widget.totp2FASessionID.isNotEmpty)
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- routeToPage(
- context,
- TwoFactorAuthenticationPage(
- widget.totp2FASessionID,
- ),
- );
- },
- child: Container(
- padding: const EdgeInsets.all(10),
- child: Center(
- child: Text(
- context.strings.loginWithTOTP,
- style: const TextStyle(
- decoration: TextDecoration.underline,
- fontSize: 12,
- ),
- ),
- ),
- ),
- ),
- GestureDetector(
- behavior: HitTestBehavior.opaque,
- onTap: () {
- UserService.instance.recoverTwoFactor(
- context,
- widget.sessionID,
- TwoFactorType.passkey,
- );
- },
- child: Container(
- padding: const EdgeInsets.all(10),
- child: Center(
+ const SizedBox(height: 16),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ widget.totp2FASessionID.isNotEmpty
+ ? GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ routeToPage(
+ context,
+ TwoFactorAuthenticationPage(
+ widget.totp2FASessionID,
+ ),
+ );
+ },
+ child: Text(
+ context.strings.loginWithTOTP,
+ style: textTheme.body.copyWith(
+ color: colorScheme.primary700,
+ decoration: TextDecoration.underline,
+ decorationColor: colorScheme.primary700,
+ ),
+ ),
+ )
+ : const SizedBox.shrink(),
+ GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () {
+ UserService.instance.recoverTwoFactor(
+ context,
+ widget.sessionID,
+ TwoFactorType.passkey,
+ );
+ },
child: Text(
context.strings.recoverAccount,
- style: const TextStyle(
+ style: textTheme.body.copyWith(
+ color: colorScheme.primary700,
decoration: TextDecoration.underline,
- fontSize: 12,
+ decorationColor: colorScheme.primary700,
),
),
),
- ),
+ ],
),
],
),
diff --git a/mobile/packages/accounts/lib/pages/password_entry_page.dart b/mobile/packages/accounts/lib/pages/password_entry_page.dart
index 7421dcc12b..4ca06f7cb2 100644
--- a/mobile/packages/accounts/lib/pages/password_entry_page.dart
+++ b/mobile/packages/accounts/lib/pages/password_entry_page.dart
@@ -477,7 +477,6 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
const SizedBox(height: 20),
GradientButton(
text: context.strings.doNotSignOut,
- backgroundColor: colorScheme.primary700,
onTap: () {
logOutFromOther = false;
Navigator.of(bottomSheetContext).pop();
diff --git a/mobile/packages/accounts/lib/pages/two_factor_recovery_page.dart b/mobile/packages/accounts/lib/pages/two_factor_recovery_page.dart
index 223d56b5c1..e6ccdafcf3 100644
--- a/mobile/packages/accounts/lib/pages/two_factor_recovery_page.dart
+++ b/mobile/packages/accounts/lib/pages/two_factor_recovery_page.dart
@@ -1,6 +1,6 @@
import 'package:ente_accounts/ente_accounts.dart';
import 'package:ente_strings/ente_strings.dart';
-import "package:ente_ui/components/buttons/gradient_button.dart";
+import 'package:ente_ui/components/buttons/dynamic_fab.dart';
import 'package:ente_ui/theme/ente_theme.dart';
import 'package:ente_utils/email_util.dart';
import 'package:flutter/material.dart';
@@ -26,12 +26,32 @@ class TwoFactorRecoveryPage extends StatefulWidget {
class _TwoFactorRecoveryPageState extends State<TwoFactorRecoveryPage> {
final _recoveryKey = TextEditingController();
+ Future<void> _onRecover() async {
+ await UserService.instance.removeTwoFactor(
+ context,
+ widget.type,
+ widget.sessionID,
+ _recoveryKey.text,
+ widget.encryptedSecret,
+ widget.secretDecryptionNonce,
+ );
+ }
+
@override
Widget build(BuildContext context) {
+ final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
+
+ FloatingActionButtonLocation? fabLocation() {
+ if (isKeypadOpen) {
+ return null;
+ } else {
+ return FloatingActionButtonLocation.centerFloat;
+ }
+ }
return Scaffold(
+ resizeToAvoidBottomInset: isKeypadOpen,
backgroundColor: colorScheme.backgroundBase,
appBar: AppBar(
elevation: 0,
@@ -49,102 +69,96 @@ class _TwoFactorRecoveryPageState extends State<TwoFactorRecoveryPage> {
},
),
),
- body: SafeArea(
- child: Column(
- children: [
- Expanded(
- child: SingleChildScrollView(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 24),
- Text(
- context.strings.recoveryKey,
- style: textTheme.bodyBold.copyWith(
- color: colorScheme.textBase,
- ),
+ body: _getBody(),
+ floatingActionButton: DynamicFAB(
+ isKeypadOpen: isKeypadOpen,
+ isFormValid: _recoveryKey.text.isNotEmpty,
+ buttonText: context.strings.recover,
+ onPressedFunction: _onRecover,
+ ),
+ floatingActionButtonLocation: fabLocation(),
+ floatingActionButtonAnimator: NoScalingAnimation(),
+ );
+ }
+
+ Widget _getBody() {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
+ return SafeArea(
+ child: Column(
+ children: [
+ Expanded(
+ child: SingleChildScrollView(
+ child: Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ Text(
+ context.strings.recoveryKey,
+ style: textTheme.bodyBold.copyWith(
+ color: colorScheme.textBase,
),
- const SizedBox(height: 8),
- TextFormField(
- decoration: InputDecoration(
- fillColor: colorScheme.backdropBase,
- filled: true,
- hintText: context.strings.enterRecoveryKeyHint,
- hintStyle: TextStyle(color: colorScheme.textMuted),
- contentPadding: const EdgeInsets.all(16),
- border: OutlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(8),
- ),
- enabledBorder: OutlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(8),
- ),
+ ),
+ const SizedBox(height: 8),
+ TextFormField(
+ decoration: InputDecoration(
+ fillColor: colorScheme.backdropBase,
+ filled: true,
+ hintText: context.strings.enterRecoveryKeyHint,
+ hintStyle: TextStyle(color: colorScheme.textMuted),
+ contentPadding: const EdgeInsets.all(16),
+ border: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
),
- style: textTheme.body.copyWith(
- color: colorScheme.textBase,
- fontFeatures: [const FontFeature.tabularFigures()],
+ enabledBorder: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
),
- controller: _recoveryKey,
- autofocus: false,
- autocorrect: false,
- keyboardType: TextInputType.multiline,
- maxLines: 4,
- minLines: 4,
- onChanged: (_) {
- setState(() {});
- },
),
- ],
- ),
- ),
- ),
- ),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: Column(
- children: [
- SizedBox(
- width: double.infinity,
- height: 56,
- child: GradientButton(
- onTap: _recoveryKey.text.isNotEmpty
- ? () async {
- await UserService.instance.removeTwoFactor(
- context,
- widget.type,
- widget.sessionID,
- _recoveryKey.text,
- widget.encryptedSecret,
- widget.secretDecryptionNonce,
- );
- }
- : null,
- text: context.strings.recover,
- ),
- ),
- const SizedBox(height: 16),
- GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () async {
- await openSupportPage(null, null);
- },
- child: Text(
- context.strings.noRecoveryKeyTitle,
- style: textTheme.small.copyWith(
- color: colorScheme.primary700,
- decoration: TextDecoration.underline,
- decorationColor: colorScheme.primary700,
+ style: textTheme.body.copyWith(
+ color: colorScheme.textBase,
+ fontFeatures: [const FontFeature.tabularFigures()],
),
+ controller: _recoveryKey,
+ autofocus: false,
+ autocorrect: false,
+ keyboardType: TextInputType.multiline,
+ maxLines: 4,
+ minLines: 4,
+ onChanged: (_) {
+ setState(() {});
+ },
+ ),
+ const SizedBox(height: 16),
+ Row(
+ mainAxisAlignment: MainAxisAlignment.end,
+ children: [
+ GestureDetector(
+ behavior: HitTestBehavior.translucent,
+ onTap: () async {
+ await openSupportPage(null, null);
+ },
+ child: Text(
+ context.strings.noRecoveryKeyTitle,
+ style: textTheme.small.copyWith(
+ color: colorScheme.primary700,
+ decoration: TextDecoration.underline,
+ decorationColor: colorScheme.primary700,
+ ),
+ ),
+ ),
+ ],
),
- ),
- ],
+ ],
+ ),
),
),
- ],
- ),
+ ),
+ ],
),
);
}
diff --git a/mobile/packages/ui/lib/components/buttons/gradient_button.dart b/mobile/packages/ui/lib/components/buttons/gradient_button.dart
index 696a145cfc..c5f9487d1e 100644
--- a/mobile/packages/ui/lib/components/buttons/gradient_button.dart
+++ b/mobile/packages/ui/lib/components/buttons/gradient_button.dart
@@ -1,12 +1,19 @@
+import 'package:ente_ui/theme/colors.dart';
import 'package:ente_ui/theme/ente_theme.dart';
import 'package:flutter/material.dart';
+enum GradientButtonType {
+ primary,
+ secondary,
+ critical,
+}
+
class GradientButton extends StatelessWidget {
final VoidCallback? onTap;
final String text;
final IconData? icon;
final double paddingValue;
- final Color? backgroundColor;
+ final GradientButtonType buttonType;
const GradientButton({
super.key,
@@ -14,7 +21,7 @@ class GradientButton extends StatelessWidget {
this.text = '',
this.icon,
this.paddingValue = 6.0,
- this.backgroundColor,
+ this.buttonType = GradientButtonType.primary,
});
static const TextStyle _textStyle = TextStyle(
@@ -28,10 +35,13 @@ class GradientButton extends StatelessWidget {
Widget build(BuildContext context) {
final colorScheme = getEnteColorScheme(context);
final bool isEnabled = onTap != null;
- final Color effectiveBackgroundColor = backgroundColor ??
- (isEnabled ? colorScheme.primary700 : colorScheme.fillFaint);
+
+ final Color effectiveBackgroundColor =
+ _getBackgroundColor(colorScheme, isEnabled);
+ final Color effectiveTextColor = _getTextColor(colorScheme, isEnabled);
+
final TextStyle effectiveTextStyle = _textStyle.copyWith(
- color: isEnabled ? Colors.white : colorScheme.textMuted,
+ color: effectiveTextColor,
);
final Widget textWidget = Text(text, style: effectiveTextStyle);
@@ -44,7 +54,7 @@ class GradientButton extends StatelessWidget {
children: [
Icon(
icon,
- color: isEnabled ? Colors.white : colorScheme.textMuted,
+ color: effectiveTextColor,
),
Padding(padding: EdgeInsets.symmetric(horizontal: paddingValue)),
if (text.isNotEmpty) textWidget,
@@ -68,4 +78,32 @@ class GradientButton extends StatelessWidget {
),
);
}
+
+ Color _getBackgroundColor(EnteColorScheme colorScheme, bool isEnabled) {
+ if (!isEnabled) {
+ return colorScheme.fillFaint;
+ }
+ switch (buttonType) {
+ case GradientButtonType.primary:
+ return colorScheme.primary700;
+ case GradientButtonType.secondary:
+ return colorScheme.backdropBase;
+ case GradientButtonType.critical:
+ return colorScheme.warning700;
+ }
+ }
+
+ Color _getTextColor(EnteColorScheme colorScheme, bool isEnabled) {
+ if (!isEnabled) {
+ return colorScheme.textMuted;
+ }
+ switch (buttonType) {
+ case GradientButtonType.primary:
+ return Colors.white;
+ case GradientButtonType.secondary:
+ return colorScheme.textBase;
+ case GradientButtonType.critical:
+ return Colors.white;
+ }
+ }
}