|
| 1 | +import 'package:easy_localization/easy_localization.dart'; |
| 2 | +import 'package:flutter/material.dart'; |
| 3 | +import 'package:immich_mobile/extensions/build_context_extensions.dart'; |
| 4 | +import 'package:immich_mobile/utils/url_helper.dart'; |
| 5 | +import 'package:immich_mobile/widgets/forms/login/email_input.dart'; |
| 6 | +import 'package:immich_mobile/widgets/forms/login/loading_icon.dart'; |
| 7 | +import 'package:immich_mobile/widgets/forms/login/login_button.dart'; |
| 8 | +import 'package:immich_mobile/widgets/forms/login/o_auth_login_button.dart'; |
| 9 | +import 'package:immich_mobile/widgets/forms/login/password_input.dart'; |
| 10 | +import 'package:immich_mobile/widgets/forms/login/version_compatibility_warning.dart'; |
| 11 | + |
| 12 | +class LoginCredentialsForm extends StatelessWidget { |
| 13 | + final TextEditingController emailController; |
| 14 | + final TextEditingController passwordController; |
| 15 | + final TextEditingController serverEndpointController; |
| 16 | + final FocusNode emailFocusNode; |
| 17 | + final FocusNode passwordFocusNode; |
| 18 | + final bool isLoading; |
| 19 | + final bool isOAuthEnabled; |
| 20 | + final bool isPasswordLoginEnabled; |
| 21 | + final String oAuthButtonLabel; |
| 22 | + final String? warningMessage; |
| 23 | + final VoidCallback onLogin; |
| 24 | + final VoidCallback onOAuthLogin; |
| 25 | + final VoidCallback onBack; |
| 26 | + |
| 27 | + const LoginCredentialsForm({ |
| 28 | + super.key, |
| 29 | + required this.emailController, |
| 30 | + required this.passwordController, |
| 31 | + required this.serverEndpointController, |
| 32 | + required this.emailFocusNode, |
| 33 | + required this.passwordFocusNode, |
| 34 | + required this.isLoading, |
| 35 | + required this.isOAuthEnabled, |
| 36 | + required this.isPasswordLoginEnabled, |
| 37 | + required this.oAuthButtonLabel, |
| 38 | + required this.warningMessage, |
| 39 | + required this.onLogin, |
| 40 | + required this.onOAuthLogin, |
| 41 | + required this.onBack, |
| 42 | + }); |
| 43 | + |
| 44 | + @override |
| 45 | + Widget build(BuildContext context) { |
| 46 | + return AutofillGroup( |
| 47 | + child: Column( |
| 48 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 49 | + children: [ |
| 50 | + if (warningMessage != null) VersionCompatibilityWarning(message: warningMessage!), |
| 51 | + Text( |
| 52 | + sanitizeUrl(serverEndpointController.text), |
| 53 | + style: context.textTheme.displaySmall, |
| 54 | + textAlign: TextAlign.center, |
| 55 | + ), |
| 56 | + if (isPasswordLoginEnabled) ...[ |
| 57 | + const SizedBox(height: 18), |
| 58 | + EmailInput( |
| 59 | + controller: emailController, |
| 60 | + focusNode: emailFocusNode, |
| 61 | + onSubmit: passwordFocusNode.requestFocus, |
| 62 | + ), |
| 63 | + const SizedBox(height: 8), |
| 64 | + PasswordInput(controller: passwordController, focusNode: passwordFocusNode, onSubmit: onLogin), |
| 65 | + ], |
| 66 | + isLoading |
| 67 | + ? const LoadingIcon() |
| 68 | + : Column( |
| 69 | + crossAxisAlignment: CrossAxisAlignment.stretch, |
| 70 | + mainAxisAlignment: MainAxisAlignment.center, |
| 71 | + children: [ |
| 72 | + const SizedBox(height: 18), |
| 73 | + if (isPasswordLoginEnabled) LoginButton(onPressed: onLogin), |
| 74 | + if (isOAuthEnabled) ...[ |
| 75 | + if (isPasswordLoginEnabled) |
| 76 | + Padding( |
| 77 | + padding: const EdgeInsets.symmetric(horizontal: 16.0), |
| 78 | + child: Divider(color: context.isDarkTheme ? Colors.white : Colors.black), |
| 79 | + ), |
| 80 | + OAuthLoginButton( |
| 81 | + serverEndpointController: serverEndpointController, |
| 82 | + buttonLabel: oAuthButtonLabel, |
| 83 | + onPressed: onOAuthLogin, |
| 84 | + ), |
| 85 | + ], |
| 86 | + ], |
| 87 | + ), |
| 88 | + if (!isOAuthEnabled && !isPasswordLoginEnabled) Center(child: const Text('login_disabled').tr()), |
| 89 | + const SizedBox(height: 12), |
| 90 | + TextButton.icon(icon: const Icon(Icons.arrow_back), onPressed: onBack, label: const Text('back').tr()), |
| 91 | + ], |
| 92 | + ), |
| 93 | + ); |
| 94 | + } |
| 95 | +} |
0 commit comments