ajuste do SMS
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:brasil_fields/brasil_fields.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -30,9 +31,14 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
final inputCPF = TextEditingController();
|
||||
final inputSenha = TextEditingController();
|
||||
final inputRepita = TextEditingController();
|
||||
final inputCodigo = TextEditingController();
|
||||
String? cidade;
|
||||
String cidadeQuery = '';
|
||||
bool carregando = false;
|
||||
int tentativas = 0;
|
||||
bool smsEnviado = false;
|
||||
String nroSMS = '';
|
||||
Map? mapAluno;
|
||||
|
||||
verificacao(){
|
||||
if(inputCPF.text.isNotEmpty){
|
||||
@@ -43,7 +49,6 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
if(cidadeQuery!=''){
|
||||
carregando = true;
|
||||
setState(() {});
|
||||
// buscarCPF();
|
||||
buscarCadastro();
|
||||
}else{
|
||||
showSnackBar(context, 'Selecione sua cidade', Colors.red);
|
||||
@@ -87,23 +92,84 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
carregando = false;
|
||||
setState(() {});
|
||||
}else{
|
||||
Map map = json.decode(response.body);
|
||||
print(map);
|
||||
print(map['CD_ALUNO']);
|
||||
inserirDB(map);
|
||||
mapAluno = json.decode(response.body);
|
||||
print(mapAluno);
|
||||
print(mapAluno!['CD_ALUNO']);
|
||||
// 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 response = await http.post(
|
||||
Uri.parse(url),
|
||||
body:{
|
||||
'CD_ALUNO' : map['CD_ALUNO'],
|
||||
'ALUNO': map['NO_ALUNO'],
|
||||
'CD_ALUNO' : mapAluno!['CD_ALUNO'],
|
||||
'ALUNO': mapAluno!['NO_ALUNO'],
|
||||
'CPF': inputCPF.text,
|
||||
'NOME' : map['NO_PAI'],
|
||||
'NOME' : mapAluno!['NO_PAI'],
|
||||
'SENHA' : inputSenha.text,
|
||||
'PARENTESCO' : 'PAI',
|
||||
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
||||
@@ -157,7 +223,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
Container(
|
||||
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,
|
||||
child: InputText(
|
||||
inputFormatters: [
|
||||
@@ -171,7 +237,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
colorBorder: PaletaCores.branco,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
smsEnviado?Container():Container(
|
||||
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||
child: InputText(
|
||||
inputFormatters: [],
|
||||
@@ -182,7 +248,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
colorBorder: PaletaCores.branco,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
smsEnviado?Container():Container(
|
||||
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
||||
child: InputText(
|
||||
inputFormatters: [],
|
||||
@@ -193,7 +259,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
colorBorder: PaletaCores.branco,
|
||||
),
|
||||
),
|
||||
Container(
|
||||
smsEnviado?Container():Container(
|
||||
width: Dimensoes.width*0.6,
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton(
|
||||
@@ -219,7 +285,7 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20,),
|
||||
ButtonCustom(
|
||||
smsEnviado?Container():ButtonCustom(
|
||||
widthCustom: 0.7,
|
||||
heightCustom: 0.07,
|
||||
text: "Cadastrar",
|
||||
@@ -229,6 +295,29 @@ class _TelaCadastroState extends State<TelaCadastro> {
|
||||
colorBorder: PaletaCores.corPrimaria,
|
||||
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:math';
|
||||
import 'package:brasil_fields/brasil_fields.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
Reference in New Issue
Block a user