Skip to content

armgit / ente

Public Imported from GitHub
0

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

refactor: Remove unused LoginPage and update UI components for better consistency

AmanRajSinghMourya849273d4aefd
diff --git a/mobile/apps/locker/lib/ui/pages/login_page.dart b/mobile/apps/locker/lib/ui/pages/login_page.dart
deleted file mode 100644
index e197ea5155..0000000000
--- a/mobile/apps/locker/lib/ui/pages/login_page.dart
+++ /dev/null
@@ -1,472 +0,0 @@
-import 'package:dio/dio.dart';
-import 'package:email_validator/email_validator.dart';
-import 'package:ente_accounts/ente_accounts.dart';
-import 'package:ente_accounts/models/errors.dart';
-import "package:ente_crypto_dart/ente_crypto_dart.dart";
-import 'package:ente_ui/components/buttons/button_widget.dart';
-import 'package:ente_ui/theme/ente_theme.dart';
-import 'package:ente_ui/utils/dialog_util.dart';
-import 'package:flutter/material.dart';
-import 'package:locker/l10n/l10n.dart';
-import 'package:locker/services/configuration.dart';
-import "package:locker/ui/components/gradient_button.dart";
-import 'package:locker/ui/components/new_account_dialog.dart';
-import 'package:logging/logging.dart';
-import 'package:url_launcher/url_launcher.dart';
-
-class LoginPage extends StatefulWidget {
- const LoginPage({super.key});
-
- @override
- State<LoginPage> createState() => _LoginPageState();
-}
-
-class _LoginPageState extends State<LoginPage> {
- final Logger _logger = Logger('LoginPageState');
- String? _email;
- bool _emailIsValid = false;
- bool _passwordVisible = false;
- bool _isLoggingIn = false;
- Color? _emailInputFieldColor;
- final _passwordController = TextEditingController();
- final FocusNode _passwordFocusNode = FocusNode();
-
- @override
- void initState() {
- super.initState();
- _email = Configuration.instance.getEmail();
- if (_email != null) {
- _emailIsValid = EmailValidator.validate(_email!);
- }
- }
-
- @override
- void dispose() {
- _passwordController.dispose();
- _passwordFocusNode.dispose();
- super.dispose();
- }
-
- Future<void> _handleLogin() async {
- // Prevent multiple simultaneous login attempts
- if (_isLoggingIn) return;
-
- setState(() {
- _isLoggingIn = true;
- });
-
- FocusScope.of(context).unfocus();
- final dialog = createProgressDialog(
- context,
- context.l10n.pleaseWait,
- isDismissible: true,
- );
- await dialog.show();
-
- try {
- await UserService.instance.setEmail(_email!);
- Configuration.instance.resetVolatilePassword();
- SrpAttributes? attr;
- bool isEmailVerificationEnabled = true;
- try {
- attr = await UserService.instance.getSrpAttributes(_email!);
- isEmailVerificationEnabled = attr.isEmailMFAEnabled;
- } catch (e) {
- if (e is! SrpSetupNotCompleteError) {
- _logger.severe('Error getting SRP attributes', e);
- }
- }
-
- await dialog.hide();
-
- final password = _passwordController.text;
- if (attr != null && !isEmailVerificationEnabled && password.isNotEmpty) {
- await _verifyPassword(attr, password);
- } else {
- await UserService.instance.sendOtt(
- context,
- _email!,
- isCreateAccountScreen: false,
- purpose: 'login',
- );
- }
- } catch (e) {
- await dialog.hide();
- _logger.severe('Login error', e);
- await showGenericErrorDialog(context: context, error: e);
- } finally {
- if (mounted) {
- setState(() {
- _isLoggingIn = false;
- });
- }
- }
- }
-
- Future<void> _verifyPassword(
- SrpAttributes srpAttributes,
- String password,
- ) async {
- final dialog = createProgressDialog(
- context,
- context.l10n.pleaseWait,
- isDismissible: true,
- );
- await dialog.show();
-
- try {
- await UserService.instance.verifyEmailViaPassword(
- context,
- srpAttributes,
- password,
- dialog,
- );
- } on DioException catch (e, s) {
- await dialog.hide();
- final enteErrCode = e.response?.data is Map<String, dynamic>
- ? e.response?.data["code"]
- : null;
- if (e.response != null && e.response!.statusCode == 401) {
- _logger.severe('Server reject, failed verify SRP login', e, s);
- await showErrorDialog(
- context,
- context.l10n.incorrectPassword,
- context.l10n.pleaseTryAgain,
- );
- } else {
- _logger.severe('API failure during SRP login ${e.type}', e, s);
- if (e.type == DioExceptionType.connectionTimeout ||
- e.type == DioExceptionType.receiveTimeout ||
- e.type == DioExceptionType.sendTimeout) {
- await showErrorDialog(
- context,
- context.l10n.noInternetConnection,
- context.l10n.checkInternetConnection,
- );
- } else if (enteErrCode != null &&
- enteErrCode == 'LOCKER_REGISTRATION_DISABLED') {
- await showErrorDialog(
- context,
- context.l10n.oops,
- context.l10n.unlockLockerNewUserBody,
- );
- } else if (enteErrCode != null &&
- enteErrCode == 'LOCKER_ROLLOUT_LIMIT') {
- await showErrorDialog(
- context,
- "We're out of beta seats for now",
- "This preview access has reached capacity. We'll be opening it to more users soon.",
- );
- } else {
- await showErrorDialog(
- context,
- context.l10n.somethingWentWrong,
- context.l10n.verificationFailedTryAgain,
- );
- }
- }
- } catch (e, s) {
- _logger.info('error during loginViaPassword', e);
- await dialog.hide();
- if (e is LoginKeyDerivationError) {
- _logger.severe('loginKey derivation error', e, s);
- await UserService.instance.sendOtt(
- context,
- _email!,
- isCreateAccountScreen: true,
- );
- return;
- } else if (e is KeyDerivationError) {
- final dialogChoice = await showChoiceDialog(
- context,
- title: context.l10n.recreatePassword,
- body: context.l10n.deviceCannotVerifyPassword,
- firstButtonLabel: context.l10n.useRecoveryKey,
- );
- if (dialogChoice!.action == ButtonAction.first) {
- await UserService.instance.sendOtt(
- context,
- _email!,
- isResetPasswordScreen: true,
- );
- }
- return;
- } else {
- _logger.severe('unexpected error while verifying password', e, s);
- await _showContactSupportDialog(
- context,
- context.l10n.oops,
- context.l10n.verificationFailedTryAgain,
- );
- }
- }
- }
-
- Future<void> _showContactSupportDialog(
- BuildContext context,
- String title,
- String message,
- ) async {
- final dialogChoice = await showChoiceDialog(
- context,
- title: title,
- body: message,
- firstButtonLabel: context.l10n.contactSupport,
- secondButtonLabel: context.l10n.ok,
- );
- if (dialogChoice!.action == ButtonAction.first) {
- final Uri emailUri = Uri(
- scheme: 'mailto',
- query:
- 'subject=${Uri.encodeComponent(context.l10n.lockerLoginIssueSubject)}',
- );
- if (await canLaunchUrl(emailUri)) {
- await launchUrl(emailUri);
- }
- }
- }
-
- void _handleForgotPassword() async {
- if (_email == null || !_emailIsValid) {
- await showErrorDialog(
- context,
- context.l10n.invalidEmail,
- context.l10n.enterValidEmailFirst,
- );
- return;
- }
-
- await UserService.instance.sendOtt(
- context,
- _email!,
- isResetPasswordScreen: true,
- );
- }
-
- void _handleSignUp() {
- showCreateNewAccountDialog(
- context,
- title: context.l10n.unlockLockerNewUserTitle,
- body: context.l10n.unlockLockerNewUserBody,
- buttonLabel: context.l10n.okay,
- assetPath: "assets/file_lock.png",
- );
- }
-
- void updateEmail(String value) {
- _email = value.trim();
- _emailIsValid = EmailValidator.validate(_email!);
- }
-
- @override
- Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
- final textTheme = getEnteTextTheme(context);
- final l10n = context.l10n;
-
- return Scaffold(
- backgroundColor: colorScheme.backgroundBase,
- appBar: AppBar(
- title: Image.asset(
- 'assets/locker-logo-blue.png',
- height: 28,
- ),
- centerTitle: true,
- backgroundColor: colorScheme.backgroundBase,
- elevation: 0,
- leading: IconButton(
- icon: Icon(
- Icons.arrow_back,
- color: colorScheme.primary700,
- ),
- onPressed: () => Navigator.of(context).pop(),
- ),
- ),
- body: SafeArea(
- child: Padding(
- padding: const EdgeInsets.symmetric(horizontal: 24.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- Expanded(
- child: AutofillGroup(
- child: SingleChildScrollView(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- const SizedBox(height: 24),
- Text(
- l10n.emailIdLabel,
- style: textTheme.bodyBold.copyWith(
- color: colorScheme.textBase,
- ),
- ),
- const SizedBox(height: 8),
- TextFormField(
- key: const ValueKey("emailInputField"),
- autofillHints: const [AutofillHints.email],
- decoration: InputDecoration(
- hintText: l10n.emailIdHint,
- hintStyle: textTheme.body.copyWith(
- color: colorScheme.textMuted,
- ),
- fillColor:
- _emailInputFieldColor ?? colorScheme.fillFaint,
- filled: true,
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 14,
- ),
- border: OutlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(8),
- ),
- suffixIcon: _emailIsValid
- ? Icon(
- Icons.check,
- size: 20,
- color: colorScheme.primary700,
- )
- : null,
- ),
- style: textTheme.body.copyWith(
- color: colorScheme.textBase,
- ),
- onChanged: (value) {
- setState(() {
- updateEmail(value);
- if (_emailIsValid) {
- _emailInputFieldColor = colorScheme.primary300
- .withValues(alpha: 0.1);
- } else {
- _emailInputFieldColor = null;
- }
- });
- },
- onFieldSubmitted: _emailIsValid
- ? (value) => _passwordFocusNode.requestFocus()
- : null,
- autocorrect: false,
- keyboardType: TextInputType.emailAddress,
- initialValue: _email,
- autofocus: true,
- ),
- const SizedBox(height: 24),
- Text(
- l10n.loginPasswordLabel,
- style: textTheme.bodyBold.copyWith(
- color: colorScheme.textBase,
- ),
- ),
- const SizedBox(height: 8),
- TextFormField(
- key: const ValueKey("passwordInputField"),
- autofillHints: const [AutofillHints.password],
- decoration: InputDecoration(
- hintText: l10n.loginPasswordHint,
- hintStyle: textTheme.body.copyWith(
- color: colorScheme.textMuted,
- ),
- filled: true,
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 16,
- vertical: 14,
- ),
- border: OutlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(8),
- ),
- fillColor: colorScheme.fillFaint,
- suffixIcon: IconButton(
- icon: Icon(
- _passwordVisible
- ? Icons.visibility_outlined
- : Icons.visibility_off_outlined,
- color: colorScheme.textMuted,
- size: 20,
- ),
- onPressed: () {
- setState(() {
- _passwordVisible = !_passwordVisible;
- });
- },
- ),
- ),
- style: textTheme.body.copyWith(
- color: colorScheme.textBase,
- ),
- controller: _passwordController,
- autofocus: false,
- autocorrect: false,
- obscureText: !_passwordVisible,
- keyboardType: TextInputType.visiblePassword,
- focusNode: _passwordFocusNode,
- onChanged: (_) {
- setState(() {});
- },
- ),
- Align(
- alignment: Alignment.centerRight,
- child: TextButton(
- onPressed: _handleForgotPassword,
- child: Text(
- l10n.forgotPassword,
- style: textTheme.bodyBold.copyWith(
- color: colorScheme.primary700,
- decoration: TextDecoration.underline,
- decorationColor: colorScheme.primary700,
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- SizedBox(
- width: double.infinity,
- child: GradientButton(
- onTap: _emailIsValid &&
- _passwordController.text.isNotEmpty &&
- !_isLoggingIn
- ? () async {
- await _handleLogin();
- }
- : null,
- text: l10n.logInAction,
- ),
- ),
- const SizedBox(height: 16),
- Center(
- child: TextButton(
- onPressed: _handleSignUp,
- child: RichText(
- text: TextSpan(
- style: textTheme.body.copyWith(
- color: colorScheme.textBase,
- ),
- children: [
- TextSpan(text: '${l10n.dontHaveAccount} '),
- TextSpan(
- text: l10n.signUp,
- style: textTheme.bodyBold.copyWith(
- color: colorScheme.primary700,
- decoration: TextDecoration.underline,
- decorationColor: colorScheme.primary700,
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- const SizedBox(height: 24),
- ],
- ),
- ),
- ),
- );
- }
-}
diff --git a/mobile/packages/accounts/lib/pages/delete_account_page.dart b/mobile/packages/accounts/lib/pages/delete_account_page.dart
index dc0afd6667..6d8332b74e 100644
--- a/mobile/packages/accounts/lib/pages/delete_account_page.dart
+++ b/mobile/packages/accounts/lib/pages/delete_account_page.dart
@@ -76,7 +76,6 @@ class DeleteAccountPage extends StatelessWidget {
),
GradientButton(
text: context.strings.yesSendFeedbackAction,
- iconData: Icons.check,
onTap: () async {
await sendEmail(
context,
diff --git a/mobile/packages/accounts/lib/pages/login_page.dart b/mobile/packages/accounts/lib/pages/login_page.dart
index 3caeebea2c..5088b43e1a 100644
--- a/mobile/packages/accounts/lib/pages/login_page.dart
+++ b/mobile/packages/accounts/lib/pages/login_page.dart
@@ -70,6 +70,7 @@ class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context) {
final isKeypadOpen = MediaQuery.of(context).viewInsets.bottom > 100;
+ final colorScheme = getEnteColorScheme(context);
FloatingActionButtonLocation? fabLocation() {
if (isKeypadOpen) {
@@ -81,14 +82,21 @@ class _LoginPageState extends State<LoginPage> {
return Scaffold(
resizeToAvoidBottomInset: isKeypadOpen,
+ backgroundColor: colorScheme.backgroundBase,
appBar: AppBar(
elevation: 0,
- leading: IconButton(
- icon: const Icon(Icons.arrow_back),
- color: Theme.of(context).iconTheme.color,
- onPressed: () {
- Navigator.of(context).pop();
- },
+ backgroundColor: colorScheme.backgroundBase,
+ centerTitle: true,
+ title: Image.asset(
+ 'assets/locker-logo-blue.png',
+ height: 24,
+ ),
+ leading: GestureDetector(
+ onTap: () => Navigator.of(context).pop(),
+ child: Icon(
+ Icons.arrow_back,
+ color: colorScheme.primary700,
+ ),
),
),
body: _getBody(),
@@ -104,6 +112,9 @@ class _LoginPageState extends State<LoginPage> {
}
Widget _getBody() {
+ final colorScheme = getEnteColorScheme(context);
+ final textTheme = getEnteTextTheme(context);
+
return Column(
children: [
Expanded(
@@ -111,102 +122,102 @@ class _LoginPageState extends State<LoginPage> {
child: ListView(
children: [
Padding(
- padding:
- const EdgeInsets.symmetric(vertical: 30, horizontal: 20),
- child: Text(
- context.strings.welcomeBack,
- style: Theme.of(context).textTheme.headlineMedium,
- ),
- ),
- Padding(
- padding: const EdgeInsets.fromLTRB(20, 24, 20, 0),
- child: TextFormField(
- autofillHints: const [AutofillHints.email],
- onFieldSubmitted:
- _emailIsValid ? (value) => onPressed() : null,
- decoration: InputDecoration(
- fillColor: _emailInputFieldColor,
- filled: true,
- hintText: context.strings.email,
- contentPadding: const EdgeInsets.symmetric(
- horizontal: 15,
- vertical: 15,
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ const SizedBox(height: 24),
+ Text(
+ context.strings.email,
+ style: textTheme.bodyBold.copyWith(
+ color: colorScheme.textBase,
+ ),
),
- border: UnderlineInputBorder(
- borderSide: BorderSide.none,
- borderRadius: BorderRadius.circular(6),
+ const SizedBox(height: 8),
+ TextFormField(
+ autofillHints: const [AutofillHints.email],
+ onFieldSubmitted:
+ _emailIsValid ? (value) => onPressed() : null,
+ decoration: InputDecoration(
+ fillColor:
+ _emailInputFieldColor ?? colorScheme.backdropBase,
+ filled: true,
+ hintText: context.strings.emailHint,
+ hintStyle: TextStyle(color: colorScheme.textMuted),
+ contentPadding: const EdgeInsets.symmetric(
+ horizontal: 16,
+ vertical: 14,
+ ),
+ border: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ enabledBorder: OutlineInputBorder(
+ borderSide: BorderSide.none,
+ borderRadius: BorderRadius.circular(8),
+ ),
+ suffixIcon: _emailIsValid
+ ? Icon(
+ Icons.check,
+ size: 20,
+ color: colorScheme.primary700,
+ )
+ : null,
+ ),
+ style: textTheme.body.copyWith(
+ color: colorScheme.textBase,
+ ),
+ onChanged: (value) {
+ setState(() {
+ _email = value.trim();
+ _emailIsValid = EmailValidator.validate(_email!);
+ if (_emailIsValid) {
+ _emailInputFieldColor =
+ getEnteColorScheme(context)
+ .primary700
+ .withValues(alpha: 0.2);
+ } else {
+ _emailInputFieldColor = null;
+ }
+ });
+ },
+ autocorrect: false,
+ keyboardType: TextInputType.emailAddress,
+ //initialValue: _email,
+ autofocus: true,
),
- suffixIcon: _emailIsValid
- ? Icon(
- Icons.check,
- size: 20,
- color: getEnteColorScheme(context).primary300,
- )
- : null,
- ),
- onChanged: (value) {
- setState(() {
- _email = value.trim();
- _emailIsValid = EmailValidator.validate(_email!);
- if (_emailIsValid) {
- _emailInputFieldColor = getEnteColorScheme(context)
- .primary300
- .withOpacity(0.2);
- } else {
- _emailInputFieldColor = null;
- }
- });
- },
- autocorrect: false,
- keyboardType: TextInputType.emailAddress,
- //initialValue: _email,
- autofocus: true,
- ),
- ),
- const Padding(
- padding: EdgeInsets.symmetric(vertical: 18),
- child: Divider(
- thickness: 1,
- ),
- ),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 20),
- child: Row(
- children: [
- Expanded(
- flex: 5,
- child: StyledText(
- text: context.strings.loginTerms,
- style: getEnteTextTheme(context).small,
- tags: {
- 'u-terms': StyledTextActionTag(
- (String? text, Map<String?, String?> attrs) =>
- PlatformUtil.openWebView(
- context,
- context.strings.termsOfServicesTitle,
- "https://ente.io/terms",
- ),
- style: const TextStyle(
- decoration: TextDecoration.underline,
- ),
+ const SizedBox(height: 24),
+ StyledText(
+ text: context.strings.loginTerms,
+ style: textTheme.small.copyWith(
+ color: colorScheme.textMuted,
+ ),
+ tags: {
+ 'u-terms': StyledTextActionTag(
+ (String? text, Map<String?, String?> attrs) =>
+ PlatformUtil.openWebView(
+ context,
+ context.strings.termsOfServicesTitle,
+ "https://ente.io/terms",
),
- 'u-policy': StyledTextActionTag(
- (String? text, Map<String?, String?> attrs) =>
- PlatformUtil.openWebView(
- context,
- context.strings.privacyPolicyTitle,
- "https://ente.io/privacy",
- ),
- style: const TextStyle(
- decoration: TextDecoration.underline,
- ),
+ style: TextStyle(
+ decoration: TextDecoration.underline,
+ color: colorScheme.textMuted,
),
- },
- ),
- ),
- Expanded(
- flex: 2,
- child: Container(),
+ ),
+ 'u-policy': StyledTextActionTag(
+ (String? text, Map<String?, String?> attrs) =>
+ PlatformUtil.openWebView(
+ context,
+ context.strings.privacyPolicyTitle,
+ "https://ente.io/privacy",
+ ),
+ style: TextStyle(
+ decoration: TextDecoration.underline,
+ color: colorScheme.textMuted,
+ ),
+ ),
+ },
),
],
),
diff --git a/mobile/packages/strings/lib/l10n/arb/strings_en.arb b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
index 3c8301667c..2c443ad7a4 100644
--- a/mobile/packages/strings/lib/l10n/arb/strings_en.arb
+++ b/mobile/packages/strings/lib/l10n/arb/strings_en.arb
@@ -137,6 +137,7 @@
"@email": {
"description": "Email field label"
},
+ "emailHint": "Enter your email id",
"verify": "Verify",
"@verify": {
"description": "Verify button label"
diff --git a/mobile/packages/ui/lib/components/buttons/dynamic_fab.dart b/mobile/packages/ui/lib/components/buttons/dynamic_fab.dart
index a6e9be9990..4f3e3a4058 100644
--- a/mobile/packages/ui/lib/components/buttons/dynamic_fab.dart
+++ b/mobile/packages/ui/lib/components/buttons/dynamic_fab.dart
@@ -1,5 +1,6 @@
import 'dart:math' as math;
+import "package:ente_ui/components/buttons/gradient_button.dart";
import 'package:ente_ui/theme/ente_theme.dart';
import 'package:ente_ui/theme/ente_theme_data.dart';
import 'package:flutter/material.dart';
@@ -58,14 +59,14 @@ class DynamicFAB extends StatelessWidget {
),
);
} 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!),
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16.0),
+ child: SizedBox(
+ width: double.infinity,
+ child: GradientButton(
+ text: buttonText!,
+ onTap: isFormValid! ? onPressedFunction as void Function()? : null,
+ ),
),
);
}
diff --git a/mobile/packages/ui/lib/components/buttons/gradient_button.dart b/mobile/packages/ui/lib/components/buttons/gradient_button.dart
index 4744cbf8d7..696a145cfc 100644
--- a/mobile/packages/ui/lib/components/buttons/gradient_button.dart
+++ b/mobile/packages/ui/lib/components/buttons/gradient_button.dart
@@ -2,80 +2,68 @@ import 'package:ente_ui/theme/ente_theme.dart';
import 'package:flutter/material.dart';
class GradientButton extends StatelessWidget {
- final Function? onTap;
-
- // text is ignored if child is specified
+ final VoidCallback? onTap;
final String text;
-
- // nullable
- final IconData? iconData;
-
- // padding between the text and icon
+ final IconData? icon;
final double paddingValue;
+ final Color? backgroundColor;
const GradientButton({
super.key,
this.onTap,
this.text = '',
- this.iconData,
- this.paddingValue = 0.0,
+ this.icon,
+ this.paddingValue = 6.0,
+ this.backgroundColor,
});
+ static const TextStyle _textStyle = TextStyle(
+ color: Colors.white,
+ fontWeight: FontWeight.w600,
+ fontFamily: 'Inter-SemiBold',
+ fontSize: 18,
+ );
+
@override
Widget build(BuildContext context) {
- Widget buttonContent;
- if (iconData == null) {
- buttonContent = Text(
- text,
- style: const TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.w600,
- fontFamily: 'Inter-SemiBold',
- fontSize: 18,
- ),
- );
- } else {
- buttonContent = Row(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Icon(
- iconData,
- size: 20,
- color: Colors.white,
- ),
- const Padding(padding: EdgeInsets.symmetric(horizontal: 6)),
- Text(
- text,
- style: const TextStyle(
- color: Colors.white,
- fontWeight: FontWeight.w600,
- fontFamily: 'Inter-SemiBold',
- fontSize: 18,
- ),
- ),
- ],
- );
- }
- return InkWell(
- onTap: onTap as void Function()?,
- child: ClipRRect(
- borderRadius: BorderRadius.circular(4),
- child: Container(
- height: 56,
- decoration: BoxDecoration(
- gradient: LinearGradient(
- begin: const Alignment(0.1, -0.9),
- end: const Alignment(-0.6, 0.9),
- colors: onTap != null
- ? getEnteColorScheme(context).gradientButtonBgColors
- : [
- getEnteColorScheme(context).fillMuted,
- getEnteColorScheme(context).fillMuted,
- ],
- ),
+ final colorScheme = getEnteColorScheme(context);
+ final bool isEnabled = onTap != null;
+ final Color effectiveBackgroundColor = backgroundColor ??
+ (isEnabled ? colorScheme.primary700 : colorScheme.fillFaint);
+ final TextStyle effectiveTextStyle = _textStyle.copyWith(
+ color: isEnabled ? Colors.white : colorScheme.textMuted,
+ );
+
+ final Widget textWidget = Text(text, style: effectiveTextStyle);
+
+ final Widget content = (icon != null)
+ ? Row(
+ mainAxisAlignment: MainAxisAlignment.center,
+ crossAxisAlignment: CrossAxisAlignment.center,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(
+ icon,
+ color: isEnabled ? Colors.white : colorScheme.textMuted,
+ ),
+ Padding(padding: EdgeInsets.symmetric(horizontal: paddingValue)),
+ if (text.isNotEmpty) textWidget,
+ ],
+ )
+ : textWidget;
+
+ return ClipRRect(
+ borderRadius: BorderRadius.circular(20),
+ child: Material(
+ color: effectiveBackgroundColor,
+ child: InkWell(
+ onTap: onTap,
+ splashColor: isEnabled ? null : Colors.transparent,
+ highlightColor: isEnabled ? null : Colors.transparent,
+ child: SizedBox(
+ height: 56,
+ child: Center(child: content),
),
- child: Center(child: buttonContent),
),
),
);