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';
|
|
|
|
|
|
|
|
class RegistrationScreen extends StatelessWidget {
|
|
|
|
const RegistrationScreen({
|
2022-09-26 10:35:53 +02:00
|
|
|
required this.registrationOptions,
|
2022-09-20 15:51:22 +02:00
|
|
|
super.key,
|
|
|
|
});
|
|
|
|
|
2022-09-26 10:35:53 +02:00
|
|
|
final RegistrationOptions registrationOptions;
|
2022-09-20 15:51:22 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-26 10:35:53 +02:00
|
|
|
var translations = registrationOptions.registrationTranslations;
|
|
|
|
|
2022-09-20 15:51:22 +02:00
|
|
|
void showError(String error) => showDialog<String>(
|
|
|
|
context: context,
|
|
|
|
builder: (BuildContext context) => AlertDialog(
|
|
|
|
content: Text(error),
|
|
|
|
actions: <Widget>[
|
|
|
|
TextButton(
|
2022-09-26 10:35:53 +02:00
|
|
|
onPressed: () => Navigator.pop(
|
|
|
|
context,
|
|
|
|
translations.closeBtn,
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
translations.closeBtn,
|
|
|
|
),
|
2022-09-20 15:51:22 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2022-09-26 10:35:53 +02:00
|
|
|
void register(values) => registrationOptions.registrationRepository
|
2022-09-22 11:48:04 +02:00
|
|
|
.register(values)
|
2022-09-20 15:51:22 +02:00
|
|
|
.then(
|
2022-09-26 10:35:53 +02:00
|
|
|
(_) => registrationOptions.afterRegistration(),
|
2022-09-20 15:51:22 +02:00
|
|
|
)
|
|
|
|
.catchError(
|
|
|
|
(error) {
|
|
|
|
showError(
|
|
|
|
error.toString(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
return AuthScreen(
|
2022-09-26 10:35:53 +02:00
|
|
|
steps: registrationOptions.registrationSteps,
|
2022-09-22 11:48:04 +02:00
|
|
|
onFinish: register,
|
2022-09-26 10:35:53 +02:00
|
|
|
title: translations.title,
|
|
|
|
submitBtnTitle: translations.registerBtn,
|
|
|
|
nextBtnTitle: translations.nextStepBtn,
|
|
|
|
previousBtnTitle: translations.previousStepBtn,
|
2022-09-20 15:51:22 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|