ajustes da pesquisa e conexão com a api
This commit is contained in:
@@ -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();
|
||||
}),
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user