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,127 +158,144 @@ 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)
child: Column( Spacer(
mainAxisAlignment: MainAxisAlignment.start, flex: widget.registrationOptions.spacerConfig
mainAxisSize: MainAxisSize.min, .beforeTitleSpacer!,
children: [
Expanded(
flex: widget.beforeTitleFlex ?? 3,
child: Container(),
),
widget.titleWidget!,
Expanded(
flex: widget.afterTitleFlex ?? 2,
child: Container(),
),
],
),
), ),
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: [ children: [
Row( for (AuthField field
mainAxisAlignment: in widget.steps[i].fields)
widget.buttonMainAxisAlignment != null Align(
? widget.buttonMainAxisAlignment! child: Column(
: (widget.previousButtonBuilder != children: [
null && if (field.title != null) field.title!,
widget.previousButtonBuilder field.build(context, () {
?.call( _validate(i);
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!,
),
], ],
), ),
], ),
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!,
),
],
),
]), ]),
]), ]),
)); ));

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