fix: registration screen

This commit is contained in:
mike doornenbal 2024-03-08 14:55:34 +01:00
parent 7a4bcd8b3f
commit 89987c5e8d
7 changed files with 162 additions and 129 deletions

View file

@ -4,11 +4,17 @@ SPDX-FileCopyrightText: 2022 Iconica
SPDX-License-Identifier: GPL-3.0-or-later 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 # 2.0.1
- feat: added circular progress indicator while awaiting registration of user - feat: added circular progress indicator while awaiting registration of user
- feat: added alignment option for buttons - feat: added alignment option for buttons
# 2.0.0 # 2.0.0
- feat(buttons): Added the possiblity to only have a next button by return zero on the previous button builder - 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: exposed input decoration in AuthTextField
- feat: added title widget and login button builder - feat: added title widget and login button builder

View file

@ -17,3 +17,4 @@ export 'src/registration_screen.dart';
export 'src/service/registration_repository.dart'; export 'src/service/registration_repository.dart';
export 'package:flutter_input_library/flutter_input_library.dart' export 'package:flutter_input_library/flutter_input_library.dart'
show BoolWidgetType; show BoolWidgetType;
export 'src/config/registration_spacers.dart';

View file

@ -9,6 +9,7 @@ import 'package:flutter_registration/flutter_registration.dart';
class AuthScreen extends StatefulWidget { class AuthScreen extends StatefulWidget {
const AuthScreen({ const AuthScreen({
required this.registrationOptions,
required this.appBarTitle, required this.appBarTitle,
required this.steps, required this.steps,
required this.submitBtnTitle, required this.submitBtnTitle,
@ -22,14 +23,11 @@ class AuthScreen extends StatefulWidget {
this.previousButtonBuilder, this.previousButtonBuilder,
this.titleWidget, this.titleWidget,
this.loginButton, this.loginButton,
this.titleFlex,
this.formFlex,
this.beforeTitleFlex,
this.afterTitleFlex,
this.isLoading = false, this.isLoading = false,
super.key, super.key,
}) : assert(steps.length > 0, 'At least one step is required'); }) : assert(steps.length > 0, 'At least one step is required');
final RegistrationOptions registrationOptions;
final String appBarTitle; final String appBarTitle;
final Future<void> Function({ final Future<void> Function({
required HashMap<String, dynamic> values, required HashMap<String, dynamic> values,
@ -48,10 +46,6 @@ class AuthScreen extends StatefulWidget {
previousButtonBuilder; previousButtonBuilder;
final Widget? titleWidget; final Widget? titleWidget;
final Widget? loginButton; final Widget? loginButton;
final int? titleFlex;
final int? formFlex;
final int? beforeTitleFlex;
final int? afterTitleFlex;
final bool isLoading; final bool isLoading;
@override @override
@ -164,24 +158,47 @@ class _AuthScreenState extends State<AuthScreen> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
if (widget.titleWidget != null) ...[ if (widget.registrationOptions.spacerConfig
Expanded( .beforeTitleSpacer !=
flex: widget.titleFlex ?? 1, null)
Spacer(
flex: widget.registrationOptions.spacerConfig
.beforeTitleSpacer!,
),
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( child: Column(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [ children: [
Expanded( for (AuthField field
flex: widget.beforeTitleFlex ?? 3, in widget.steps[i].fields)
child: Container(), Align(
), child: Column(
widget.titleWidget!, children: [
Expanded( if (field.title != null) field.title!,
flex: widget.afterTitleFlex ?? 2, field.build(context, () {
child: Container(), _validate(i);
), })
], ],
), ),
)
],
),
),
if (widget.registrationOptions.spacerConfig
.afterFormSpacer !=
null)
Spacer(
flex: widget.registrationOptions.spacerConfig
.afterFormSpacer!,
), ),
Column( Column(
children: [ children: [
@ -194,8 +211,7 @@ class _AuthScreenState extends State<AuthScreen> {
widget.previousButtonBuilder widget.previousButtonBuilder
?.call( ?.call(
onPrevious, onPrevious,
widget widget.previousBtnTitle,
.previousBtnTitle,
i, i,
) == ) ==
null) null)
@ -207,8 +223,7 @@ class _AuthScreenState extends State<AuthScreen> {
children: [ children: [
if (widget.previousButtonBuilder == if (widget.previousButtonBuilder ==
null) ...[ null) ...[
if (widget.steps.first != if (widget.steps.first != widget.steps[i])
widget.steps[i])
ElevatedButton( ElevatedButton(
onPressed: onPrevious, onPressed: onPrevious,
child: Row( child: Row(
@ -218,8 +233,7 @@ class _AuthScreenState extends State<AuthScreen> {
size: 18, size: 18,
), ),
Padding( Padding(
padding: padding: const EdgeInsets.only(
const EdgeInsets.only(
left: 4.0), left: 4.0),
child: Text( child: Text(
widget.previousBtnTitle), widget.previousBtnTitle),
@ -240,8 +254,7 @@ class _AuthScreenState extends State<AuthScreen> {
!_formValid !_formValid
? null ? null
: () async { : () async {
await onNext( await onNext(widget.steps[i]);
widget.steps[i]);
}, },
widget.steps.last == widget.steps[i] widget.steps.last == widget.steps[i]
? widget.submitBtnTitle ? widget.submitBtnTitle
@ -253,8 +266,7 @@ class _AuthScreenState extends State<AuthScreen> {
onPressed: !_formValid onPressed: !_formValid
? null ? null
: () async { : () async {
await onNext( await onNext(widget.steps[i]);
widget.steps[i]);
}, },
child: Row( child: Row(
children: [ children: [
@ -265,8 +277,8 @@ class _AuthScreenState extends State<AuthScreen> {
: widget.nextBtnTitle, : widget.nextBtnTitle,
), ),
const Padding( const Padding(
padding: EdgeInsets.only( padding:
left: 4.0), EdgeInsets.only(left: 4.0),
child: Icon( child: Icon(
Icons.arrow_forward, Icons.arrow_forward,
size: 18, size: 18,
@ -284,7 +296,6 @@ class _AuthScreenState extends State<AuthScreen> {
), ),
], ],
), ),
],
]), ]),
]), ]),
)); ));

View file

@ -12,6 +12,7 @@ class RegistrationOptions {
required this.registrationRepository, required this.registrationRepository,
required this.registrationSteps, required this.registrationSteps,
required this.afterRegistration, required this.afterRegistration,
this.spacerConfig = const RegistrationSpacerConfig(),
this.registrationTranslations = const RegistrationTranslations.empty(), this.registrationTranslations = const RegistrationTranslations.empty(),
this.onError, this.onError,
this.customAppbarBuilder, this.customAppbarBuilder,
@ -23,6 +24,7 @@ class RegistrationOptions {
this.loginButton, this.loginButton,
}); });
final RegistrationSpacerConfig spacerConfig;
final RegistrationTranslations registrationTranslations; final RegistrationTranslations registrationTranslations;
final List<AuthStep> registrationSteps; final List<AuthStep> registrationSteps;
final int? Function(String error)? onError; final int? Function(String error)? onError;

View file

@ -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;
}

View file

@ -52,6 +52,7 @@ class RegistrationScreenState extends State<RegistrationScreen> {
var translations = widget.registrationOptions.registrationTranslations; var translations = widget.registrationOptions.registrationTranslations;
return AuthScreen( return AuthScreen(
registrationOptions: widget.registrationOptions,
steps: widget.registrationOptions.registrationSteps, steps: widget.registrationOptions.registrationSteps,
customAppBar: widget.registrationOptions.customAppbarBuilder?.call( customAppBar: widget.registrationOptions.customAppbarBuilder?.call(
translations.title, translations.title,

View file

@ -4,7 +4,7 @@
name: flutter_registration name: flutter_registration
description: A Flutter Registration package description: A Flutter Registration package
version: 2.0.1 version: 2.0.2
repository: https://github.com/Iconica-Development/flutter_registration repository: https://github.com/Iconica-Development/flutter_registration
publish_to: none publish_to: none