feat: Update README, update login form field

This commit is contained in:
Anton Stubenbord
2023-06-16 19:54:54 +02:00
parent 656cbcab80
commit cfb301c8f6
5 changed files with 71 additions and 28 deletions

View File

@@ -126,6 +126,7 @@ class _LoginPageState extends State<LoginPage> {
}
Future<void> _login() async {
FocusScope.of(context).unfocus();
if (_formKey.currentState?.saveAndValidate() ?? false) {
final form = _formKey.currentState!.value;

View File

@@ -6,6 +6,9 @@ class ObscuredInputTextFormField extends StatefulWidget {
final void Function(String?) onChanged;
final FormFieldValidator<String>? validator;
final bool enabled;
final FocusNode? focusNode;
final ValueChanged<String?>? onFieldSubmitted;
const ObscuredInputTextFormField({
super.key,
@@ -14,6 +17,8 @@ class ObscuredInputTextFormField extends StatefulWidget {
this.validator,
this.initialValue,
this.enabled = true,
this.focusNode,
this.onFieldSubmitted,
});
@override
@@ -24,7 +29,13 @@ class ObscuredInputTextFormField extends StatefulWidget {
class _ObscuredInputTextFormFieldState
extends State<ObscuredInputTextFormField> {
bool _showPassword = false;
final FocusNode _passwordFocusNode = FocusNode();
late final FocusNode _passwordFocusNode;
@override
void initState() {
super.initState();
_passwordFocusNode = widget.focusNode ?? FocusNode();
}
@override
void dispose() {
@@ -37,6 +48,7 @@ class _ObscuredInputTextFormFieldState
return TextFormField(
enabled: widget.enabled,
autovalidateMode: AutovalidateMode.onUserInteraction,
onFieldSubmitted: widget.onFieldSubmitted,
validator: widget.validator,
initialValue: widget.initialValue,
focusNode: _passwordFocusNode,

View File

@@ -9,8 +9,11 @@ import 'package:paperless_mobile/generated/l10n/app_localizations.dart';
class UserCredentialsFormField extends StatefulWidget {
static const fkCredentials = 'credentials';
final void Function() onFieldsSubmitted;
const UserCredentialsFormField({
Key? key,
required this.onFieldsSubmitted,
}) : super(key: key);
@override
@@ -19,6 +22,9 @@ class UserCredentialsFormField extends StatefulWidget {
}
class _UserCredentialsFormFieldState extends State<UserCredentialsFormField> {
final _usernameFocusNode = FocusNode();
final _passwordFocusNode = FocusNode();
@override
Widget build(BuildContext context) {
return FormBuilderField<LoginFormCredentials?>(
@@ -28,9 +34,13 @@ class _UserCredentialsFormFieldState extends State<UserCredentialsFormField> {
children: [
TextFormField(
key: const ValueKey('login-username'),
textCapitalization: TextCapitalization.words,
focusNode: _usernameFocusNode,
textCapitalization: TextCapitalization.none,
textInputAction: TextInputAction.next,
onFieldSubmitted: (value) {
_passwordFocusNode.requestFocus();
},
autovalidateMode: AutovalidateMode.onUserInteraction,
// USERNAME
autocorrect: false,
onChanged: (username) => field.didChange(
field.value?.copyWith(username: username) ??
@@ -49,11 +59,15 @@ class _UserCredentialsFormFieldState extends State<UserCredentialsFormField> {
),
ObscuredInputTextFormField(
key: const ValueKey('login-password'),
focusNode: _passwordFocusNode,
label: S.of(context)!.password,
onChanged: (password) => field.didChange(
field.value?.copyWith(password: password) ??
LoginFormCredentials(password: password),
),
onFieldSubmitted: (_) {
widget.onFieldsSubmitted();
},
validator: (value) {
if (value?.trim().isEmpty ?? true) {
return S.of(context)!.passwordMustNotBeEmpty;

View File

@@ -41,8 +41,21 @@ class _ServerLoginPageState extends State<ServerLoginPage> {
),
body: ListView(
children: [
Text(S.of(context)!.signInToServer(serverAddress)).padded(),
const UserCredentialsFormField(),
Text(
S.of(context)!.signInToServer(serverAddress) + ":",
style: Theme.of(context).textTheme.labelLarge,
).padded(16),
UserCredentialsFormField(
onFieldsSubmitted: widget.onSubmit,
),
Text(
"Please make sure that the user has the permission to view users ('Users -> View') and view UI settings ('UISettings -> View).",
style: Theme.of(context).textTheme.bodySmall?.apply(
color: Theme.of(context)
.colorScheme
.onBackground
.withOpacity(0.6)),
).padded(16),
],
),
bottomNavigationBar: BottomAppBar(