register page completed
parent
0a8aeb96d8
commit
9d271357d9
|
|
@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
|
|||
|
||||
class NCFormField extends StatelessWidget {
|
||||
final String label;
|
||||
final String value;
|
||||
final TextEditingController controller;
|
||||
final bool? obscureText;
|
||||
final void Function(String)? onChanged;
|
||||
final String? Function(String?)? validator;
|
||||
|
|
@ -12,7 +12,7 @@ class NCFormField extends StatelessWidget {
|
|||
const NCFormField({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.value,
|
||||
required this.controller,
|
||||
this.onChanged,
|
||||
this.validator,
|
||||
this.inputFormatters,
|
||||
|
|
@ -24,7 +24,7 @@ class NCFormField extends StatelessWidget {
|
|||
height: 80,
|
||||
child: TextFormField(
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
initialValue: value,
|
||||
controller: controller,
|
||||
validator: validator,
|
||||
onChanged: onChanged,
|
||||
inputFormatters: inputFormatters,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
class UserModel {
|
||||
int? id;
|
||||
String? message;
|
||||
String? name;
|
||||
String? companyname;
|
||||
String? email;
|
||||
|
|
@ -13,6 +14,7 @@ class UserModel {
|
|||
|
||||
UserModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
message = json['message'] ?? '';
|
||||
name = json['name'];
|
||||
companyname = json['companyname'];
|
||||
email = json['email'];
|
||||
|
|
@ -26,6 +28,7 @@ class UserModel {
|
|||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['id'] = id;
|
||||
data['message'] = message;
|
||||
data['name'] = name;
|
||||
data['companyname'] = companyname;
|
||||
data['email'] = email;
|
||||
|
|
|
|||
|
|
@ -21,8 +21,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
String email = '';
|
||||
String password = '';
|
||||
TextEditingController email = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
return Container(
|
||||
color: const Color.fromRGBO(166, 0, 249, 1),
|
||||
child: Center(
|
||||
|
|
@ -61,24 +61,22 @@ class _LoginPageState extends State<LoginPage> {
|
|||
children: [
|
||||
NCFormField(
|
||||
label: 'Email',
|
||||
value: email,
|
||||
controller: email,
|
||||
validator: Validatorless.multiple(
|
||||
[
|
||||
Validatorless.email('Email inválido'),
|
||||
Validatorless.required('Email é obrigatório'),
|
||||
],
|
||||
),
|
||||
onChanged: (value) => email = value,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16.0,
|
||||
),
|
||||
NCFormField(
|
||||
label: 'Senha',
|
||||
value: password,
|
||||
controller: password,
|
||||
obscureText: true,
|
||||
validator: Validatorless.required('Senha é obrigatória'),
|
||||
onChanged: (value) => password = value,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 32.0,
|
||||
|
|
@ -92,7 +90,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var result = await processAuth(formKey, store, email, password);
|
||||
var result = await processAuth(formKey, store, email.text, password.text);
|
||||
if (result) {
|
||||
switch (store.userType) {
|
||||
case 'A':
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import 'package:motion_toast/motion_toast.dart';
|
|||
import 'package:motion_toast/resources/arrays.dart';
|
||||
import 'package:pcastlivetv/components/nc_form_field.dart';
|
||||
import 'package:pcastlivetv/globals.dart';
|
||||
import 'package:pcastlivetv/models/user_model.dart';
|
||||
import 'package:pcastlivetv/routes.dart';
|
||||
import 'package:pcastlivetv/stores/login_store.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
|
|
@ -25,12 +26,12 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
String name = '';
|
||||
String companyname = '';
|
||||
String email = '';
|
||||
String password = '';
|
||||
String password2 = '';
|
||||
String channel = '';
|
||||
TextEditingController name = TextEditingController();
|
||||
TextEditingController companyname = TextEditingController();
|
||||
TextEditingController email = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
TextEditingController password2 = TextEditingController();
|
||||
TextEditingController channel = TextEditingController();
|
||||
|
||||
return Container(
|
||||
color: const Color.fromRGBO(166, 0, 249, 1),
|
||||
|
|
@ -69,21 +70,17 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
),
|
||||
child: Column(
|
||||
children: [
|
||||
NCFormField(label: 'Nome', value: name, validator: Validatorless.required('Nome é obrigatório'), onChanged: (value) => name = value),
|
||||
NCFormField(label: 'Empresa', value: companyname, validator: Validatorless.required('Nome da empresa é obrigatório'), onChanged: (value) => companyname = value),
|
||||
NCFormField(
|
||||
label: 'Email',
|
||||
value: email,
|
||||
validator: Validatorless.multiple([Validatorless.email('Email inválido'), Validatorless.required('Email é obrigatório')]),
|
||||
onChanged: (value) => email = value),
|
||||
NCFormField(label: 'Senha', value: password, obscureText: true, validator: Validatorless.required('Senha é obrigatória'), onChanged: (value) => password = value),
|
||||
NCFormField(label: 'Nome', controller: name, validator: Validatorless.required('Nome é obrigatório')),
|
||||
NCFormField(label: 'Empresa', controller: companyname, validator: Validatorless.required('Nome da empresa é obrigatório')),
|
||||
NCFormField(label: 'Email', controller: email, validator: Validatorless.multiple([Validatorless.email('Email inválido'), Validatorless.required('Email é obrigatório')])),
|
||||
NCFormField(label: 'Senha', controller: password, obscureText: true, validator: Validatorless.required('Senha é obrigatória')),
|
||||
NCFormField(
|
||||
label: 'Confirme Senha',
|
||||
value: password,
|
||||
controller: password2,
|
||||
obscureText: true,
|
||||
validator: Validatorless.required('Senha de confirmação é obrigatória'),
|
||||
onChanged: (value) => password2 = value),
|
||||
NCFormField(label: 'Canal', value: channel, validator: Validatorless.required('Nome do canal é obrigatório'), onChanged: (value) => channel = value),
|
||||
validator: Validatorless.multiple([Validatorless.required('Senha é obrigatória'), Validatorless.compare(password, 'Senhas não conferem')]),
|
||||
),
|
||||
NCFormField(label: 'Canal', controller: channel, validator: Validatorless.required('Nome do canal é obrigatório')),
|
||||
const SizedBox(height: 16.0),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
|
|
@ -94,9 +91,9 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var result = await registerUser(name, companyname, email, password, password2, channel);
|
||||
var result = await registerUser(formKey, store, name.text, companyname.text, email.text, password.text, password2.text, channel.text);
|
||||
if (result) {
|
||||
var result = await processAuth(formKey, store, email, password);
|
||||
var result = await processAuth(formKey, store, email.text, password.text);
|
||||
if (result) {
|
||||
router.go('/user');
|
||||
}
|
||||
|
|
@ -139,7 +136,11 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
).show(context);
|
||||
}
|
||||
|
||||
Future<bool> registerUser(String name, String companyname, String email, String password, String password2, String channel) async {
|
||||
Future<bool> registerUser(GlobalKey<FormState> formKey, LoginStore store, String name, String companyname, String email, String password, String password2, String channel) async {
|
||||
if (formKey.currentState!.validate()) {
|
||||
formKey.currentState!.save();
|
||||
store.email = email;
|
||||
store.password = password;
|
||||
var data = json.encode({
|
||||
"name": name,
|
||||
"companyname": companyname,
|
||||
|
|
@ -162,7 +163,11 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
print(json.encode(response.data));
|
||||
var u = UserModel.fromJson(response.data);
|
||||
if (u.message != "") {
|
||||
_displayErrorMotionToast(u.message!);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 406:
|
||||
_displayErrorMotionToast('Usuário já cadastrado');
|
||||
|
|
@ -170,6 +175,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
default:
|
||||
_displayErrorMotionToast(response.statusMessage!);
|
||||
}
|
||||
}
|
||||
return Future.value(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue