2022-11-01 09:19:20 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Iconica
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
|
2022-09-28 09:23:41 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-26 10:35:53 +02:00
|
|
|
import 'package:flutter_registration/flutter_registration.dart';
|
|
|
|
|
|
|
|
class RegistrationOptions {
|
|
|
|
RegistrationOptions({
|
|
|
|
required this.registrationRepository,
|
|
|
|
required this.registrationSteps,
|
|
|
|
required this.afterRegistration,
|
|
|
|
this.registrationTranslations = const RegistrationTranslations(),
|
2023-09-19 11:16:43 +02:00
|
|
|
this.onError,
|
2022-09-28 09:23:41 +02:00
|
|
|
this.customAppbarBuilder,
|
2023-02-16 15:02:03 +01:00
|
|
|
this.nextButtonBuilder,
|
|
|
|
this.previousButtonBuilder,
|
2023-09-19 11:16:43 +02:00
|
|
|
this.backgroundColor,
|
2022-09-26 10:35:53 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
final RegistrationTranslations registrationTranslations;
|
|
|
|
final List<AuthStep> registrationSteps;
|
2023-09-20 11:45:55 +02:00
|
|
|
final void Function(String error)? onError;
|
2022-09-26 10:35:53 +02:00
|
|
|
final VoidCallback afterRegistration;
|
|
|
|
final RegistrationRepository registrationRepository;
|
2022-09-28 09:23:41 +02:00
|
|
|
final AppBar Function(String title)? customAppbarBuilder;
|
2023-02-16 15:02:03 +01:00
|
|
|
final Widget Function(VoidCallback onPressed, String label)?
|
|
|
|
nextButtonBuilder;
|
|
|
|
final Widget Function(VoidCallback onPressed, String label)?
|
|
|
|
previousButtonBuilder;
|
2023-09-19 11:16:43 +02:00
|
|
|
final Color? backgroundColor;
|
2022-09-26 10:35:53 +02:00
|
|
|
|
2022-11-04 11:38:16 +01:00
|
|
|
static List<AuthStep> getDefaultSteps({
|
2023-03-09 09:12:05 +01:00
|
|
|
TextEditingController? emailController,
|
|
|
|
TextEditingController? pass1Controller,
|
|
|
|
bool pass1Hidden = true,
|
|
|
|
TextEditingController? pass2Controller,
|
|
|
|
bool pass2Hidden = true,
|
|
|
|
Function(bool mainPass, bool value)? passHideOnChange,
|
2022-11-04 11:38:16 +01:00
|
|
|
RegistrationTranslations translations = const RegistrationTranslations(),
|
2023-02-16 15:02:03 +01:00
|
|
|
Function(String title)? titleBuilder,
|
|
|
|
Function(String label)? labelBuilder,
|
|
|
|
TextStyle? textStyle,
|
2023-02-24 14:19:31 +01:00
|
|
|
String? initialEmail,
|
2023-02-16 15:02:03 +01:00
|
|
|
}) {
|
|
|
|
var password1 = '';
|
|
|
|
|
|
|
|
return [
|
|
|
|
AuthStep(
|
|
|
|
fields: [
|
|
|
|
AuthTextField(
|
|
|
|
name: 'email',
|
2023-03-09 09:12:05 +01:00
|
|
|
textEditingController: emailController,
|
2023-02-24 14:19:31 +01:00
|
|
|
value: initialEmail ?? '',
|
2023-02-16 15:02:03 +01:00
|
|
|
title: titleBuilder?.call(
|
|
|
|
translations.defaultEmailTitle,
|
|
|
|
) ??
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 24.0,
|
|
|
|
bottom: 12.0,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
translations.defaultEmailTitle,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
label: labelBuilder?.call(translations.defaultEmailLabel),
|
|
|
|
hintText: translations.defaultEmailHint,
|
|
|
|
textStyle: textStyle,
|
|
|
|
validators: [
|
|
|
|
(email) => (email == null || email.isEmpty)
|
|
|
|
? translations.defaultEmailEmpty
|
|
|
|
: null,
|
|
|
|
(email) =>
|
|
|
|
RegExp(r"""(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])""")
|
|
|
|
.hasMatch(email!)
|
|
|
|
? null
|
|
|
|
: translations.defaultEmailValidatorMessage,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
AuthStep(
|
|
|
|
fields: [
|
|
|
|
AuthTextField(
|
|
|
|
name: 'password1',
|
2023-03-09 09:12:05 +01:00
|
|
|
textEditingController: pass1Controller,
|
2023-02-16 15:02:03 +01:00
|
|
|
title: titleBuilder?.call(
|
|
|
|
translations.defaultPassword1Title,
|
|
|
|
) ??
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 24.0,
|
|
|
|
bottom: 12.0,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
translations.defaultPassword1Title,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
label: labelBuilder?.call(translations.defaultPassword1Label),
|
|
|
|
hintText: translations.defaultPassword1Hint,
|
|
|
|
textStyle: textStyle,
|
|
|
|
obscureText: true,
|
|
|
|
validators: [
|
|
|
|
(value) => (value == null || value.isEmpty)
|
|
|
|
? translations.defaultPassword1ValidatorMessage
|
|
|
|
: null,
|
|
|
|
],
|
|
|
|
onChange: (value) {
|
|
|
|
password1 = value;
|
|
|
|
},
|
2023-03-09 09:12:05 +01:00
|
|
|
hidden: pass1Hidden,
|
|
|
|
onPassChanged: (value) {
|
|
|
|
passHideOnChange?.call(true, value);
|
|
|
|
},
|
2023-02-16 15:02:03 +01:00
|
|
|
),
|
|
|
|
AuthTextField(
|
|
|
|
name: 'password2',
|
2023-03-09 09:12:05 +01:00
|
|
|
textEditingController: pass2Controller,
|
2023-03-31 11:15:48 +02:00
|
|
|
title: titleBuilder?.call(
|
|
|
|
translations.defaultPassword2Title,
|
|
|
|
) ??
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 24.0,
|
|
|
|
bottom: 12.0,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
translations.defaultPassword2Title,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2023-02-16 15:02:03 +01:00
|
|
|
label: labelBuilder?.call(translations.defaultPassword2Label),
|
|
|
|
hintText: translations.defaultPassword2Hint,
|
|
|
|
textStyle: textStyle,
|
|
|
|
obscureText: true,
|
|
|
|
validators: [
|
2023-03-09 09:12:05 +01:00
|
|
|
(value) {
|
|
|
|
if (pass1Controller != null) {
|
|
|
|
if (value != pass1Controller.value.text) {
|
|
|
|
return translations.defaultPassword2ValidatorMessage;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (value != password1) {
|
|
|
|
return translations.defaultPassword2ValidatorMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2023-02-16 15:02:03 +01:00
|
|
|
],
|
2023-03-09 09:12:05 +01:00
|
|
|
hidden: pass2Hidden,
|
|
|
|
onPassChanged: (value) {
|
|
|
|
passHideOnChange?.call(false, value);
|
|
|
|
},
|
2023-02-16 15:02:03 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
];
|
|
|
|
}
|
2022-09-26 10:35:53 +02:00
|
|
|
}
|