diff --git a/CHANGELOG.md b/CHANGELOG.md index bdde506..36b458c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/example/pubspec.lock b/example/pubspec.lock index 6e5a4c3..b9b62f0 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -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 diff --git a/lib/src/config/login_options.dart b/lib/src/config/login_options.dart index afb8046..9a8fd25 100644 --- a/lib/src/config/login_options.dart +++ b/lib/src/config/login_options.dart @@ -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; diff --git a/lib/src/widgets/email_password_login.dart b/lib/src/widgets/email_password_login.dart index 96ef072..a2fea9e 100644 --- a/lib/src/widgets/email_password_login.dart +++ b/lib/src/widgets/email_password_login.dart @@ -102,7 +102,7 @@ class _EmailPasswordLoginFormState extends State { 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 { 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 { 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 { ), options.passwordInputContainerBuilder( TextFormField( + textAlign: + options.passwordTextAlign ?? TextAlign.start, obscureText: _obscurePassword, onChanged: _updateCurrentPassword, validator: @@ -245,12 +249,12 @@ class _EmailPasswordLoginFormState extends State { ], ); } +} - Widget? _wrapWithDefaultStyle(Widget? widget, TextStyle? style) { - if (style == null || widget == null) { - return widget; - } else { - return DefaultTextStyle(style: style, child: widget); - } +Widget? wrapWithDefaultStyle(Widget? widget, TextStyle? style) { + if (style == null || widget == null) { + return widget; + } else { + return DefaultTextStyle(style: style, child: widget); } } diff --git a/lib/src/widgets/forgot_password_form.dart b/lib/src/widgets/forgot_password_form.dart index b3c56b3..0bc594c 100644 --- a/lib/src/widgets/forgot_password_form.dart +++ b/lib/src/widgets/forgot_password_form.dart @@ -66,106 +66,112 @@ class _ForgotPasswordFormState extends State { @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, - ), - child: Column( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - if (options.forgotPasswordSpacerOptions.spacerBeforeTitle != - null) ...[ - Spacer( - flex: options.forgotPasswordSpacerOptions.spacerBeforeTitle!, - ), - ], - _wrapWithDefaultStyle( + var options = widget.options; + + return CustomScrollView( + physics: const ScrollPhysics(), + slivers: [ + SliverFillRemaining( + hasScrollBody: false, + fillOverscroll: true, + child: Column( + children: [ + if (options.forgotPasswordSpacerOptions.spacerBeforeTitle != + null) ...[ + Spacer( + flex: options.forgotPasswordSpacerOptions.spacerBeforeTitle!, + ), + ], + 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( + if (options.forgotPasswordSpacerOptions.spacerAfterTitle != + null) ...[ + Spacer( + flex: options.forgotPasswordSpacerOptions.spacerAfterTitle!, + ), + ], + Align( + alignment: Alignment.topCenter, + child: wrapWithDefaultStyle( widget.description, theme.textTheme.bodyMedium, - ) ?? - const SizedBox.shrink(), - if (options.forgotPasswordSpacerOptions.spacerAfterDescription != - null) ...[ - Spacer( - flex: - options.forgotPasswordSpacerOptions.spacerAfterDescription!, + ), ), - ], - Expanded( - flex: options.forgotPasswordSpacerOptions.formFlexValue, - child: Align( - child: options.emailInputContainerBuilder( - TextFormField( - focusNode: _focusNode, - onChanged: _updateCurrentEmail, - validator: widget.options.validations.validateEmail, - initialValue: options.initialEmail, - keyboardType: TextInputType.emailAddress, - textInputAction: TextInputAction.next, - style: options.emailTextStyle, - decoration: options.emailDecoration, + if (options.forgotPasswordSpacerOptions.spacerAfterDescription != + null) ...[ + Spacer( + 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, + initialValue: options.initialEmail, + keyboardType: TextInputType.emailAddress, + textInputAction: TextInputAction.next, + style: options.emailTextStyle, + decoration: options.emailDecoration, + ), + ), + ), ), ), ), - ), - if (options.forgotPasswordSpacerOptions.spacerBeforeButton != - null) ...[ - Spacer( - flex: options.forgotPasswordSpacerOptions.spacerBeforeButton!, - ), - ], - AnimatedBuilder( - animation: _formValid, - builder: (context, snapshot) => Align( - child: widget.options.requestForgotPasswordButtonBuilder( - context, - () async { - _formKey.currentState?.validate(); - if (_formValid.value) { - widget.onRequestForgotPassword(_currentEmail); - } - }, - !_formValid.value, - () { - _formKey.currentState?.validate(); - }, - options, + if (options.forgotPasswordSpacerOptions.spacerBeforeButton != + null) ...[ + Spacer( + flex: options.forgotPasswordSpacerOptions.spacerBeforeButton!, + ), + ], + AnimatedBuilder( + animation: _formValid, + builder: (context, snapshot) => Align( + child: widget.options.requestForgotPasswordButtonBuilder( + context, + () async { + _formKey.currentState?.validate(); + if (_formValid.value) { + widget.onRequestForgotPassword(_currentEmail); + } + }, + !_formValid.value, + () { + _formKey.currentState?.validate(); + }, + options, + ), ), ), - ), - if (options.forgotPasswordSpacerOptions.spacerAfterButton != - null) ...[ - Spacer( - flex: options.forgotPasswordSpacerOptions.spacerAfterButton!, - ), + if (options.forgotPasswordSpacerOptions.spacerAfterButton != + null) ...[ + Spacer( + flex: options.forgotPasswordSpacerOptions.spacerAfterButton!, + ), + ], ], - ], + ), ), - ), + ], ); } - - Widget? _wrapWithDefaultStyle(Widget? widget, TextStyle? style) { - if (style == null || widget == null) { - return widget; - } else { - return DefaultTextStyle(style: style, child: widget); - } - } } diff --git a/pubspec.yaml b/pubspec.yaml index 312c130..5166b25 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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"