2022-09-20 15:51:22 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_registration/flutter_registration.dart';
|
|
|
|
import 'package:flutter_registration/src/auth_screen.dart';
|
|
|
|
import 'package:flutter_registration/src/model/auth_field.dart';
|
|
|
|
import 'package:flutter_registration/src/model/auth_step.dart';
|
|
|
|
|
|
|
|
class RegistrationScreen extends StatelessWidget {
|
|
|
|
const RegistrationScreen({
|
|
|
|
required this.afterRegistration,
|
|
|
|
required this.repository,
|
2022-09-22 09:40:25 +02:00
|
|
|
this.additionalSteps = const [],
|
2022-09-20 15:51:22 +02:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
|
|
|
final VoidCallback afterRegistration;
|
|
|
|
final RegistrationRepository repository;
|
2022-09-22 09:40:25 +02:00
|
|
|
final List<AuthStep> additionalSteps;
|
2022-09-20 15:51:22 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
void showError(String error) => showDialog<String>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => AlertDialog(
|
|
|
|
content: Text(error),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context, 'Sluit'),
|
|
|
|
child: const Text('Sluit'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
void register(String email, String password) => repository
|
|
|
|
.register(email, password)
|
|
|
|
.then(
|
|
|
|
(value) => afterRegistration(),
|
|
|
|
)
|
|
|
|
.catchError(
|
|
|
|
(error) {
|
|
|
|
showError(
|
|
|
|
error.toString(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return AuthScreen(
|
|
|
|
title: 'Registreren',
|
|
|
|
submitBtnTitle: 'Registreren',
|
|
|
|
steps: [
|
|
|
|
AuthStep(
|
|
|
|
fields: [
|
|
|
|
AuthField(
|
|
|
|
name: 'email',
|
|
|
|
title: 'Wat is je e-mailadres?',
|
|
|
|
validators: [
|
|
|
|
(value) => (value == null || value.isEmpty)
|
|
|
|
? 'Geef uw e-mailadres op'
|
|
|
|
: null,
|
|
|
|
(value) => !value!.contains('@')
|
|
|
|
? 'Geef een geldig e-mailadres op'
|
|
|
|
: null,
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
AuthStep(
|
|
|
|
fields: [
|
|
|
|
AuthField(
|
|
|
|
name: 'password',
|
|
|
|
title: 'Kies een wachtwoord',
|
|
|
|
obscureText: true,
|
|
|
|
validators: [
|
|
|
|
(value) => (value == null || value.isEmpty)
|
|
|
|
? 'Geef een wachtwoord op'
|
|
|
|
: null,
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
2022-09-22 09:40:25 +02:00
|
|
|
),
|
|
|
|
...additionalSteps
|
2022-09-20 15:51:22 +02:00
|
|
|
],
|
|
|
|
onFinish: (values) => register(
|
|
|
|
values['email']!,
|
|
|
|
values['password']!,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|