301 lines
12 KiB
Dart
301 lines
12 KiB
Dart
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 '../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';
|
|
|
|
class ResponsibleRegisterScreen extends StatefulWidget {
|
|
AlunoModel alunoModel;
|
|
|
|
ResponsibleRegisterScreen({required 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();
|
|
|
|
salvarResponsavel() {
|
|
if(inputNome.text.isNotEmpty && inputNome.text.contains(' ')){
|
|
if(inputParentesco.text.isNotEmpty){
|
|
if(inputCpf.text.isNotEmpty && GetUtils.isCpf(inputCpf.text)){
|
|
if(inputSenha.text.isNotEmpty && inputSenha.text.length > 5){
|
|
if(editando && indice!=null){
|
|
responsaveis[indice!] = ResponsavelModel(
|
|
nomeAluno: widget.alunoModel.nome,
|
|
raAluno: widget.alunoModel.ra,
|
|
escola: widget.alunoModel.escola,
|
|
serie: widget.alunoModel.serie,
|
|
turma: widget.alunoModel.turma,
|
|
nomeResponsavel: inputNome.text,
|
|
parentesco: inputParentesco.text,
|
|
cpf: inputCpf.text,
|
|
senha: inputSenha.text,
|
|
dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now())
|
|
);
|
|
}else{
|
|
responsaveis.add(
|
|
ResponsavelModel(
|
|
nomeAluno: widget.alunoModel.nome.toUpperCase(),
|
|
raAluno: widget.alunoModel.ra.toUpperCase(),
|
|
escola: widget.alunoModel.escola.toUpperCase(),
|
|
serie: widget.alunoModel.serie.toUpperCase(),
|
|
turma: widget.alunoModel.turma.toUpperCase(),
|
|
nomeResponsavel: inputNome.text.toUpperCase(),
|
|
parentesco: inputParentesco.text.toUpperCase(),
|
|
cpf: inputCpf.text,
|
|
senha: inputSenha.text.toUpperCase(),
|
|
dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now())
|
|
)
|
|
);
|
|
}
|
|
editando?
|
|
showSnackBar(context, 'Responsável alterado!', Colors.green):
|
|
showSnackBar(context, 'Responsável adicionado!', Colors.green);
|
|
inputNome.clear();
|
|
inputParentesco.clear();
|
|
inputCpf.clear();
|
|
inputSenha.clear();
|
|
showRegister = false;
|
|
editando = false;
|
|
indice = null;
|
|
inputData.clear();
|
|
setState((){});
|
|
}else{
|
|
showSnackBar(context, 'Insira o uma senha com o mínimo de 6 caracteres', Colors.red);
|
|
}
|
|
}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);
|
|
}
|
|
}
|
|
|
|
@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,),
|
|
],
|
|
),
|
|
backgroundColor: PaletteColors.grey,
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(30.0),
|
|
child: Column(
|
|
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: '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: [],
|
|
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: [],
|
|
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(),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
width: width>900? width * 0.18:width*0.4,
|
|
child: InputText(
|
|
inputFormatters: [],
|
|
controller: inputSenha,
|
|
title: 'Senha',
|
|
width: width * 0.18,
|
|
colorBorder: PaletteColors.white,
|
|
),
|
|
),
|
|
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();
|
|
inputSenha.clear();
|
|
inputCpf.clear();
|
|
}),
|
|
text: 'Cancelar',
|
|
widthCustom: 0.1,
|
|
heightCustom: 0.05,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
colorButton: PaletteColors.primaryColor,
|
|
size: 15,
|
|
),
|
|
SizedBox(width: 50,),
|
|
ButtonCustom(
|
|
onPressed:()=>salvarResponsavel(),
|
|
text: 'Salvar',
|
|
widthCustom: 0.1,
|
|
heightCustom: 0.05,
|
|
colorText: Colors.white,
|
|
colorBorder: PaletteColors.green,
|
|
colorButton: PaletteColors.green,
|
|
size: 15,
|
|
)
|
|
],
|
|
)
|
|
],
|
|
),
|
|
),
|
|
),
|
|
):Container(),
|
|
showRegister?Container():Container(
|
|
alignment: Alignment.centerLeft,
|
|
width: width,
|
|
height: height*0.3,
|
|
child: ListView.separated(
|
|
itemCount: responsaveis.length,
|
|
separatorBuilder: (context,index){
|
|
return Divider();
|
|
},
|
|
itemBuilder: (context,index){
|
|
return DadosResponsaveisContainer(
|
|
responsavelModel: responsaveis[index],
|
|
onTapEdit: (){
|
|
showRegister = true;
|
|
editando = true;
|
|
indice = index;
|
|
inputNome.text = responsaveis[index].nomeResponsavel;
|
|
inputParentesco.text = responsaveis[index].parentesco;
|
|
inputCpf.text = responsaveis[index].cpf;
|
|
inputSenha.text = responsaveis[index].senha;
|
|
inputData.text = responsaveis[index].dataCadastro;
|
|
setState(() {});
|
|
},
|
|
onTapDelete: (){
|
|
responsaveis.removeAt(index);
|
|
setState(() {});
|
|
showSnackBar(context, 'Responsável deletado!', Colors.green);
|
|
},
|
|
);
|
|
}
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
);
|
|
}
|
|
}
|