feature: changes on register page / useer model
parent
b8958f4c5a
commit
8601b2ac6b
|
|
@ -21,7 +21,7 @@ class NCFormField extends StatelessWidget {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
height: 80,
|
||||
height: 70,
|
||||
child: TextFormField(
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
controller: controller,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
class Events {
|
||||
int? id;
|
||||
String? name;
|
||||
String? description;
|
||||
String? startDt;
|
||||
int? user;
|
||||
String? eventtype;
|
||||
String? transmitted;
|
||||
|
||||
Events({this.id, this.name, this.description, this.startDt, this.user, this.eventtype, this.transmitted});
|
||||
|
||||
Events.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
name = json['name'];
|
||||
description = json['description'];
|
||||
startDt = json['startDt'];
|
||||
user = json['user'];
|
||||
eventtype = json['eventtype'];
|
||||
transmitted = json['transmitted'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = <String, dynamic>{};
|
||||
data['id'] = id;
|
||||
data['name'] = name;
|
||||
data['description'] = description;
|
||||
data['startDt'] = startDt;
|
||||
data['user'] = user;
|
||||
data['eventtype'] = eventtype;
|
||||
data['transmitted'] = transmitted;
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,20 +3,24 @@ class UserModel {
|
|||
String? message;
|
||||
String? name;
|
||||
String? companyname;
|
||||
String? url;
|
||||
String? email;
|
||||
String? channel;
|
||||
String? cpfcnpj;
|
||||
String? usertype;
|
||||
String? blocked;
|
||||
String? cancelled;
|
||||
String? createdby;
|
||||
|
||||
UserModel({this.id, this.name, this.companyname, this.email, this.channel, this.usertype, this.blocked, this.cancelled, this.createdby});
|
||||
UserModel({this.id, this.name, this.companyname, this.email, this.channel, this.usertype, this.blocked, this.cancelled, this.createdby, this.cpfcnpj, this.url});
|
||||
|
||||
UserModel.fromJson(Map<String, dynamic> json) {
|
||||
id = json['id'];
|
||||
message = json['message'] ?? '';
|
||||
name = json['name'];
|
||||
companyname = json['companyname'];
|
||||
url = json['url'];
|
||||
cpfcnpj = json['cpfcnpj'];
|
||||
email = json['email'];
|
||||
channel = json['channel'];
|
||||
usertype = json['usertype'];
|
||||
|
|
@ -31,6 +35,8 @@ class UserModel {
|
|||
data['message'] = message;
|
||||
data['name'] = name;
|
||||
data['companyname'] = companyname;
|
||||
data['url'] = url;
|
||||
data['cpfcnpj'] = cpfcnpj;
|
||||
data['email'] = email;
|
||||
data['channel'] = channel;
|
||||
data['usertype'] = usertype;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
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/routes.dart';
|
||||
import 'package:pcastlivetv/services/snackbar_service.dart';
|
||||
import 'package:pcastlivetv/stores/login_store.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
import 'package:velocity_x/velocity_x.dart';
|
||||
|
|
@ -105,7 +104,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||
default:
|
||||
}
|
||||
} else {
|
||||
_displayErrorMotionToast(store.message!);
|
||||
SnackBarService.showSnackBar(context: context, message: store.message!);
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
|
|
@ -127,23 +126,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||
);
|
||||
}
|
||||
|
||||
void _displayErrorMotionToast(String message) {
|
||||
MotionToast.error(
|
||||
title: const Text(
|
||||
"ERRO",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
description: Text(message),
|
||||
position: MotionToastPosition.top,
|
||||
barrierColor: Colors.black.withOpacity(0.3),
|
||||
width: 300,
|
||||
height: 80,
|
||||
dismissable: false,
|
||||
).show(context);
|
||||
}
|
||||
|
||||
Future<bool> processAuth(GlobalKey<FormState> formKey, LoginStore store, String email, String password) async {
|
||||
Function? close;
|
||||
if (formKey.currentState!.validate()) {
|
||||
|
|
@ -169,9 +151,8 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
} catch (e) {
|
||||
close!();
|
||||
_displayErrorMotionToast(e.toString().replaceAll("Exception: ", ""));
|
||||
SnackBarService.showSnackBar(context: context, message: e.toString().replaceAll("Exception: ", ""));
|
||||
}
|
||||
// SnackBarService.showSnackBar(content: e.toString().replaceAll("Exception: ", ""), error: true);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,14 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:brasil_fields/brasil_fields.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:motion_toast/motion_toast.dart';
|
||||
import 'package:motion_toast/resources/arrays.dart';
|
||||
import 'package:flutter/services.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/services/snackbar_service.dart';
|
||||
import 'package:pcastlivetv/stores/login_store.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
import 'package:velocity_x/velocity_x.dart';
|
||||
|
|
@ -29,6 +30,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
TextEditingController name = TextEditingController();
|
||||
TextEditingController companyname = TextEditingController();
|
||||
TextEditingController email = TextEditingController();
|
||||
TextEditingController url = TextEditingController();
|
||||
TextEditingController cpfCnpj = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
TextEditingController password2 = TextEditingController();
|
||||
TextEditingController channel = TextEditingController();
|
||||
|
|
@ -70,27 +73,69 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
),
|
||||
child: Column(
|
||||
children: [
|
||||
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: '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')],
|
||||
[
|
||||
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: 'CPF/CNPJ',
|
||||
controller: cpfCnpj,
|
||||
inputFormatters: [
|
||||
FilteringTextInputFormatter.digitsOnly,
|
||||
CpfOuCnpjFormatter(),
|
||||
],
|
||||
validator: (value) {
|
||||
if (value!.isEmpty) {
|
||||
return 'CPF/CNPJ é obrigatório';
|
||||
} else if (CPFValidator.isValid(value) || CNPJValidator.isValid(value)) {
|
||||
return null;
|
||||
}
|
||||
return 'CPF ou CNPJ inválido';
|
||||
},
|
||||
),
|
||||
NCFormField(
|
||||
label: 'Site',
|
||||
controller: url,
|
||||
validator: Validatorless.required('Endereço do site é obrigatório'),
|
||||
),
|
||||
NCFormField(
|
||||
label: 'Senha',
|
||||
controller: password,
|
||||
obscureText: true,
|
||||
validator: Validatorless.required('Senha é obrigatória'),
|
||||
),
|
||||
NCFormField(
|
||||
label: 'Confirme Senha',
|
||||
controller: password2,
|
||||
obscureText: true,
|
||||
validator: Validatorless.multiple([Validatorless.required('Senha é obrigatória'), Validatorless.compare(password, 'Senhas não conferem')]),
|
||||
validator: Validatorless.multiple([
|
||||
Validatorless.required('Senha é obrigatória'),
|
||||
Validatorless.compare(password, 'Senhas não conferem'),
|
||||
]),
|
||||
),
|
||||
NCFormField(
|
||||
label: 'Canal',
|
||||
controller: channel,
|
||||
validator:
|
||||
Validatorless.multiple([Validatorless.required('Nome do canal é obrigatório'), Validatorless.onlyCharacters('Nome do canal deve conter apenas letras e números')]),
|
||||
validator: Validatorless.multiple([
|
||||
Validatorless.required('Nome do canal é obrigatório'),
|
||||
Validatorless.onlyCharacters('Nome do canal deve conter apenas letras e números'),
|
||||
]),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
ElevatedButton(
|
||||
|
|
@ -102,7 +147,18 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var result = await registerUser(formKey, store, name.text, companyname.text, email.text, password.text, password2.text, channel.text);
|
||||
var result = await registerUser(
|
||||
formKey,
|
||||
store,
|
||||
name.text,
|
||||
companyname.text,
|
||||
email.text,
|
||||
password.text,
|
||||
password2.text,
|
||||
channel.text,
|
||||
cpfCnpj.text,
|
||||
url.text,
|
||||
);
|
||||
if (result) {
|
||||
var result = await processAuth(formKey, store, email.text, password.text);
|
||||
if (result) {
|
||||
|
|
@ -130,24 +186,18 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
);
|
||||
}
|
||||
|
||||
void _displayErrorMotionToast(String message) {
|
||||
MotionToast.error(
|
||||
title: const Text(
|
||||
"ERRO",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
description: Text(message),
|
||||
position: MotionToastPosition.top,
|
||||
barrierColor: Colors.black.withOpacity(0.3),
|
||||
width: 300,
|
||||
height: 80,
|
||||
dismissable: false,
|
||||
).show(context);
|
||||
}
|
||||
|
||||
Future<bool> registerUser(GlobalKey<FormState> formKey, LoginStore store, 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,
|
||||
String cpfCnpj,
|
||||
String url,
|
||||
) async {
|
||||
if (formKey.currentState!.validate()) {
|
||||
formKey.currentState!.save();
|
||||
store.email = email;
|
||||
|
|
@ -155,9 +205,11 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
var data = json.encode({
|
||||
"name": name,
|
||||
"companyname": companyname,
|
||||
"url": url,
|
||||
"email": email,
|
||||
"password": password,
|
||||
"channel": channel,
|
||||
"cpfcnpj": cpfCnpj,
|
||||
"usertype": "U",
|
||||
"blocked": "N",
|
||||
"cancelled": "N",
|
||||
|
|
@ -176,15 +228,15 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
case 200:
|
||||
var u = UserModel.fromJson(response.data);
|
||||
if (u.message != "") {
|
||||
_displayErrorMotionToast(u.message!);
|
||||
SnackBarService.showSnackBar(context: context, message: u.message!);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 406:
|
||||
_displayErrorMotionToast('Usuário já cadastrado');
|
||||
SnackBarService.showSnackBar(context: context, message: 'Usuário já cadastrado');
|
||||
break;
|
||||
default:
|
||||
_displayErrorMotionToast(response.statusMessage!);
|
||||
SnackBarService.showSnackBar(context: context, message: response.statusMessage!);
|
||||
}
|
||||
}
|
||||
return Future.value(true);
|
||||
|
|
@ -215,9 +267,8 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
}
|
||||
} catch (e) {
|
||||
close!();
|
||||
_displayErrorMotionToast(e.toString().replaceAll("Exception: ", ""));
|
||||
SnackBarService.showSnackBar(context: context, message: e.toString().replaceAll("Exception: ", ""));
|
||||
}
|
||||
// SnackBarService.showSnackBar(content: e.toString().replaceAll("Exception: ", ""), error: true);
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,22 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../globals.dart';
|
||||
import 'package:motion_toast/motion_toast.dart';
|
||||
import 'package:motion_toast/resources/arrays.dart';
|
||||
|
||||
class SnackBarService {
|
||||
static void showSnackBar({required String content, bool error = false}) {
|
||||
snackbarKey.currentState?.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
content,
|
||||
textAlign: TextAlign.center,
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
static void showSnackBar({required BuildContext context, required String message}) {
|
||||
MotionToast.error(
|
||||
title: const Text(
|
||||
"ERRO",
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
),
|
||||
),
|
||||
backgroundColor: error ? Colors.red : Colors.green,
|
||||
duration: const Duration(seconds: 3),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(10.0),
|
||||
),
|
||||
elevation: 8.0,
|
||||
),
|
||||
);
|
||||
description: Text(message),
|
||||
position: MotionToastPosition.top,
|
||||
barrierColor: Colors.black.withOpacity(0.3),
|
||||
width: 300,
|
||||
height: 80,
|
||||
dismissable: false,
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
16
pubspec.lock
16
pubspec.lock
|
|
@ -25,6 +25,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
brasil_fields:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: brasil_fields
|
||||
sha256: "765f59e4e22fbfbc10d59d0208d369bad611c714419093ad14668a41863e49a8"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.14.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -49,6 +57,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.17.2"
|
||||
cpf_cnpj_validator:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: cpf_cnpj_validator
|
||||
sha256: "2d52caefe720f7428d8fd12b5dc3a9603e137ae4eafe032b8f1bd104d3656bfb"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ dependencies:
|
|||
|
||||
flutter_web_plugins:
|
||||
sdk: flutter
|
||||
brasil_fields: ^1.14.0
|
||||
cpf_cnpj_validator: ^2.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
|
|||
Loading…
Reference in New Issue