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
-->
# 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

View file

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

View file

@ -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<void> Function({
required HashMap<String, dynamic> 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,24 +158,47 @@ class _AuthScreenState extends State<AuthScreen> {
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
if (widget.titleWidget != null) ...[
Expanded(
flex: widget.titleFlex ?? 1,
if (widget.registrationOptions.spacerConfig
.beforeTitleSpacer !=
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(
mainAxisAlignment: MainAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
flex: widget.beforeTitleFlex ?? 3,
child: Container(),
),
widget.titleWidget!,
Expanded(
flex: widget.afterTitleFlex ?? 2,
child: Container(),
),
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: [
@ -194,8 +211,7 @@ class _AuthScreenState extends State<AuthScreen> {
widget.previousButtonBuilder
?.call(
onPrevious,
widget
.previousBtnTitle,
widget.previousBtnTitle,
i,
) ==
null)
@ -207,8 +223,7 @@ class _AuthScreenState extends State<AuthScreen> {
children: [
if (widget.previousButtonBuilder ==
null) ...[
if (widget.steps.first !=
widget.steps[i])
if (widget.steps.first != widget.steps[i])
ElevatedButton(
onPressed: onPrevious,
child: Row(
@ -218,8 +233,7 @@ class _AuthScreenState extends State<AuthScreen> {
size: 18,
),
Padding(
padding:
const EdgeInsets.only(
padding: const EdgeInsets.only(
left: 4.0),
child: Text(
widget.previousBtnTitle),
@ -240,8 +254,7 @@ class _AuthScreenState extends State<AuthScreen> {
!_formValid
? null
: () async {
await onNext(
widget.steps[i]);
await onNext(widget.steps[i]);
},
widget.steps.last == widget.steps[i]
? widget.submitBtnTitle
@ -253,8 +266,7 @@ class _AuthScreenState extends State<AuthScreen> {
onPressed: !_formValid
? null
: () async {
await onNext(
widget.steps[i]);
await onNext(widget.steps[i]);
},
child: Row(
children: [
@ -265,8 +277,8 @@ class _AuthScreenState extends State<AuthScreen> {
: widget.nextBtnTitle,
),
const Padding(
padding: EdgeInsets.only(
left: 4.0),
padding:
EdgeInsets.only(left: 4.0),
child: Icon(
Icons.arrow_forward,
size: 18,
@ -284,7 +296,6 @@ class _AuthScreenState extends State<AuthScreen> {
),
],
),
],
]),
]),
));

View file

@ -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<AuthStep> registrationSteps;
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;
return AuthScreen(
registrationOptions: widget.registrationOptions,
steps: widget.registrationOptions.registrationSteps,
customAppBar: widget.registrationOptions.customAppbarBuilder?.call(
translations.title,

View file

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