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