mirror of
https://github.com/Iconica-Development/flutter_login_widget.git
synced 2025-05-19 05:33:45 +02:00
Merge pull request #39 from Iconica-Development/38-add-autofill-functionality-for-the-login-form
38 add autofill functionality for the login form
This commit is contained in:
commit
54e0a687cc
5 changed files with 194 additions and 156 deletions
|
@ -1,3 +1,8 @@
|
|||
## 7.1.0
|
||||
|
||||
* Added autofillgroup to support native password managers
|
||||
|
||||
|
||||
## 7.0.0
|
||||
|
||||
* Removed `title` and `subtitle` parameters from `LoginOptions` in favour of passing them directly to the `EmailPasswordLoginForm` widget directly
|
||||
|
|
|
@ -68,7 +68,7 @@ packages:
|
|||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "6.1.0"
|
||||
version: "7.1.0"
|
||||
flutter_test:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
|
|
@ -90,8 +90,94 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var theme = Theme.of(context);
|
||||
var options = widget.options;
|
||||
|
||||
var emailTextFormField = TextFormField(
|
||||
autofillHints: const [
|
||||
AutofillHints.email,
|
||||
AutofillHints.username,
|
||||
],
|
||||
textAlign: options.emailTextAlign ?? TextAlign.start,
|
||||
onChanged: _updateCurrentEmail,
|
||||
validator: widget.options.validations.validateEmail,
|
||||
initialValue: options.initialEmail,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
style: options.emailTextStyle,
|
||||
decoration: options.emailDecoration,
|
||||
);
|
||||
|
||||
var passwordTextFormField = TextFormField(
|
||||
autofillHints: const [
|
||||
AutofillHints.password,
|
||||
],
|
||||
textAlign: options.passwordTextAlign ?? TextAlign.start,
|
||||
obscureText: _obscurePassword,
|
||||
onChanged: _updateCurrentPassword,
|
||||
validator: widget.options.validations.validatePassword,
|
||||
initialValue: options.initialPassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
textInputAction: TextInputAction.done,
|
||||
style: options.passwordTextStyle,
|
||||
onFieldSubmitted: (_) async => _handleLogin(),
|
||||
decoration: options.passwordDecoration.copyWith(
|
||||
suffixIcon: options.showObscurePassword
|
||||
? IconButton(
|
||||
padding: options.suffixIconPadding,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
_obscurePassword ? Icons.visibility : Icons.visibility_off,
|
||||
size: options.suffixIconSize,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
);
|
||||
|
||||
var forgotPasswordButton = widget.onForgotPassword != null
|
||||
? Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: options.forgotPasswordButtonBuilder(
|
||||
context,
|
||||
() => widget.onForgotPassword?.call(_currentEmail, context),
|
||||
false,
|
||||
() {},
|
||||
options,
|
||||
),
|
||||
)
|
||||
: const SizedBox(height: 16);
|
||||
|
||||
var loginButton = AnimatedBuilder(
|
||||
animation: _formValid,
|
||||
builder: (context, _) => options.loginButtonBuilder(
|
||||
context,
|
||||
_handleLogin,
|
||||
!_formValid.value,
|
||||
() {
|
||||
_formKey.currentState?.validate();
|
||||
},
|
||||
options,
|
||||
),
|
||||
);
|
||||
|
||||
var registerButton = options.registrationButtonBuilder(
|
||||
context,
|
||||
() async {
|
||||
widget.onRegister?.call(
|
||||
_currentEmail,
|
||||
_currentPassword,
|
||||
context,
|
||||
);
|
||||
},
|
||||
false,
|
||||
() {},
|
||||
options,
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: options.loginBackgroundColor,
|
||||
body: CustomScrollView(
|
||||
|
@ -104,16 +190,81 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
|
|||
children: [
|
||||
Expanded(
|
||||
flex: options.spacers.titleSpacer,
|
||||
child: LoginTitle(
|
||||
options: options,
|
||||
title: widget.title,
|
||||
subtitle: widget.subtitle,
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: options.spacers.formFlexValue,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: options.maxFormWidth ?? 300,
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: AutofillGroup(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
options.emailInputContainerBuilder(
|
||||
emailTextFormField,
|
||||
),
|
||||
options.passwordInputContainerBuilder(
|
||||
passwordTextFormField,
|
||||
),
|
||||
forgotPasswordButton,
|
||||
if (options.spacers.spacerAfterForm != null) ...[
|
||||
Spacer(flex: options.spacers.spacerAfterForm!),
|
||||
],
|
||||
loginButton,
|
||||
if (widget.onRegister != null) ...[
|
||||
registerButton,
|
||||
],
|
||||
if (options.spacers.spacerAfterButton != null) ...[
|
||||
Spacer(flex: options.spacers.spacerAfterButton!),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class LoginTitle extends StatelessWidget {
|
||||
const LoginTitle({
|
||||
required this.options,
|
||||
this.title,
|
||||
this.subtitle,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final LoginOptions options;
|
||||
final Widget? title;
|
||||
final Widget? subtitle;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var theme = Theme.of(context);
|
||||
return Column(
|
||||
children: [
|
||||
if (options.spacers.spacerBeforeTitle != null) ...[
|
||||
Spacer(flex: options.spacers.spacerBeforeTitle!),
|
||||
],
|
||||
if (widget.title != null) ...[
|
||||
if (title != null) ...[
|
||||
Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: wrapWithDefaultStyle(
|
||||
widget.title,
|
||||
title,
|
||||
theme.textTheme.headlineSmall,
|
||||
),
|
||||
),
|
||||
|
@ -121,11 +272,11 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
|
|||
if (options.spacers.spacerAfterTitle != null) ...[
|
||||
Spacer(flex: options.spacers.spacerAfterTitle!),
|
||||
],
|
||||
if (widget.subtitle != null) ...[
|
||||
if (subtitle != null) ...[
|
||||
Align(
|
||||
alignment: Alignment.topCenter,
|
||||
child: wrapWithDefaultStyle(
|
||||
widget.subtitle,
|
||||
subtitle,
|
||||
theme.textTheme.titleSmall,
|
||||
),
|
||||
),
|
||||
|
@ -143,127 +294,6 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
|
|||
Spacer(flex: options.spacers.spacerAfterImage!),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: options.spacers.formFlexValue,
|
||||
child: ConstrainedBox(
|
||||
constraints: BoxConstraints(
|
||||
maxWidth: options.maxFormWidth ?? 300,
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
options.emailInputContainerBuilder(
|
||||
TextFormField(
|
||||
textAlign:
|
||||
options.emailTextAlign ?? TextAlign.start,
|
||||
onChanged: _updateCurrentEmail,
|
||||
validator:
|
||||
widget.options.validations.validateEmail,
|
||||
initialValue: options.initialEmail,
|
||||
keyboardType: TextInputType.emailAddress,
|
||||
textInputAction: TextInputAction.next,
|
||||
style: options.emailTextStyle,
|
||||
decoration: options.emailDecoration,
|
||||
),
|
||||
),
|
||||
options.passwordInputContainerBuilder(
|
||||
TextFormField(
|
||||
textAlign:
|
||||
options.passwordTextAlign ?? TextAlign.start,
|
||||
obscureText: _obscurePassword,
|
||||
onChanged: _updateCurrentPassword,
|
||||
validator:
|
||||
widget.options.validations.validatePassword,
|
||||
initialValue: options.initialPassword,
|
||||
keyboardType: TextInputType.visiblePassword,
|
||||
textInputAction: TextInputAction.done,
|
||||
style: options.passwordTextStyle,
|
||||
onFieldSubmitted: (_) async => _handleLogin(),
|
||||
decoration: options.passwordDecoration.copyWith(
|
||||
suffixIcon: options.showObscurePassword
|
||||
? IconButton(
|
||||
padding: options.suffixIconPadding,
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscurePassword =
|
||||
!_obscurePassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
_obscurePassword
|
||||
? Icons.visibility
|
||||
: Icons.visibility_off,
|
||||
size: options.suffixIconSize,
|
||||
),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (widget.onForgotPassword != null) ...[
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: options.forgotPasswordButtonBuilder(
|
||||
context,
|
||||
() {
|
||||
widget.onForgotPassword
|
||||
?.call(_currentEmail, context);
|
||||
},
|
||||
false,
|
||||
() {},
|
||||
options,
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
const SizedBox(height: 16),
|
||||
],
|
||||
if (options.spacers.spacerAfterForm != null) ...[
|
||||
Spacer(flex: options.spacers.spacerAfterForm!),
|
||||
],
|
||||
AnimatedBuilder(
|
||||
animation: _formValid,
|
||||
builder: (context, _) => options.loginButtonBuilder(
|
||||
context,
|
||||
_handleLogin,
|
||||
!_formValid.value,
|
||||
() {
|
||||
_formKey.currentState?.validate();
|
||||
},
|
||||
options,
|
||||
),
|
||||
),
|
||||
if (widget.onRegister != null) ...[
|
||||
options.registrationButtonBuilder(
|
||||
context,
|
||||
() async {
|
||||
widget.onRegister?.call(
|
||||
_currentEmail,
|
||||
_currentPassword,
|
||||
context,
|
||||
);
|
||||
},
|
||||
false,
|
||||
() {},
|
||||
options,
|
||||
),
|
||||
],
|
||||
if (options.spacers.spacerAfterButton != null) ...[
|
||||
Spacer(flex: options.spacers.spacerAfterButton!),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,10 +129,12 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
|
|||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: AutofillGroup(
|
||||
child: Align(
|
||||
alignment: Alignment.center,
|
||||
child: options.emailInputContainerBuilder(
|
||||
TextFormField(
|
||||
autofillHints: const [AutofillHints.email],
|
||||
textAlign:
|
||||
options.emailTextAlign ?? TextAlign.start,
|
||||
focusNode: _focusNode,
|
||||
|
@ -150,6 +152,7 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
|
|||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (options.forgotPasswordSpacerOptions.spacerBeforeButton !=
|
||||
null) ...[
|
||||
Spacer(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: flutter_login
|
||||
description: Flutter Login Component
|
||||
version: 7.0.0
|
||||
version: 7.1.0
|
||||
|
||||
environment:
|
||||
sdk: ">=2.18.1 <3.0.0"
|
||||
|
|
Loading…
Reference in a new issue