238 lines
7.9 KiB
Dart
238 lines
7.9 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:brasil_fields/brasil_fields.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:get/get_utils/src/get_utils/get_utils.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:rkm_educa_app/componentes/text_custom.dart';
|
|
import 'package:rkm_educa_app/telas/tela_login.dart';
|
|
import '../componentes/appbar_custom.dart';
|
|
import '../componentes/buttom_custom.dart';
|
|
import '../componentes/input_text.dart';
|
|
import '../componentes/snackBars.dart';
|
|
import '../utils/cores.dart';
|
|
import '../utils/dimensoes.dart';
|
|
import '../utils/fixos.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class TelaCadastro extends StatefulWidget {
|
|
String api;
|
|
|
|
TelaCadastro({required this.api});
|
|
|
|
@override
|
|
State<TelaCadastro> createState() => _TelaCadastroState();
|
|
}
|
|
|
|
class _TelaCadastroState extends State<TelaCadastro> {
|
|
|
|
final inputCPF = TextEditingController();
|
|
final inputSenha = TextEditingController();
|
|
final inputRepita = TextEditingController();
|
|
String? cidade;
|
|
String cidadeQuery = '';
|
|
bool carregando = false;
|
|
|
|
verificacao(){
|
|
if(inputCPF.text.isNotEmpty){
|
|
if(inputSenha.text.isNotEmpty){
|
|
if(inputRepita.text.isNotEmpty){
|
|
if(inputSenha.text == inputRepita.text){
|
|
if(GetUtils.isCpf(inputCPF.text)){
|
|
if(cidadeQuery!=''){
|
|
carregando = true;
|
|
setState(() {});
|
|
// buscarCPF();
|
|
buscarCadastro();
|
|
}else{
|
|
showSnackBar(context, 'Selecione sua cidade', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'CPF Inválido', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Senhas não são idênticas', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Repita sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha sua senha', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Preencha seu CPF', Colors.red);
|
|
}
|
|
}
|
|
|
|
buscarCadastro()async{
|
|
final url = '${widget.api}/buscarcadastrocpf?CPF=${inputCPF.text}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
if(response.body == 'false'){
|
|
buscarCPF();
|
|
}else{
|
|
carregando = false;
|
|
setState(() {});
|
|
showSnackBar(context, 'CPF já está cadastrado!', Colors.red);
|
|
}
|
|
}
|
|
|
|
buscarCPF()async{
|
|
final url = '${widget.api}/buscarcpf?CPF=${inputCPF.text.replaceAll('.','').replaceAll('-', '')}&CIDADE=${cidadeQuery.toUpperCase()}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
if(response.body == 'false'){
|
|
showSnackBar(context, 'CPF não encontrado entre em contato com a escola!', Colors.red);
|
|
carregando = false;
|
|
setState(() {});
|
|
}else{
|
|
Map map = json.decode(response.body);
|
|
print(map);
|
|
print(map['CD_ALUNO']);
|
|
inserirDB(map);
|
|
}
|
|
}
|
|
|
|
inserirDB(Map map)async{
|
|
final url = '${widget.api}/inserirpais';
|
|
|
|
final response = await http.post(
|
|
Uri.parse(url),
|
|
body:{
|
|
'CD_ALUNO' : map['CD_ALUNO'],
|
|
'ALUNO': map['NO_ALUNO'],
|
|
'CPF': inputCPF.text,
|
|
'NOME' : map['NO_PAI'],
|
|
'SENHA' : inputSenha.text,
|
|
'PARENTESCO' : 'PAI',
|
|
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
|
'CONDICAO' : 'NOVO',
|
|
'CIDADE' : cidadeQuery.toUpperCase()
|
|
}
|
|
);
|
|
if(response.body == 'cadastrado com sucesso' || response.body == 'editado com sucesso'){
|
|
showSnackBar(context, 'Cadastro realizado com sucesso!', Colors.green);
|
|
|
|
inputCPF.clear();
|
|
inputSenha.clear();
|
|
inputRepita.clear();
|
|
carregando = false;
|
|
cidade =null;
|
|
setState((){});
|
|
Navigator.push(context, MaterialPageRoute(builder: (context)=>TelaLogin()));
|
|
|
|
}else{
|
|
carregando = false;
|
|
setState((){});
|
|
showSnackBar(context, 'Erro ao fazer o registro, entre em contato com a escola', Colors.red);
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
List cidades= [];
|
|
for(int i=0;Fixos().listCidades.length>i;i++){
|
|
cidades.add(Fixos().listCidades[i].cidade);
|
|
}
|
|
|
|
return Scaffold(
|
|
appBar: AppBarCustom().appbar(context, 'CADASTRO'),
|
|
body: Container(
|
|
padding: EdgeInsets.all(Dimensoes.width*0.15),
|
|
width: Dimensoes.width,
|
|
height: Dimensoes.height,
|
|
alignment: Alignment.center,
|
|
child: carregando?Center(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
TextCustom(text: 'VALIDANDO DADOS ...\n AGUARDE ALGUNS SEGUNDOS !',maxLines: 2,textAlign: TextAlign.center,),
|
|
SizedBox(height: 30,),
|
|
CircularProgressIndicator(color: PaletaCores.corPrimaria,)
|
|
],
|
|
),
|
|
):ListView(
|
|
children: [
|
|
Container(
|
|
child: Image.asset("assets/images/logoEduca.png",width:Dimensoes.width * 0.4,height: Dimensoes.height * 0.12)
|
|
),
|
|
Container(
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
child: InputText(
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
CpfInputFormatter(),
|
|
],
|
|
textInputType: TextInputType.number,
|
|
controller: inputCPF,
|
|
title: 'CPF',
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
colorBorder: PaletaCores.branco,
|
|
),
|
|
),
|
|
Container(
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
obscure: true,
|
|
controller: inputSenha,
|
|
title: 'Senha',
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
colorBorder: PaletaCores.branco,
|
|
),
|
|
),
|
|
Container(
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
obscure: true,
|
|
controller: inputRepita,
|
|
title: 'Repetir Senha',
|
|
width: Dimensoes.width>900? Dimensoes.width * 0.18:Dimensoes.width*0.7,
|
|
colorBorder: PaletaCores.branco,
|
|
),
|
|
),
|
|
Container(
|
|
width: Dimensoes.width*0.6,
|
|
child: DropdownButtonHideUnderline(
|
|
child: DropdownButton(
|
|
hint: TextCustom(text: 'Cidade'),
|
|
value: cidade,
|
|
items: Fixos().listCidades.map((value) => DropdownMenuItem(
|
|
value: value.cidade,
|
|
child: TextCustom(
|
|
text: value.cidade,
|
|
color: Colors.black54,
|
|
),
|
|
)
|
|
).toList(),
|
|
onChanged: (value){
|
|
setState(() {
|
|
cidade = value!;
|
|
print(cidades.indexOf(cidade!));
|
|
cidadeQuery = Fixos().listCidades[cidades.indexOf(cidade!)].cidadeQuery;
|
|
print(cidadeQuery);
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 20,),
|
|
ButtonCustom(
|
|
widthCustom: 0.7,
|
|
heightCustom: 0.07,
|
|
text: "Cadastrar",
|
|
fontsize: 14.0,
|
|
colorText: PaletaCores.branco,
|
|
colorButton: PaletaCores.corPrimaria,
|
|
colorBorder: PaletaCores.corPrimaria,
|
|
onPressed: ()=>verificacao(),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|