2022-09-27 16:38:12 +02:00
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
2022-09-29 17:22:26 +02:00
|
|
|
import 'package:flutter_login/src/service/login_validation_.dart';
|
|
|
|
import 'package:flutter_login/src/service/validation.dart';
|
2022-09-27 16:38:12 +02:00
|
|
|
|
|
|
|
class LoginOptions {
|
|
|
|
const LoginOptions({
|
|
|
|
this.image,
|
|
|
|
this.title,
|
|
|
|
this.subtitle,
|
|
|
|
this.emailLabel,
|
|
|
|
this.passwordLabel,
|
|
|
|
this.emailInputPrefix,
|
|
|
|
this.passwordInputPrefix,
|
|
|
|
this.decoration = const InputDecoration(),
|
|
|
|
this.initialEmail = '',
|
|
|
|
this.initialPassword = '',
|
|
|
|
this.translations = const LoginTranslations(),
|
2022-09-29 17:22:26 +02:00
|
|
|
this.validationService,
|
2022-09-27 16:38:12 +02:00
|
|
|
this.loginButtonBuilder = _createLoginButton,
|
|
|
|
this.forgotPasswordButtonBuilder = _createForgotPasswordButton,
|
2022-09-29 17:22:26 +02:00
|
|
|
this.requestForgotPasswordButtonBuilder =
|
|
|
|
_createRequestForgotPasswordButton,
|
2022-09-27 16:38:12 +02:00
|
|
|
this.registrationButtonBuilder = _createRegisterButton,
|
2022-09-29 12:14:30 +02:00
|
|
|
this.emailInputContainerBuilder = _createEmailInputContainer,
|
|
|
|
this.passwordInputContainerBuilder = _createPasswordInputContainer,
|
2022-10-19 15:14:51 +02:00
|
|
|
this.emailHintText,
|
|
|
|
this.passwordHintText,
|
2022-09-27 16:38:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
final ButtonBuilder loginButtonBuilder;
|
|
|
|
final ButtonBuilder registrationButtonBuilder;
|
|
|
|
final ButtonBuilder forgotPasswordButtonBuilder;
|
2022-09-29 17:22:26 +02:00
|
|
|
final ButtonBuilder requestForgotPasswordButtonBuilder;
|
2022-09-29 12:14:30 +02:00
|
|
|
final InputContainerBuilder emailInputContainerBuilder;
|
|
|
|
final InputContainerBuilder passwordInputContainerBuilder;
|
2022-09-27 16:38:12 +02:00
|
|
|
|
|
|
|
final Widget? image;
|
|
|
|
final Widget? title;
|
|
|
|
final Widget? subtitle;
|
|
|
|
final Widget? emailLabel;
|
|
|
|
final Widget? passwordLabel;
|
|
|
|
final Widget? emailInputPrefix;
|
|
|
|
final Widget? passwordInputPrefix;
|
|
|
|
final InputDecoration decoration;
|
|
|
|
final String initialEmail;
|
|
|
|
final String initialPassword;
|
2022-10-19 15:14:51 +02:00
|
|
|
final String? emailHintText;
|
|
|
|
final String? passwordHintText;
|
2022-09-27 16:38:12 +02:00
|
|
|
final LoginTranslations translations;
|
2022-09-29 17:22:26 +02:00
|
|
|
final ValidationService? validationService;
|
|
|
|
|
|
|
|
ValidationService get validations =>
|
|
|
|
validationService ?? LoginValidationService(this);
|
2022-09-27 16:38:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class LoginTranslations {
|
|
|
|
const LoginTranslations({
|
|
|
|
this.emailEmpty = 'Email is required',
|
|
|
|
this.passwordEmpty = 'Password is required',
|
|
|
|
this.emailInvalid = 'Enter a valid email address',
|
|
|
|
});
|
|
|
|
|
|
|
|
final String emailInvalid;
|
|
|
|
final String emailEmpty;
|
|
|
|
final String passwordEmpty;
|
|
|
|
}
|
|
|
|
|
2022-09-29 12:14:30 +02:00
|
|
|
Widget _createEmailInputContainer(Widget child) => child;
|
|
|
|
|
|
|
|
Widget _createPasswordInputContainer(Widget child) => child;
|
|
|
|
|
2022-09-27 16:38:12 +02:00
|
|
|
Widget _createLoginButton(
|
|
|
|
BuildContext context,
|
|
|
|
OptionalAsyncCallback onPressed,
|
|
|
|
bool disabled,
|
|
|
|
) {
|
|
|
|
return Opacity(
|
|
|
|
opacity: disabled ? 0.5 : 1.0,
|
|
|
|
child: ElevatedButton(
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: const Text('Login'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _createForgotPasswordButton(
|
|
|
|
BuildContext context,
|
|
|
|
OptionalAsyncCallback onPressed,
|
|
|
|
bool disabled,
|
|
|
|
) {
|
|
|
|
return Opacity(
|
|
|
|
opacity: disabled ? 0.5 : 1.0,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: const Text('Forgot password?'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-29 17:22:26 +02:00
|
|
|
Widget _createRequestForgotPasswordButton(
|
|
|
|
BuildContext context,
|
|
|
|
OptionalAsyncCallback onPressed,
|
|
|
|
bool disabled,
|
|
|
|
) {
|
|
|
|
return Opacity(
|
|
|
|
opacity: disabled ? 0.5 : 1.0,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: const Text('Send request'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-27 16:38:12 +02:00
|
|
|
Widget _createRegisterButton(
|
|
|
|
BuildContext context,
|
|
|
|
OptionalAsyncCallback onPressed,
|
|
|
|
bool disabled,
|
|
|
|
) {
|
|
|
|
return Opacity(
|
|
|
|
opacity: disabled ? 0.5 : 1.0,
|
|
|
|
child: TextButton(
|
|
|
|
onPressed: onPressed,
|
|
|
|
child: const Text('Create Account'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef ButtonBuilder = Widget Function(
|
|
|
|
BuildContext context,
|
|
|
|
OptionalAsyncCallback onPressed,
|
|
|
|
bool isDisabled,
|
|
|
|
);
|
|
|
|
|
2022-09-29 12:14:30 +02:00
|
|
|
typedef InputContainerBuilder = Widget Function(
|
|
|
|
Widget child,
|
|
|
|
);
|
|
|
|
|
2022-09-27 16:38:12 +02:00
|
|
|
typedef OptionalAsyncCallback = FutureOr<void> Function();
|