initial functional register page
parent
b65da2fe3a
commit
68766a03ad
|
|
@ -0,0 +1,39 @@
|
||||||
|
class UserModel {
|
||||||
|
int? id;
|
||||||
|
String? name;
|
||||||
|
String? companyname;
|
||||||
|
String? email;
|
||||||
|
String? channel;
|
||||||
|
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.fromJson(Map<String, dynamic> json) {
|
||||||
|
id = json['id'];
|
||||||
|
name = json['name'];
|
||||||
|
companyname = json['companyname'];
|
||||||
|
email = json['email'];
|
||||||
|
channel = json['channel'];
|
||||||
|
usertype = json['usertype'];
|
||||||
|
blocked = json['blocked'];
|
||||||
|
cancelled = json['cancelled'];
|
||||||
|
createdby = json['createdby'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = <String, dynamic>{};
|
||||||
|
data['id'] = id;
|
||||||
|
data['name'] = name;
|
||||||
|
data['companyname'] = companyname;
|
||||||
|
data['email'] = email;
|
||||||
|
data['channel'] = channel;
|
||||||
|
data['usertype'] = usertype;
|
||||||
|
data['blocked'] = blocked;
|
||||||
|
data['cancelled'] = cancelled;
|
||||||
|
data['createdby'] = createdby;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,20 +1,232 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'dart:convert';
|
||||||
import 'package:pcastlivetv/components/nc_base_page.dart';
|
|
||||||
|
|
||||||
class RegisterPage extends StatelessWidget {
|
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:pcastlivetv/components/nc_form_field.dart';
|
||||||
|
import 'package:pcastlivetv/stores/login_store.dart';
|
||||||
|
import 'package:validatorless/validatorless.dart';
|
||||||
|
import 'package:velocity_x/velocity_x.dart';
|
||||||
|
|
||||||
|
class RegisterPage extends StatefulWidget {
|
||||||
const RegisterPage({super.key});
|
const RegisterPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RegisterPage> createState() => _RegisterPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RegisterPageState extends State<RegisterPage> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return const NcBasePage(
|
LoginStore store = VxState.store as LoginStore;
|
||||||
body: Center(
|
|
||||||
child: Column(
|
final formKey = GlobalKey<FormState>();
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
String name = '';
|
||||||
Text("Register Page"),
|
String companyname = '';
|
||||||
],
|
String email = '';
|
||||||
|
String password = '';
|
||||||
|
String channel = '';
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
color: const Color.fromRGBO(166, 0, 249, 1),
|
||||||
|
child: Center(
|
||||||
|
child: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Card(
|
||||||
|
elevation: 20,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(10),
|
||||||
|
side: const BorderSide(
|
||||||
|
width: 1,
|
||||||
|
color: Colors.black,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 32.0,
|
||||||
|
),
|
||||||
|
"Registrar-se".text.xl5.bold.make(),
|
||||||
|
const SizedBox(
|
||||||
|
height: 32.0,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width / 2,
|
||||||
|
child: Form(
|
||||||
|
key: formKey,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 64.0,
|
||||||
|
right: 64,
|
||||||
|
bottom: 32,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
NCFormField(
|
||||||
|
label: 'Nome',
|
||||||
|
value: name,
|
||||||
|
validator: Validatorless.required('Nome é obrigatório'),
|
||||||
|
onChanged: (value) => name = value,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 16.0,
|
||||||
|
),
|
||||||
|
NCFormField(
|
||||||
|
label: 'Empresa',
|
||||||
|
value: companyname,
|
||||||
|
validator: Validatorless.required('Nome da empresa é obrigatório'),
|
||||||
|
onChanged: (value) => companyname = value,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 16.0,
|
||||||
|
),
|
||||||
|
NCFormField(
|
||||||
|
label: 'Email',
|
||||||
|
value: 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,
|
||||||
|
obscureText: true,
|
||||||
|
validator: Validatorless.required('Senha é obrigatória'),
|
||||||
|
onChanged: (value) => password = value,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 32.0,
|
||||||
|
),
|
||||||
|
NCFormField(
|
||||||
|
label: 'Canal',
|
||||||
|
value: channel,
|
||||||
|
validator: Validatorless.required('Nome do canal é obrigatório'),
|
||||||
|
onChanged: (value) => channel = value,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 16.0,
|
||||||
|
),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ElevatedButton.styleFrom(
|
||||||
|
backgroundColor: const Color.fromRGBO(166, 0, 249, 1),
|
||||||
|
foregroundColor: Colors.white,
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: () async {
|
||||||
|
var data = json.encode(
|
||||||
|
{
|
||||||
|
"name": name,
|
||||||
|
"companyname": companyname,
|
||||||
|
"email": email,
|
||||||
|
"password": password,
|
||||||
|
"channel": channel,
|
||||||
|
"usertype": "U",
|
||||||
|
"blocked": "N",
|
||||||
|
"cancelled": "N",
|
||||||
|
"createdby": "Site",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
var dio = Dio();
|
||||||
|
var response = await dio.request(
|
||||||
|
'http://localhost:8112/register',
|
||||||
|
options: Options(
|
||||||
|
method: 'POST',
|
||||||
|
contentType: 'application/json',
|
||||||
|
),
|
||||||
|
data: data,
|
||||||
|
);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
print(json.encode(response.data));
|
||||||
|
break;
|
||||||
|
case 406:
|
||||||
|
print('Usuário já cadastrado');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
print(response.statusMessage);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.all(8.0),
|
||||||
|
child: Text('Registrar', style: TextStyle(fontSize: 24)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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()) {
|
||||||
|
formKey.currentState!.save();
|
||||||
|
store.email = email;
|
||||||
|
store.password = password;
|
||||||
|
try {
|
||||||
|
close = context.showLoading(
|
||||||
|
msg: '',
|
||||||
|
bgColor: Colors.transparent,
|
||||||
|
textSize: 20,
|
||||||
|
);
|
||||||
|
|
||||||
|
await store.login();
|
||||||
|
close();
|
||||||
|
|
||||||
|
if (store.isLogged) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (store.message != "") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
close!();
|
||||||
|
_displayErrorMotionToast(e.toString().replaceAll("Exception: ", ""));
|
||||||
|
}
|
||||||
|
// SnackBarService.showSnackBar(content: e.toString().replaceAll("Exception: ", ""), error: true);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue