mirror of
https://github.com/Iconica-Development/flutter_registration.git
synced 2025-05-19 13:23:45 +02:00
87 lines
2.4 KiB
Dart
87 lines
2.4 KiB
Dart
|
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,
|
||
|
super.key,
|
||
|
});
|
||
|
|
||
|
final VoidCallback afterRegistration;
|
||
|
final RegistrationRepository repository;
|
||
|
|
||
|
@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,
|
||
|
],
|
||
|
),
|
||
|
],
|
||
|
)
|
||
|
],
|
||
|
onFinish: (values) => register(
|
||
|
values['email']!,
|
||
|
values['password']!,
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|