ajuste do SMS
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
|
|
||||||
import 'package:brasil_fields/brasil_fields.dart';
|
import 'package:brasil_fields/brasil_fields.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
@@ -30,9 +31,14 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
final inputCPF = TextEditingController();
|
final inputCPF = TextEditingController();
|
||||||
final inputSenha = TextEditingController();
|
final inputSenha = TextEditingController();
|
||||||
final inputRepita = TextEditingController();
|
final inputRepita = TextEditingController();
|
||||||
|
final inputCodigo = TextEditingController();
|
||||||
String? cidade;
|
String? cidade;
|
||||||
String cidadeQuery = '';
|
String cidadeQuery = '';
|
||||||
bool carregando = false;
|
bool carregando = false;
|
||||||
|
int tentativas = 0;
|
||||||
|
bool smsEnviado = false;
|
||||||
|
String nroSMS = '';
|
||||||
|
Map? mapAluno;
|
||||||
|
|
||||||
verificacao(){
|
verificacao(){
|
||||||
if(inputCPF.text.isNotEmpty){
|
if(inputCPF.text.isNotEmpty){
|
||||||
@@ -43,7 +49,6 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
if(cidadeQuery!=''){
|
if(cidadeQuery!=''){
|
||||||
carregando = true;
|
carregando = true;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
// buscarCPF();
|
|
||||||
buscarCadastro();
|
buscarCadastro();
|
||||||
}else{
|
}else{
|
||||||
showSnackBar(context, 'Selecione sua cidade', Colors.red);
|
showSnackBar(context, 'Selecione sua cidade', Colors.red);
|
||||||
@@ -87,23 +92,84 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
carregando = false;
|
carregando = false;
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}else{
|
}else{
|
||||||
Map map = json.decode(response.body);
|
mapAluno = json.decode(response.body);
|
||||||
print(map);
|
print(mapAluno);
|
||||||
print(map['CD_ALUNO']);
|
print(mapAluno!['CD_ALUNO']);
|
||||||
inserirDB(map);
|
// inserirDB(map);
|
||||||
|
if(tentativas <=3){
|
||||||
|
tentativas = tentativas + 1;
|
||||||
|
criarNumero();
|
||||||
|
}else{
|
||||||
|
showSnackBar(context, 'Excedeu suas tentativas, entre em contato com a escola', Colors.red);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inserirDB(Map map)async{
|
criarNumero(){
|
||||||
|
var random = Random();
|
||||||
|
nroSMS = (random.nextInt(9000) + 1000).toString();
|
||||||
|
apiSMS();
|
||||||
|
}
|
||||||
|
|
||||||
|
apiSMS()async{
|
||||||
|
final String apiUrl = 'https://api-rest.zenvia.com/services/send-sms';
|
||||||
|
final String authToken = '6nPV7rkTncLaugyoEBHQklHrvD5-GzDVMCeI';
|
||||||
|
final headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization':'Y2FicmV1dmEucmVzdDo0U0lmYktjUTgy',
|
||||||
|
'Cache-Control': 'no-cache'
|
||||||
|
};
|
||||||
|
|
||||||
|
final data = {
|
||||||
|
"sendSmsRequest": {
|
||||||
|
"from": "RKM EDUCA",
|
||||||
|
"to": "+5515996083456",
|
||||||
|
"msg": "Seu codigo de acesso : $nroSMS",
|
||||||
|
"flashSms": true,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
final response = await http.post(
|
||||||
|
Uri.parse(apiUrl),
|
||||||
|
headers: headers,
|
||||||
|
body: json.encode(data),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
print('SMS sent successfully');
|
||||||
|
print(response.body);
|
||||||
|
smsEnviado = true;
|
||||||
|
carregando = false;
|
||||||
|
setState(() {});
|
||||||
|
showSnackBar(context, 'Código SMS enviado com sucesso!', Colors.green);
|
||||||
|
} else {
|
||||||
|
print(response.body);
|
||||||
|
print(response.statusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
verificacaoSMS(){
|
||||||
|
if(inputCodigo.text == nroSMS){
|
||||||
|
smsEnviado = false;
|
||||||
|
carregando = true;
|
||||||
|
setState(() {});
|
||||||
|
showSnackBar(context, 'Acesso validado com sucesso!', Colors.green);
|
||||||
|
inserirDB();
|
||||||
|
}else{
|
||||||
|
showSnackBar(context, 'Código incorreto, tente novamente!', Colors.red);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inserirDB()async{
|
||||||
final url = '${widget.api}/inserirpais';
|
final url = '${widget.api}/inserirpais';
|
||||||
|
|
||||||
final response = await http.post(
|
final response = await http.post(
|
||||||
Uri.parse(url),
|
Uri.parse(url),
|
||||||
body:{
|
body:{
|
||||||
'CD_ALUNO' : map['CD_ALUNO'],
|
'CD_ALUNO' : mapAluno!['CD_ALUNO'],
|
||||||
'ALUNO': map['NO_ALUNO'],
|
'ALUNO': mapAluno!['NO_ALUNO'],
|
||||||
'CPF': inputCPF.text,
|
'CPF': inputCPF.text,
|
||||||
'NOME' : map['NO_PAI'],
|
'NOME' : mapAluno!['NO_PAI'],
|
||||||
'SENHA' : inputSenha.text,
|
'SENHA' : inputSenha.text,
|
||||||
'PARENTESCO' : 'PAI',
|
'PARENTESCO' : 'PAI',
|
||||||
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
||||||
@@ -157,7 +223,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
Container(
|
Container(
|
||||||
child: Image.asset("assets/images/logoEduca.png",width:Dimensoes.width * 0.4,height: Dimensoes.height * 0.12)
|
child: Image.asset("assets/images/logoEduca.png",width:Dimensoes.width * 0.4,height: Dimensoes.height * 0.12)
|
||||||
),
|
),
|
||||||
Container(
|
smsEnviado?Container():Container(
|
||||||
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||||
child: InputText(
|
child: InputText(
|
||||||
inputFormatters: [
|
inputFormatters: [
|
||||||
@@ -171,7 +237,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
colorBorder: PaletaCores.branco,
|
colorBorder: PaletaCores.branco,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
smsEnviado?Container():Container(
|
||||||
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||||
child: InputText(
|
child: InputText(
|
||||||
inputFormatters: [],
|
inputFormatters: [],
|
||||||
@@ -182,7 +248,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
colorBorder: PaletaCores.branco,
|
colorBorder: PaletaCores.branco,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
smsEnviado?Container():Container(
|
||||||
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||||
child: InputText(
|
child: InputText(
|
||||||
inputFormatters: [],
|
inputFormatters: [],
|
||||||
@@ -193,7 +259,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
colorBorder: PaletaCores.branco,
|
colorBorder: PaletaCores.branco,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Container(
|
smsEnviado?Container():Container(
|
||||||
width: Dimensoes.width*0.6,
|
width: Dimensoes.width*0.6,
|
||||||
child: DropdownButtonHideUnderline(
|
child: DropdownButtonHideUnderline(
|
||||||
child: DropdownButton(
|
child: DropdownButton(
|
||||||
@@ -219,7 +285,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 20,),
|
SizedBox(height: 20,),
|
||||||
ButtonCustom(
|
smsEnviado?Container():ButtonCustom(
|
||||||
widthCustom: 0.7,
|
widthCustom: 0.7,
|
||||||
heightCustom: 0.07,
|
heightCustom: 0.07,
|
||||||
text: "Cadastrar",
|
text: "Cadastrar",
|
||||||
@@ -229,6 +295,29 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
|||||||
colorBorder: PaletaCores.corPrimaria,
|
colorBorder: PaletaCores.corPrimaria,
|
||||||
onPressed: ()=>verificacao(),
|
onPressed: ()=>verificacao(),
|
||||||
),
|
),
|
||||||
|
smsEnviado?Container(
|
||||||
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||||
|
child: InputText(
|
||||||
|
inputFormatters: [
|
||||||
|
FilteringTextInputFormatter.digitsOnly,
|
||||||
|
],
|
||||||
|
textInputType: TextInputType.number,
|
||||||
|
controller: inputCodigo,
|
||||||
|
title: 'Código SMS',
|
||||||
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||||
|
colorBorder: PaletaCores.branco,
|
||||||
|
),
|
||||||
|
):Container(),
|
||||||
|
smsEnviado?ButtonCustom(
|
||||||
|
widthCustom: 0.7,
|
||||||
|
heightCustom: 0.07,
|
||||||
|
text: "Enviar",
|
||||||
|
fontsize: 14.0,
|
||||||
|
colorText: PaletaCores.branco,
|
||||||
|
colorButton: PaletaCores.corPrimaria,
|
||||||
|
colorBorder: PaletaCores.corPrimaria,
|
||||||
|
onPressed: ()=>verificacaoSMS(),
|
||||||
|
):Container(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
import 'package:brasil_fields/brasil_fields.dart';
|
import 'package:brasil_fields/brasil_fields.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user