From 58614a7756c33e30799069db1330bd8ca2f204fb Mon Sep 17 00:00:00 2001 From: Reginaldo Date: Fri, 16 Jun 2023 17:15:15 -0300 Subject: [PATCH] =?UTF-8?q?ajustes=20da=20pesquisa=20e=20conex=C3=A3o=20co?= =?UTF-8?q?m=20a=20api?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/screens/home_screen.dart | 85 +++++++++++++------- lib/screens/login_screen.dart | 26 ++++-- lib/screens/responsible_register_screen.dart | 52 ++++++++++++ 3 files changed, 131 insertions(+), 32 deletions(-) diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index dccaff5..5cdcf0a 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -20,7 +20,7 @@ class HomeScreen extends StatefulWidget { class _HomeScreenState extends State { - var controllerPesquisa = TextEditingController(); + var inputPesquisa = TextEditingController(); List alunos = []; List resultadoPesquisa = []; bool filtroEstudante = false; @@ -29,11 +29,15 @@ class _HomeScreenState extends State { 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 { }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 { @override void initState() { super.initState(); - carregarAlunos(); - controllerPesquisa.addListener(pesquisa); + // inputPesquisa.addListener(pesquisa); } @override @@ -143,13 +151,32 @@ class _HomeScreenState extends State { 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 { colorText: PaletteColors.white, colorButton: PaletteColors.primaryColor, colorBorder: PaletteColors.primaryColor, - onPressed: ()=>setState(()=>controllerPesquisa.clear()), + onPressed: ()=>setState((){ + inputPesquisa.clear(); + resultadoPesquisa.clear(); + alunos.clear(); + }), ) ], ) diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index a393019..a57e52e 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -20,8 +20,10 @@ class _LoginScreenState extends State { //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 { 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 { 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 { }); } + 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; diff --git a/lib/screens/responsible_register_screen.dart b/lib/screens/responsible_register_screen.dart index 7bef538..b160410 100644 --- a/lib/screens/responsible_register_screen.dart +++ b/lib/screens/responsible_register_screen.dart @@ -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 { } } + 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) {