ajustes da pesquisa e conexão com a api

This commit is contained in:
Reginaldo
2023-06-16 17:15:15 -03:00
parent ffde39e0f5
commit 58614a7756
3 changed files with 131 additions and 32 deletions

View File

@@ -20,7 +20,7 @@ class HomeScreen extends StatefulWidget {
class _HomeScreenState extends State<HomeScreen> {
var controllerPesquisa = TextEditingController();
var inputPesquisa = TextEditingController();
List<AlunoModel> alunos = [];
List resultadoPesquisa = [];
bool filtroEstudante = false;
@@ -29,11 +29,15 @@ class _HomeScreenState extends State<HomeScreen> {
bool filtroSerie = false;
bool filtroTurma = false;
bool filtroEscola = false;
bool buscandoDados = true;
bool buscandoDados = false;
carregarAlunos()async{
final url = 'http://localhost:8000/aluno?NR_LOGRADOURO=715';
print(url);
resultadoPesquisa.clear();
alunos.clear();
String q = inputPesquisa.text.replaceAll(' ', '%20').toUpperCase();
// print(q);
final url = 'http://localhost:8000/aluno?NOME=$q';
// print(url);
final response = await http.get(Uri.parse(url));
var map = json.decode(response.body);
if(map==null){
@@ -44,40 +48,45 @@ class _HomeScreenState extends State<HomeScreen> {
}else{
List list = map;
print(list);
for(int i =0; list.length>i;i++){
String data = list[i]['DT_NASCIMENTO']??'';
String dia = '00';
String mes = '00';
String ano = '0000';
if(data!=''){
dia = data.substring(6,8);
mes = data.substring(4,6);
ano = data.substring(0,4);
if(list.length != 0){
for(int i =0; list.length>i;i++){
String data = list[i]['DT_NASCIMENTO']??'';
String dia = '00';
String mes = '00';
String ano = '0000';
if(data!=''){
dia = data.substring(6,8);
mes = data.substring(4,6);
ano = data.substring(0,4);
}
alunos.add(AlunoModel(nome: list[i]['NO_ALUNO']??'', data_nasc: '${dia}/${mes}/${ano}', ra: list[i]['NR_RA']??'', escola: 'escola', serie: 'serie', turma: 'turma',dados: list[i]));
resultadoPesquisa.add(alunos[i]);
}
alunos.add(AlunoModel(nome: list[i]['NO_ALUNO']??'', data_nasc: '${dia}/${mes}/${ano}', ra: list[i]['NR_RA']??'', escola: 'escola', serie: 'serie', turma: 'turma',dados: list[i]));
}else{
showSnackBar(context, 'Aluno(a) não localizado', Colors.red);
}
setState(() {
buscandoDados = false;
});
pesquisarAluno();
// pesquisarAluno();
}
}
pesquisa(){
pesquisarAluno();
}
// pesquisa(){
// pesquisarAluno();
// }
pesquisarAluno()async{
resultadoPesquisa =[];
if(controllerPesquisa.text.isNotEmpty){
if(inputPesquisa.text.isNotEmpty){
for (int i =0;alunos.length>i;i++) {
String nome = alunos[i].nome.toUpperCase();
String data = alunos[i].data_nasc.toUpperCase();
String ra = alunos[i].ra.toUpperCase();
if(nome.contains(controllerPesquisa.text.toUpperCase()) ||
data.contains(controllerPesquisa.text.toUpperCase()) ||
ra.contains(controllerPesquisa.text.toUpperCase())
if(nome.contains(inputPesquisa.text.toUpperCase()) ||
data.contains(inputPesquisa.text.toUpperCase()) ||
ra.contains(inputPesquisa.text.toUpperCase())
){
if(resultadoPesquisa.length<10){
resultadoPesquisa.add(alunos[i]);
@@ -101,8 +110,7 @@ class _HomeScreenState extends State<HomeScreen> {
@override
void initState() {
super.initState();
carregarAlunos();
controllerPesquisa.addListener(pesquisa);
// inputPesquisa.addListener(pesquisa);
}
@override
@@ -143,13 +151,32 @@ class _HomeScreenState extends State<HomeScreen> {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
InputText(
hint: 'Pesquisar por estudante, RA ou data de nascimento'.toUpperCase(),
controller: controllerPesquisa,
hint: 'Pesquisar por nome do aluno(a)'.toUpperCase(),
controller: inputPesquisa,
width: width*0.25,
inputFormatters: [],
fontSize: 12,
colorBackground: Colors.white,
),
ButtonCustom(
widthCustom: 0.05,
heightCustom: 0.063,
text: "PESQUISAR",
size: 10.0,
colorText: PaletteColors.white,
colorButton: PaletteColors.green,
colorBorder: PaletteColors.green,
onPressed: (){
if(inputPesquisa.text.isNotEmpty){
setState(() {
buscandoDados = true;
});
carregarAlunos();
}else{
showSnackBar(context, 'Digite alguma informação para pesquisar', Colors.red);
}
},
),
ButtonCustom(
widthCustom: 0.05,
heightCustom: 0.063,
@@ -158,7 +185,11 @@ class _HomeScreenState extends State<HomeScreen> {
colorText: PaletteColors.white,
colorButton: PaletteColors.primaryColor,
colorBorder: PaletteColors.primaryColor,
onPressed: ()=>setState(()=>controllerPesquisa.clear()),
onPressed: ()=>setState((){
inputPesquisa.clear();
resultadoPesquisa.clear();
alunos.clear();
}),
)
],
)

View File

@@ -20,8 +20,10 @@ class _LoginScreenState extends State<LoginScreen> {
//MMATOS LOGIN IGUAL A SENHA
//AMENEZES LOGIN DIFERENTE DA SENHA
//SENHAS CRIPTOGRAFADAS PORQUE FORMA ALTERADAS, SENHAS NOVAS USUÁRIO E SENHA SÃO IGUAIS
final inputLogin = TextEditingController(text: 'mmatos');
final inputSenha = TextEditingController(text: 'mmatos');
// final inputLogin = TextEditingController(text: 'mmatos');
final inputLogin = TextEditingController(text: 'admin');
final inputSenha = TextEditingController(text: 'rkm12345');
// final inputSenha = TextEditingController(text: 'mmatos');
bool loading = false;
verificacao(){
@@ -41,10 +43,10 @@ class _LoginScreenState extends State<LoginScreen> {
conectAPI()async{
final url = 'http://localhost:8000/login?NO_USERNAME=${inputLogin.text.toUpperCase()}';
print(url);
// print(url);
final response = await http.get(Uri.parse(url));
var map = json.decode(response.body);
print(map);
// print(map);
if(map==false){
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red);
}else{
@@ -59,7 +61,7 @@ class _LoginScreenState extends State<LoginScreen> {
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red);
}
}else{
print(MainControllers().encrypt(inputSenha.text,map['SENHA']));
// print(MainControllers().encrypt(inputSenha.text,map['SENHA']));
if(MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']){
showSnackBar(context, 'Acesso validado', Colors.green);
Navigator.push(
@@ -77,6 +79,20 @@ class _LoginScreenState extends State<LoginScreen> {
});
}
paisBanco()async{
final url = 'http://localhost:8000/pais';
// print(url);
final response = await http.get(Uri.parse(url));
var map = json.decode(response.body);
print(map);
}
@override
void initState() {
super.initState();
paisBanco();
}
@override
Widget build(BuildContext context) {
double height = MediaQuery.of(context).size.height;

View File

@@ -1,3 +1,5 @@
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';
@@ -12,6 +14,7 @@ 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;
@@ -94,6 +97,55 @@ class _ResponsibleRegisterScreenState extends State<ResponsibleRegisterScreen> {
}
}
carregaPais(){
if(widget.alunoModel.dados['NO_PAI']!=''){
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: widget.alunoModel.dados['NO_PAI'],
parentesco: 'PAI',
cpf: '',
senha: '',
dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now())
)
);
}
if(widget.alunoModel.dados['NO_MAE']!=''){
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: widget.alunoModel.dados['NO_MAE'],
parentesco: 'MAE',
cpf: '',
senha: '',
dataCadastro: DateFormat('dd/MM/yyyy HH:mm').format(DateTime.now())
)
);
}
}
paisBanco()async{
final url = 'http://localhost:8000/pais';
// print(url);
final response = await http.get(Uri.parse(url));
var map = json.decode(response.body);
print(map);
}
@override
void initState() {
super.initState();
carregaPais();
}
@override
Widget build(BuildContext context) {