From 89987c5e8da1d8b0899351dac2c049729122583d Mon Sep 17 00:00:00 2001 From: mike doornenbal Date: Fri, 8 Mar 2024 14:55:34 +0100 Subject: [PATCH] fix: registration screen --- CHANGELOG.md | 12 +- lib/flutter_registration.dart | 1 + lib/src/auth_screen.dart | 261 ++++++++++++----------- lib/src/config/registration_options.dart | 2 + lib/src/config/registration_spacers.dart | 12 ++ lib/src/registration_screen.dart | 1 + pubspec.yaml | 2 +- 7 files changed, 162 insertions(+), 129 deletions(-) create mode 100644 lib/src/config/registration_spacers.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b3cf71..ec36a19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,16 +4,22 @@ SPDX-FileCopyrightText: 2022 Iconica SPDX-License-Identifier: GPL-3.0-or-later --> +# 2.0.2 + +- fix: authfields not showing and not being able to set space between widgets + # 2.0.1 + - feat: added circular progress indicator while awaiting registration of user - feat: added alignment option for buttons # 2.0.0 + - feat(buttons): Added the possiblity to only have a next button by return zero on the previous button builder - feat: exposed input decoration in AuthTextField - feat: added title widget and login button builder - feat(bool): Add a boolean field. Can be used for accepting terms and conditions -- feat(pass): Add dedicated password screen that manages state internally +- feat(pass): Add dedicated password screen that manages state internally - fix: Small refactor and brought back the normal alignment for the screens - fix: Fixed alignment and spacing when opening keyboard - feat: add auth drop down field @@ -26,7 +32,7 @@ SPDX-License-Identifier: GPL-3.0-or-later # 1.2.0 -- feat: Added the ability to have an async register function so you can call it asynchronous. +- feat: Added the ability to have an async register function so you can call it asynchronous. # 1.1.0 @@ -43,7 +49,7 @@ SPDX-License-Identifier: GPL-3.0-or-later - fix: fix linter - fix: fix translations to English -# 0.4.0 +# 0.4.0 - feat: Added the abilty to show and hide the passwords diff --git a/lib/flutter_registration.dart b/lib/flutter_registration.dart index d4d9e9a..0ba8e0b 100644 --- a/lib/flutter_registration.dart +++ b/lib/flutter_registration.dart @@ -17,3 +17,4 @@ export 'src/registration_screen.dart'; export 'src/service/registration_repository.dart'; export 'package:flutter_input_library/flutter_input_library.dart' show BoolWidgetType; +export 'src/config/registration_spacers.dart'; diff --git a/lib/src/auth_screen.dart b/lib/src/auth_screen.dart index 8c5a51b..1d5c93c 100644 --- a/lib/src/auth_screen.dart +++ b/lib/src/auth_screen.dart @@ -9,6 +9,7 @@ import 'package:flutter_registration/flutter_registration.dart'; class AuthScreen extends StatefulWidget { const AuthScreen({ + required this.registrationOptions, required this.appBarTitle, required this.steps, required this.submitBtnTitle, @@ -22,14 +23,11 @@ class AuthScreen extends StatefulWidget { this.previousButtonBuilder, this.titleWidget, this.loginButton, - this.titleFlex, - this.formFlex, - this.beforeTitleFlex, - this.afterTitleFlex, this.isLoading = false, super.key, }) : assert(steps.length > 0, 'At least one step is required'); + final RegistrationOptions registrationOptions; final String appBarTitle; final Future Function({ required HashMap values, @@ -48,10 +46,6 @@ class AuthScreen extends StatefulWidget { previousButtonBuilder; final Widget? titleWidget; final Widget? loginButton; - final int? titleFlex; - final int? formFlex; - final int? beforeTitleFlex; - final int? afterTitleFlex; final bool isLoading; @override @@ -164,127 +158,144 @@ class _AuthScreenState extends State { mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - if (widget.titleWidget != null) ...[ - Expanded( - flex: widget.titleFlex ?? 1, - child: Column( - mainAxisAlignment: MainAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - Expanded( - flex: widget.beforeTitleFlex ?? 3, - child: Container(), - ), - widget.titleWidget!, - Expanded( - flex: widget.afterTitleFlex ?? 2, - child: Container(), - ), - ], - ), + if (widget.registrationOptions.spacerConfig + .beforeTitleSpacer != + null) + Spacer( + flex: widget.registrationOptions.spacerConfig + .beforeTitleSpacer!, ), - Column( + widget.titleWidget ?? const SizedBox.shrink(), + if (widget.registrationOptions.spacerConfig + .afterTitleSpacer != + null) + Spacer( + flex: widget.registrationOptions.spacerConfig + .afterTitleSpacer!, + ), + Flexible( + flex: widget + .registrationOptions.spacerConfig.formFlex!, + child: Column( children: [ - Row( - mainAxisAlignment: - widget.buttonMainAxisAlignment != null - ? widget.buttonMainAxisAlignment! - : (widget.previousButtonBuilder != - null && - widget.previousButtonBuilder - ?.call( - onPrevious, - widget - .previousBtnTitle, - i, - ) == - null) - ? MainAxisAlignment.start - : widget.steps.first != - widget.steps[i] - ? MainAxisAlignment.center - : MainAxisAlignment.end, - children: [ - if (widget.previousButtonBuilder == - null) ...[ - if (widget.steps.first != - widget.steps[i]) - ElevatedButton( - onPressed: onPrevious, - child: Row( - children: [ - const Icon( - Icons.arrow_back, - size: 18, - ), - Padding( - padding: - const EdgeInsets.only( - left: 4.0), - child: Text( - widget.previousBtnTitle), - ), - ], - ), - ), - ] else if (widget.previousButtonBuilder - ?.call(onPrevious, - widget.previousBtnTitle, i) != - null) ...[ - widget.previousButtonBuilder!.call( - onPrevious, - widget.previousBtnTitle, - i)! - ], - widget.nextButtonBuilder?.call( - !_formValid - ? null - : () async { - await onNext( - widget.steps[i]); - }, - widget.steps.last == widget.steps[i] - ? widget.submitBtnTitle - : widget.nextBtnTitle, - i, - _formValid, - ) ?? - ElevatedButton( - onPressed: !_formValid - ? null - : () async { - await onNext( - widget.steps[i]); - }, - child: Row( - children: [ - Text( - widget.steps.last == - widget.steps[i] - ? widget.submitBtnTitle - : widget.nextBtnTitle, - ), - const Padding( - padding: EdgeInsets.only( - left: 4.0), - child: Icon( - Icons.arrow_forward, - size: 18, - ), - ), - ], - ), - ), - ], - ), - if (widget.loginButton != null) - Padding( - padding: const EdgeInsets.only(top: 20.0), - child: widget.loginButton!, - ), + for (AuthField field + in widget.steps[i].fields) + Align( + child: Column( + children: [ + if (field.title != null) field.title!, + field.build(context, () { + _validate(i); + }) + ], + ), + ) ], ), - ], + ), + if (widget.registrationOptions.spacerConfig + .afterFormSpacer != + null) + Spacer( + flex: widget.registrationOptions.spacerConfig + .afterFormSpacer!, + ), + Column( + children: [ + Row( + mainAxisAlignment: + widget.buttonMainAxisAlignment != null + ? widget.buttonMainAxisAlignment! + : (widget.previousButtonBuilder != + null && + widget.previousButtonBuilder + ?.call( + onPrevious, + widget.previousBtnTitle, + i, + ) == + null) + ? MainAxisAlignment.start + : widget.steps.first != + widget.steps[i] + ? MainAxisAlignment.center + : MainAxisAlignment.end, + children: [ + if (widget.previousButtonBuilder == + null) ...[ + if (widget.steps.first != widget.steps[i]) + ElevatedButton( + onPressed: onPrevious, + child: Row( + children: [ + const Icon( + Icons.arrow_back, + size: 18, + ), + Padding( + padding: const EdgeInsets.only( + left: 4.0), + child: Text( + widget.previousBtnTitle), + ), + ], + ), + ), + ] else if (widget.previousButtonBuilder + ?.call(onPrevious, + widget.previousBtnTitle, i) != + null) ...[ + widget.previousButtonBuilder!.call( + onPrevious, + widget.previousBtnTitle, + i)! + ], + widget.nextButtonBuilder?.call( + !_formValid + ? null + : () async { + await onNext(widget.steps[i]); + }, + widget.steps.last == widget.steps[i] + ? widget.submitBtnTitle + : widget.nextBtnTitle, + i, + _formValid, + ) ?? + ElevatedButton( + onPressed: !_formValid + ? null + : () async { + await onNext(widget.steps[i]); + }, + child: Row( + children: [ + Text( + widget.steps.last == + widget.steps[i] + ? widget.submitBtnTitle + : widget.nextBtnTitle, + ), + const Padding( + padding: + EdgeInsets.only(left: 4.0), + child: Icon( + Icons.arrow_forward, + size: 18, + ), + ), + ], + ), + ), + ], + ), + if (widget.loginButton != null) + Padding( + padding: const EdgeInsets.only(top: 20.0), + child: widget.loginButton!, + ), + ], + ), ]), ]), )); diff --git a/lib/src/config/registration_options.dart b/lib/src/config/registration_options.dart index 01abe48..a877ead 100644 --- a/lib/src/config/registration_options.dart +++ b/lib/src/config/registration_options.dart @@ -12,6 +12,7 @@ class RegistrationOptions { required this.registrationRepository, required this.registrationSteps, required this.afterRegistration, + this.spacerConfig = const RegistrationSpacerConfig(), this.registrationTranslations = const RegistrationTranslations.empty(), this.onError, this.customAppbarBuilder, @@ -23,6 +24,7 @@ class RegistrationOptions { this.loginButton, }); + final RegistrationSpacerConfig spacerConfig; final RegistrationTranslations registrationTranslations; final List registrationSteps; final int? Function(String error)? onError; diff --git a/lib/src/config/registration_spacers.dart b/lib/src/config/registration_spacers.dart new file mode 100644 index 0000000..46840f2 --- /dev/null +++ b/lib/src/config/registration_spacers.dart @@ -0,0 +1,12 @@ +class RegistrationSpacerConfig { + const RegistrationSpacerConfig({ + this.beforeTitleSpacer, + this.afterTitleSpacer, + this.afterFormSpacer, + this.formFlex = 1, + }); + final int? beforeTitleSpacer; + final int? afterTitleSpacer; + final int? afterFormSpacer; + final int? formFlex; +} diff --git a/lib/src/registration_screen.dart b/lib/src/registration_screen.dart index 33695de..d39ea01 100644 --- a/lib/src/registration_screen.dart +++ b/lib/src/registration_screen.dart @@ -52,6 +52,7 @@ class RegistrationScreenState extends State { var translations = widget.registrationOptions.registrationTranslations; return AuthScreen( + registrationOptions: widget.registrationOptions, steps: widget.registrationOptions.registrationSteps, customAppBar: widget.registrationOptions.customAppbarBuilder?.call( translations.title, diff --git a/pubspec.yaml b/pubspec.yaml index 89d3bd5..e3d9761 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ name: flutter_registration description: A Flutter Registration package -version: 2.0.1 +version: 2.0.2 repository: https://github.com/Iconica-Development/flutter_registration publish_to: none