Merge pull request #30 from Iconica-Development/6.0.0

fix: change forgotpassword form layout
This commit is contained in:
Freek van de Ven 2024-03-08 14:36:27 +01:00 committed by GitHub
commit f1b11ae79a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 119 additions and 96 deletions

View file

@ -1,3 +1,8 @@
## 6.0.0
* Changed ForgotPasswordform to use the same layout as the EmailPasswordLoginForm.
* Add option for textalignment for email and password fields.
## 5.2.0
* Added spacer options for the ForogotPasswordForm.

View file

@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "5.1.4"
version: "6.0.0"
flutter_test:
dependency: "direct dev"
description: flutter

View file

@ -15,6 +15,8 @@ class LoginOptions {
this.maxFormWidth,
this.emailTextStyle,
this.passwordTextStyle,
this.emailTextAlign,
this.passwordTextAlign,
this.emailDecoration = const InputDecoration(),
this.passwordDecoration = const InputDecoration(),
this.initialEmail = '',
@ -88,6 +90,12 @@ class LoginOptions {
/// The text style for the password input field.
final TextStyle? passwordTextStyle;
/// The text alignment for the email input field.
final TextAlign? emailTextAlign;
/// The text alignment for the password input field.
final TextAlign? passwordTextAlign;
/// Translations for various texts on the login screen.
final LoginTranslations translations;

View file

@ -102,7 +102,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
if (options.title != null) ...[
Align(
alignment: Alignment.topCenter,
child: _wrapWithDefaultStyle(
child: wrapWithDefaultStyle(
options.title,
theme.textTheme.headlineSmall,
),
@ -114,7 +114,7 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
if (options.subtitle != null) ...[
Align(
alignment: Alignment.topCenter,
child: _wrapWithDefaultStyle(
child: wrapWithDefaultStyle(
options.subtitle,
theme.textTheme.titleSmall,
),
@ -148,6 +148,8 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
children: [
options.emailInputContainerBuilder(
TextFormField(
textAlign:
options.emailTextAlign ?? TextAlign.start,
onChanged: _updateCurrentEmail,
validator: widget.options.validations.validateEmail,
initialValue: options.initialEmail,
@ -159,6 +161,8 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
),
options.passwordInputContainerBuilder(
TextFormField(
textAlign:
options.passwordTextAlign ?? TextAlign.start,
obscureText: _obscurePassword,
onChanged: _updateCurrentPassword,
validator:
@ -245,12 +249,12 @@ class _EmailPasswordLoginFormState extends State<EmailPasswordLoginForm> {
],
);
}
}
Widget? _wrapWithDefaultStyle(Widget? widget, TextStyle? style) {
Widget? wrapWithDefaultStyle(Widget? widget, TextStyle? style) {
if (style == null || widget == null) {
return widget;
} else {
return DefaultTextStyle(style: style, child: widget);
}
}
}

View file

@ -66,17 +66,16 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
@override
Widget build(BuildContext context) {
var options = widget.options;
var theme = Theme.of(context);
return Form(
key: _formKey,
child: ConstrainedBox(
constraints: const BoxConstraints(
maxWidth: 300,
),
var options = widget.options;
return CustomScrollView(
physics: const ScrollPhysics(),
slivers: [
SliverFillRemaining(
hasScrollBody: false,
fillOverscroll: true,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (options.forgotPasswordSpacerOptions.spacerBeforeTitle !=
null) ...[
@ -84,34 +83,46 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
flex: options.forgotPasswordSpacerOptions.spacerBeforeTitle!,
),
],
_wrapWithDefaultStyle(
Align(
alignment: Alignment.topCenter,
child: wrapWithDefaultStyle(
widget.title,
theme.textTheme.displaySmall,
) ??
const SizedBox.shrink(),
),
),
if (options.forgotPasswordSpacerOptions.spacerAfterTitle !=
null) ...[
Spacer(
flex: options.forgotPasswordSpacerOptions.spacerAfterTitle!,
),
],
_wrapWithDefaultStyle(
Align(
alignment: Alignment.topCenter,
child: wrapWithDefaultStyle(
widget.description,
theme.textTheme.bodyMedium,
) ??
const SizedBox.shrink(),
),
),
if (options.forgotPasswordSpacerOptions.spacerAfterDescription !=
null) ...[
Spacer(
flex:
options.forgotPasswordSpacerOptions.spacerAfterDescription!,
flex: options
.forgotPasswordSpacerOptions.spacerAfterDescription!,
),
],
Expanded(
flex: options.forgotPasswordSpacerOptions.formFlexValue,
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: options.maxFormWidth ?? 300,
),
child: Form(
key: _formKey,
child: Align(
alignment: Alignment.center,
child: options.emailInputContainerBuilder(
TextFormField(
textAlign: options.emailTextAlign ?? TextAlign.start,
focusNode: _focusNode,
onChanged: _updateCurrentEmail,
validator: widget.options.validations.validateEmail,
@ -124,6 +135,8 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
),
),
),
),
),
if (options.forgotPasswordSpacerOptions.spacerBeforeButton !=
null) ...[
Spacer(
@ -158,14 +171,7 @@ class _ForgotPasswordFormState extends State<ForgotPasswordForm> {
],
),
),
],
);
}
Widget? _wrapWithDefaultStyle(Widget? widget, TextStyle? style) {
if (style == null || widget == null) {
return widget;
} else {
return DefaultTextStyle(style: style, child: widget);
}
}
}

View file

@ -1,6 +1,6 @@
name: flutter_login
description: Flutter Login Component
version: 5.2.0
version: 6.0.0
environment:
sdk: ">=2.18.1 <3.0.0"