596 lines
24 KiB
Dart
596 lines
24 KiB
Dart
import 'dart:convert';
|
|
import 'package:brasil_fields/brasil_fields.dart';
|
|
import 'package:educa_controle_acesso/models/aluno_model.dart';
|
|
import 'package:educa_controle_acesso/models/responsavel_model.dart';
|
|
import 'package:educa_controle_acesso/widgets/dados_responsaveis_container.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:intl/intl.dart';
|
|
import '../controllers/main_controllers.dart';
|
|
import '../utils/colors.dart';
|
|
import '../widgets/buttom_custom.dart';
|
|
import '../widgets/caixa_texto_container.dart';
|
|
import '../widgets/input_text.dart';
|
|
import '../widgets/snackBars.dart';
|
|
import '../widgets/text_custom.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
class ResponsibleRegisterScreen extends StatefulWidget {
|
|
AlunoModel alunoModel;
|
|
|
|
ResponsibleRegisterScreen(this.alunoModel);
|
|
|
|
@override
|
|
State<ResponsibleRegisterScreen> createState() => _ResponsibleRegisterScreenState();
|
|
}
|
|
|
|
class _ResponsibleRegisterScreenState extends State<ResponsibleRegisterScreen> {
|
|
|
|
List <ResponsavelModel> responsaveis = [];
|
|
bool showRegister = false;
|
|
bool editando = false;
|
|
int? indice;
|
|
var inputNome = TextEditingController();
|
|
var inputParentesco = TextEditingController();
|
|
var inputCpf = TextEditingController();
|
|
// var inputSenha = TextEditingController();
|
|
var inputData = TextEditingController();
|
|
bool carregando = true;
|
|
List dados = [];
|
|
|
|
bloquearResponsavel(int index,String CONDICAO)async{
|
|
final url = '${widget.alunoModel.URL}/inserirpais';
|
|
|
|
final response = await http.post(
|
|
Uri.parse(url),
|
|
body:{
|
|
'CD_ALUNO' : widget.alunoModel.dados['CD_ALUNO'],
|
|
'ALUNO': widget.alunoModel.dados['NO_ALUNO'],
|
|
'CPF': responsaveis[index].CPF,
|
|
'NOME' : responsaveis[index].NOME,
|
|
'SENHA' : responsaveis[index].SENHA,
|
|
'PARENTESCO' : responsaveis[index].PARENTESCO,
|
|
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
|
'CONDICAO' : CONDICAO=='BLOQUEADO'?'EDITADO':'BLOQUEADO',
|
|
'CIDADE' : widget.alunoModel.cidade
|
|
}
|
|
);
|
|
if(response.body == 'cadastrado com sucesso' || response.body == 'editado com sucesso'){
|
|
CONDICAO=='BLOQUEADO'
|
|
?MainControllers().salvarLog('LIBERADO O ACESSO DO USUARIO ${responsaveis[index].CPF}',dados)
|
|
:MainControllers().salvarLog('BLOQUEADO O ACESSO DO USUARIO ${responsaveis[index].CPF}',dados);
|
|
editando?
|
|
showSnackBar(context, 'Responsável alterado!', Colors.green):
|
|
showSnackBar(context, 'Responsável adicionado!', Colors.green);
|
|
|
|
inputNome.clear();
|
|
inputParentesco.clear();
|
|
inputCpf.clear();
|
|
showRegister = false;
|
|
editando = false;
|
|
indice = null;
|
|
inputData.clear();
|
|
paisBanco();
|
|
setState((){});
|
|
|
|
}else{
|
|
carregando = false;
|
|
setState((){});
|
|
showSnackBar(context, 'Erro ao fazer o registro, verifique os dados do usuário', Colors.red);
|
|
}
|
|
}
|
|
|
|
inserirDB(int index)async{
|
|
final url = '${widget.alunoModel.URL}/inserirpais';
|
|
|
|
final response = await http.post(
|
|
Uri.parse(url),
|
|
body:{
|
|
'CD_ALUNO' : widget.alunoModel.dados['CD_ALUNO'],
|
|
'ALUNO': widget.alunoModel.dados['NO_ALUNO'],
|
|
'CPF': responsaveis[index].CPF,
|
|
'NOME' : responsaveis[index].NOME,
|
|
'SENHA' : editando?responsaveis[index].SENHA: responsaveis[index].CPF.replaceAll('-','').replaceAll('.', ''),
|
|
'PARENTESCO' : responsaveis[index].PARENTESCO,
|
|
'DATA_CADASTRO' : DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
|
'CONDICAO' : editando?'EDITADO':'NOVO',
|
|
'CIDADE' : widget.alunoModel.cidade
|
|
}
|
|
);
|
|
if(response.body == 'cadastrado com sucesso' || response.body == 'editado com sucesso'){
|
|
editando?
|
|
showSnackBar(context, 'Responsável alterado!', Colors.green):
|
|
showSnackBar(context, 'Responsável adicionado!', Colors.green);
|
|
|
|
inputNome.clear();
|
|
inputParentesco.clear();
|
|
inputCpf.clear();
|
|
showRegister = false;
|
|
editando = false;
|
|
indice = null;
|
|
inputData.clear();
|
|
paisBanco();
|
|
setState((){});
|
|
|
|
}else{
|
|
carregando = false;
|
|
setState((){});
|
|
showSnackBar(context, 'Erro ao fazer o registro, verifique os dados do usuário', Colors.red);
|
|
}
|
|
}
|
|
|
|
salvarResponsavel() {
|
|
if(inputNome.text.isNotEmpty && inputNome.text.contains(' ')){
|
|
if(inputParentesco.text.isNotEmpty){
|
|
if(inputCpf.text.isNotEmpty && GetUtils.isCpf(inputCpf.text)){
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
inserirDB(indice!);
|
|
}else{
|
|
showSnackBar(context, 'CPF inválido', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Insira o parentesco do responsável', Colors.red);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Insira o nome completo do responsável', Colors.red);
|
|
}
|
|
}
|
|
|
|
carregaPais(var map){
|
|
responsaveis.clear();
|
|
List list = map;
|
|
if(widget.alunoModel.dados['NO_PAI']!=''){
|
|
responsaveis.add(
|
|
ResponsavelModel(
|
|
CD_ALUNO: widget.alunoModel.dados['CD_ALUNO'],
|
|
NOME: widget.alunoModel.dados['NO_PAI'],
|
|
PARENTESCO: 'PAI',
|
|
CPF: '',
|
|
SENHA: '',
|
|
DATA_CADASTRO: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
|
CONDICAO: ''
|
|
)
|
|
);
|
|
}
|
|
if(widget.alunoModel.dados['NO_MAE']!=''){
|
|
responsaveis.add(
|
|
ResponsavelModel(
|
|
CD_ALUNO: widget.alunoModel.dados['CD_ALUNO'],
|
|
NOME: widget.alunoModel.dados['NO_MAE'],
|
|
PARENTESCO: 'MAE',
|
|
CPF: '',
|
|
SENHA: '',
|
|
DATA_CADASTRO: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now()),
|
|
CONDICAO: ''
|
|
)
|
|
);
|
|
}
|
|
//fazer if comparando os parentescos para não duplicar e não falta pais
|
|
for(int i = 0; list.length>i;i++){
|
|
if(list[i]['PARENTESCO'].toString().toUpperCase()=='PAI'){
|
|
responsaveis[0]=
|
|
ResponsavelModel(
|
|
CD_ALUNO: list[i]['CD_ALUNO']??'',
|
|
NOME: list[i]['NOME']??'',
|
|
PARENTESCO: list[i]['PARENTESCO']??'',
|
|
CPF: list[i]['CPF']??'',
|
|
SENHA: list[i]['SENHA']??'',
|
|
DATA_CADASTRO: list[i]['DATA_CADASTRO']??'',
|
|
CONDICAO: list[i]['CONDICAO']??''
|
|
);
|
|
}else if (list[i]['PARENTESCO'].toString().toUpperCase()=='MAE' ||list[i]['PARENTESCO'].toString().toUpperCase()=='MÃE'){
|
|
responsaveis[1]=
|
|
ResponsavelModel(
|
|
CD_ALUNO: list[i]['CD_ALUNO']??'',
|
|
NOME: list[i]['NOME'].toString().toUpperCase()??'',
|
|
PARENTESCO: list[i]['PARENTESCO'].toString().toUpperCase()??'',
|
|
CPF: list[i]['CPF'].toString().toUpperCase()??'',
|
|
SENHA: list[i]['SENHA'].toString().toUpperCase()??'',
|
|
DATA_CADASTRO: list[i]['DATA_CADASTRO'].toString().toUpperCase()??'',
|
|
CONDICAO: list[i]['CONDICAO']??''
|
|
);
|
|
}else{
|
|
responsaveis.add(
|
|
ResponsavelModel(
|
|
CD_ALUNO: list[i]['CD_ALUNO']??'',
|
|
NOME: list[i]['NOME'].toString().toUpperCase()??'',
|
|
PARENTESCO: list[i]['PARENTESCO'].toString().toUpperCase()??'',
|
|
CPF: list[i]['CPF'].toString().toUpperCase()??'',
|
|
SENHA: list[i]['SENHA'].toString().toUpperCase()??'',
|
|
DATA_CADASTRO: list[i]['DATA_CADASTRO'].toString().toUpperCase()??'',
|
|
CONDICAO: list[i]['CONDICAO']??''
|
|
)
|
|
);
|
|
}
|
|
}
|
|
carregando = false;
|
|
setState(() {});
|
|
dadosLog();
|
|
}
|
|
dadosLog(){
|
|
dados = [
|
|
widget.alunoModel.cidade,
|
|
widget.alunoModel.login,
|
|
widget.alunoModel.URL,
|
|
'',
|
|
widget.alunoModel.CD_USUARIO,
|
|
widget.alunoModel.USER_USUARIO
|
|
];
|
|
}
|
|
|
|
paisBanco()async{
|
|
final url = '${widget.alunoModel.URL}/pais?CD_ALUNO=${widget.alunoModel.dados['CD_ALUNO']}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
// print(map);
|
|
carregaPais(map);
|
|
}
|
|
|
|
excluirResponsavel(int index, String cpf)async{
|
|
Navigator.pop(context);
|
|
setState(() {
|
|
carregando = true;
|
|
});
|
|
final url = '${widget.alunoModel.URL}/deleta?CPF=$cpf';
|
|
// print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
// print(response.body);
|
|
if(response.body == 'deletado com sucesso'){
|
|
MainControllers().salvarLog('DELETADO OS DADOS DO USUARIO ${responsaveis[index].CPF}',dados);
|
|
responsaveis[index].CPF = '';
|
|
responsaveis[index].SENHA='';
|
|
responsaveis[index].CONDICAO='';
|
|
responsaveis[index].CD_ALUNO='';
|
|
carregando = false;
|
|
setState(() {});
|
|
showSnackBar(context, 'Responsável deletado!', Colors.green);
|
|
}
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
paisBanco();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
double width = MediaQuery.of(context).size.width;
|
|
double height = MediaQuery.of(context).size.height;
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
title: Row(
|
|
children: [
|
|
Container(
|
|
child: Image.asset("assets/images/logoEduca.png",width:width * 0.08,height: height * 0.12)
|
|
),
|
|
TextCustom(text: '- Cadastrar Responsável',color: Colors.white,),
|
|
Spacer(),
|
|
Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
TextCustom(text: widget.alunoModel.cidade,color: Colors.white,),
|
|
TextCustom(text:widget.alunoModel.login.toUpperCase(),color: Colors.white,),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
backgroundColor: PaletteColors.grey,
|
|
),
|
|
body: carregando?Center(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(),
|
|
SizedBox(width: 20,),
|
|
TextCustom(text: 'AGUARDE ...')
|
|
],
|
|
),
|
|
):Container(
|
|
alignment: Alignment.topLeft,
|
|
padding: const EdgeInsets.all(30.0),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: width,
|
|
alignment: Alignment.centerLeft,
|
|
child: Container(
|
|
alignment: Alignment.centerLeft,
|
|
width: width*0.7,
|
|
padding: EdgeInsets.all(10),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: PaletteColors.grey,width: 2)
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
CaixaTextoContainer(texto: widget.alunoModel.nome.toUpperCase(),titulo: 'Estudante'),
|
|
CaixaTextoContainer(texto: widget.alunoModel.serie.toUpperCase()+'°',titulo: 'Série',),
|
|
CaixaTextoContainer(texto: widget.alunoModel.turma.toUpperCase(),titulo: 'Turma',),
|
|
],
|
|
),
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
CaixaTextoContainer(texto: widget.alunoModel.ra.toUpperCase(),titulo: 'RA'),
|
|
CaixaTextoContainer(texto: widget.alunoModel.escola.toUpperCase(),titulo: 'Escola',),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
SizedBox(height: 50,),
|
|
Row(
|
|
children: [
|
|
TextCustom(text: 'Responsáveis Cadastrados:'),
|
|
// IconButton(
|
|
// icon: Icon(Icons.add_circle,color: PaletteColors.primaryColor),
|
|
// onPressed: ()=>setState(()=>showRegister = true),
|
|
// )
|
|
],
|
|
),
|
|
showRegister?Container(
|
|
alignment: Alignment.center,
|
|
padding: EdgeInsets.symmetric(horizontal: width*0.35),
|
|
width: width,
|
|
child: Card(
|
|
elevation: 10,
|
|
child: Padding(
|
|
padding: EdgeInsets.only(bottom: 20),
|
|
child: Column(
|
|
children: [
|
|
Container(
|
|
width: width*0.30,
|
|
padding: EdgeInsets.all(10),
|
|
color: Colors.black54,
|
|
child: TextCustom(
|
|
text: editando?'Editar responsável':'Novo responsável',
|
|
color: Colors.white,
|
|
textAlign: TextAlign.center,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 15.0),
|
|
child: TextCustom(text: 'Prencha os campos todos os campos para adicionar.'),
|
|
),
|
|
Container(
|
|
width: width>900? width * 0.18:width*0.4,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
enable: false,
|
|
controller: inputNome,
|
|
title: 'Nome Completo',
|
|
width: width * 0.18,
|
|
colorBorder: PaletteColors.white,
|
|
),
|
|
),
|
|
Container(
|
|
width: width>900? width * 0.18:width*0.4,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
enable: false,
|
|
controller: inputParentesco,
|
|
title: 'Parentesco',
|
|
width: width * 0.18,
|
|
colorBorder: PaletteColors.white,
|
|
),
|
|
),
|
|
Container(
|
|
width: width>900? width * 0.18:width*0.4,
|
|
child: InputText(
|
|
controller: inputCpf,
|
|
title: 'CPF',
|
|
width: width * 0.18,
|
|
colorBorder: PaletteColors.white,
|
|
inputFormatters: [
|
|
FilteringTextInputFormatter.digitsOnly,
|
|
CpfInputFormatter(),
|
|
],
|
|
),
|
|
),
|
|
editando?Container(
|
|
width: width>900? width * 0.18:width*0.4,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
controller: inputData,
|
|
title: 'Data de Cadastro',
|
|
width: width * 0.18,
|
|
colorBorder: PaletteColors.white,
|
|
enable: false,
|
|
),
|
|
):Container(),
|
|
SizedBox(height: 50,),
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
ButtonCustom(
|
|
onPressed:()=>setState((){
|
|
showRegister = false;
|
|
editando = false;
|
|
indice = null;
|
|
inputData.clear();
|
|
inputNome.clear();
|
|
inputParentesco.clear();
|
|
inputCpf.clear();
|
|
}),
|
|
text: 'Cancelar',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
colorButton: PaletteColors.primaryColor,
|
|
fontSize: 15,
|
|
),
|
|
SizedBox(width: 50,),
|
|
ButtonCustom(
|
|
onPressed:(){
|
|
responsaveis[indice!].CPF = inputCpf.text;
|
|
salvarResponsavel();
|
|
},
|
|
text: 'Salvar',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.green,
|
|
colorButton: PaletteColors.green,
|
|
fontSize: 15,
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
):Container(),
|
|
showRegister?Container():Container(
|
|
alignment: Alignment.centerLeft,
|
|
width: width,
|
|
height: height*0.4,
|
|
child: ListView.separated(
|
|
itemCount: responsaveis.length,
|
|
separatorBuilder: (context,index){
|
|
return Divider();
|
|
},
|
|
itemBuilder: (context,index){
|
|
return DadosResponsaveisContainer(
|
|
responsavelModel: responsaveis[index],
|
|
onTapEdit: (){
|
|
showRegister = true;
|
|
|
|
print(responsaveis[index].CONDICAO);
|
|
|
|
if(responsaveis[index].CONDICAO == 'NOVO' || responsaveis[index].CONDICAO == 'EDITADO'){
|
|
editando = true;
|
|
}
|
|
indice = index;
|
|
inputNome.text = responsaveis[index].NOME;
|
|
inputParentesco.text = responsaveis[index].PARENTESCO;
|
|
inputCpf.text = responsaveis[index].CPF;
|
|
inputData.text = responsaveis[index].DATA_CADASTRO;
|
|
setState(() {});
|
|
},
|
|
onTapDelete: (){
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context){
|
|
return AlertDialog(
|
|
title: TextCustom(text: 'Excluir Responsável'),
|
|
content: TextCustom(text:'Deseja realmente excluir esse responsável?',),
|
|
actions: [
|
|
ButtonCustom(
|
|
onPressed:()=>Navigator.pop(context),
|
|
text: 'NÃO',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.bgColor,
|
|
colorButton: PaletteColors.bgColor,
|
|
fontSize: 15,
|
|
),
|
|
ButtonCustom(
|
|
onPressed:()=>excluirResponsavel(index, responsaveis[index].CPF),
|
|
text: 'SIM',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
colorButton: PaletteColors.primaryColor,
|
|
fontSize: 15,
|
|
),
|
|
],
|
|
);
|
|
});
|
|
},
|
|
resetarSenha: (){
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context){
|
|
return AlertDialog(
|
|
title: TextCustom(text: 'Resetar senha'),
|
|
content: TextCustom(text:'Deseja realmente resetar a senha desse responsável?',),
|
|
actions: [
|
|
ButtonCustom(
|
|
onPressed:()=>Navigator.pop(context),
|
|
text: 'NÃO',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.bgColor,
|
|
colorButton: PaletteColors.bgColor,
|
|
fontSize: 15,
|
|
),
|
|
ButtonCustom(
|
|
onPressed:(){
|
|
Navigator.pop(context);
|
|
editando = true;
|
|
responsaveis[index].SENHA = responsaveis[index].CPF.toString().replaceAll('-', '').replaceAll('.', '');
|
|
carregando = true;
|
|
setState(() {});
|
|
inserirDB(index);
|
|
},
|
|
text: 'SIM',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
colorButton: PaletteColors.primaryColor,
|
|
fontSize: 15,
|
|
),
|
|
],
|
|
);
|
|
});
|
|
},
|
|
bloquearSenha: (){
|
|
showDialog(
|
|
context: context,
|
|
builder: (BuildContext context){
|
|
return AlertDialog(
|
|
title: TextCustom(text: responsaveis[index].CONDICAO=='BLOQUEADO'?'Desbloquear':'Bloquear'),
|
|
content: TextCustom(text:responsaveis[index].CONDICAO=='BLOQUEADO'
|
|
?'Deseja realmente desbloquear esse responsável'
|
|
:'Deseja realmente bloquear esse responsável?',),
|
|
actions: [
|
|
ButtonCustom(
|
|
onPressed:()=>Navigator.pop(context),
|
|
text: 'NÃO',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.bgColor,
|
|
colorButton: PaletteColors.bgColor,
|
|
fontSize: 15,
|
|
),
|
|
ButtonCustom(
|
|
onPressed:(){
|
|
Navigator.pop(context);
|
|
editando = true;
|
|
carregando = true;
|
|
setState(() {});
|
|
bloquearResponsavel(index,responsaveis[index].CONDICAO);
|
|
},
|
|
text: 'SIM',
|
|
widthCustom: 0.1,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
colorButton: PaletteColors.primaryColor,
|
|
fontSize: 15,
|
|
),
|
|
],
|
|
);
|
|
});
|
|
},
|
|
);
|
|
}
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|