344 lines
13 KiB
Dart
344 lines
13 KiB
Dart
import 'dart:convert';
|
|
|
|
import 'package:educa_controle_acesso/utils/colors.dart';
|
|
import 'package:educa_controle_acesso/widgets/input_text.dart';
|
|
import 'package:educa_controle_acesso/widgets/text_custom.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../models/aluno_model.dart';
|
|
import '../widgets/buttom_custom.dart';
|
|
import '../widgets/dados_alunos_container.dart';
|
|
import 'package:http/http.dart' as http;
|
|
|
|
import '../widgets/snackBars.dart';
|
|
|
|
class HomeScreen extends StatefulWidget {
|
|
const HomeScreen({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
|
|
var inputPesquisa = TextEditingController();
|
|
List<AlunoModel> alunos = [];
|
|
List resultadoPesquisa = [];
|
|
bool filtroEstudante = false;
|
|
bool filtroData = false;
|
|
bool filtroRA = false;
|
|
bool filtroSerie = false;
|
|
bool filtroTurma = false;
|
|
bool filtroEscola = false;
|
|
bool buscandoDados = false;
|
|
|
|
carregarAlunos()async{
|
|
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){
|
|
showSnackBar(context, 'Dados não localizados', Colors.red);
|
|
setState(() {
|
|
buscandoDados = false;
|
|
});
|
|
}else{
|
|
List list = map;
|
|
// print(list);
|
|
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: '', serie: list[i]['DESC_SERIE'], turma: list[i]['TURMA'],dados: list[i]));
|
|
resultadoPesquisa.add(alunos[i]);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Aluno(a) não matriculado em ${DateTime.now().year}', Colors.red);
|
|
}
|
|
setState(() {
|
|
buscandoDados = false;
|
|
});
|
|
// pesquisarAluno();
|
|
}
|
|
}
|
|
|
|
// pesquisa(){
|
|
// pesquisarAluno();
|
|
// }
|
|
|
|
pesquisarAluno()async{
|
|
resultadoPesquisa =[];
|
|
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(inputPesquisa.text.toUpperCase()) ||
|
|
data.contains(inputPesquisa.text.toUpperCase()) ||
|
|
ra.contains(inputPesquisa.text.toUpperCase())
|
|
){
|
|
if(resultadoPesquisa.length<10){
|
|
resultadoPesquisa.add(alunos[i]);
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
if(alunos.length<10){
|
|
for(int i = 0;i<alunos.length;i++){
|
|
resultadoPesquisa.add(alunos[i]);
|
|
}
|
|
}else{
|
|
for(int i = 0;i<10;i++){
|
|
resultadoPesquisa.add(alunos[i]);
|
|
}
|
|
}
|
|
}
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// inputPesquisa.addListener(pesquisa);
|
|
}
|
|
|
|
@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: '- PESQUISAR ALUNO',color: Colors.white,),
|
|
],
|
|
),
|
|
backgroundColor: PaletteColors.grey,
|
|
),
|
|
body: buscandoDados?Center(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(),
|
|
SizedBox(width: 20,),
|
|
TextCustom(text: 'BUSCANDO DADOS...')
|
|
],
|
|
),
|
|
):Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: ListView(
|
|
children: [
|
|
SizedBox(height: height*0.05),
|
|
Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: width>900?width*0.15:width*0.05),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
InputText(
|
|
hint: 'Pesquisar por nome do aluno(a)'.toUpperCase(),
|
|
controller: inputPesquisa,
|
|
width: width*0.25,
|
|
inputFormatters: [],
|
|
fontSize: 14,
|
|
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,
|
|
text: "LIMPAR",
|
|
size: 10.0,
|
|
colorText: PaletteColors.white,
|
|
colorButton: PaletteColors.primaryColor,
|
|
colorBorder: PaletteColors.primaryColor,
|
|
onPressed: ()=>setState((){
|
|
inputPesquisa.clear();
|
|
resultadoPesquisa.clear();
|
|
alunos.clear();
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.symmetric(vertical: 20),
|
|
padding: EdgeInsets.symmetric(horizontal: width>900?width*0.15:width*0.05),
|
|
width: width,
|
|
alignment: Alignment.center,
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: width*0.2,
|
|
child: Row(
|
|
children: [
|
|
TextCustom(text: 'ESTUDANTE',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
IconButton(
|
|
icon: Icon(filtroEstudante?Icons.arrow_drop_up:Icons.arrow_drop_down,color: filtroEstudante?PaletteColors.primaryColor:PaletteColors.grey,),
|
|
onPressed: ()=>setState((){
|
|
filtroEstudante?filtroEstudante=false:filtroEstudante=true;
|
|
filtroData = false;
|
|
filtroRA = false;
|
|
filtroSerie = false;
|
|
filtroTurma = false;
|
|
filtroEscola = false;
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
width: width*0.1,
|
|
child: Row(
|
|
children: [
|
|
TextCustom(text: 'DATA DE NASCIMENTO',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
IconButton(
|
|
icon: Icon(filtroData?Icons.arrow_drop_up:Icons.arrow_drop_down,color: filtroData?PaletteColors.primaryColor:PaletteColors.grey,),
|
|
onPressed: ()=>setState((){
|
|
filtroData?filtroData=false:filtroData=true;
|
|
filtroEstudante = false;
|
|
filtroRA = false;
|
|
filtroSerie = false;
|
|
filtroTurma = false;
|
|
filtroEscola = false;
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
width: width*0.08,
|
|
child: Row(
|
|
children: [
|
|
TextCustom(text: 'RA',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
IconButton(
|
|
icon: Icon(filtroRA?Icons.arrow_drop_up:Icons.arrow_drop_down,color: filtroRA?PaletteColors.primaryColor:PaletteColors.grey,),
|
|
onPressed: ()=>setState((){
|
|
filtroRA?filtroRA=false:filtroRA=true;
|
|
filtroData = false;
|
|
filtroEstudante = false;
|
|
filtroSerie = false;
|
|
filtroTurma = false;
|
|
filtroEscola = false;
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
width: width*0.05,
|
|
child: Row(
|
|
children: [
|
|
TextCustom(text: 'Série',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
IconButton(
|
|
icon: Icon(filtroSerie?Icons.arrow_drop_up:Icons.arrow_drop_down,color: filtroSerie?PaletteColors.primaryColor:PaletteColors.grey,),
|
|
onPressed: ()=>setState((){
|
|
filtroSerie?filtroSerie=false:filtroSerie=true;
|
|
filtroData = false;
|
|
filtroRA = false;
|
|
filtroEstudante = false;
|
|
filtroTurma = false;
|
|
filtroEscola = false;
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
width: width*0.05,
|
|
child: Row(
|
|
children: [
|
|
TextCustom(text: 'Turma',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
IconButton(
|
|
icon: Icon(filtroTurma?Icons.arrow_drop_up:Icons.arrow_drop_down,color: filtroTurma?PaletteColors.primaryColor:PaletteColors.grey,),
|
|
onPressed: ()=>setState((){
|
|
filtroTurma?filtroTurma=false:filtroTurma=true;
|
|
filtroData = false;
|
|
filtroRA = false;
|
|
filtroSerie = false;
|
|
filtroEstudante = false;
|
|
filtroEscola = false;
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
width: width*0.15,
|
|
child: Row(
|
|
children: [
|
|
TextCustom(text: 'Escola',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
IconButton(
|
|
icon: Icon(filtroEscola?Icons.arrow_drop_up:Icons.arrow_drop_down,color: filtroEscola?PaletteColors.primaryColor:PaletteColors.grey,),
|
|
onPressed: ()=>setState((){
|
|
filtroEscola?filtroEscola=false:filtroEscola=true;
|
|
filtroData = false;
|
|
filtroRA = false;
|
|
filtroSerie = false;
|
|
filtroTurma = false;
|
|
filtroEstudante = false;
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
padding: EdgeInsets.symmetric(horizontal: width>900?width*0.15:width*0.05),
|
|
width: width*0.5,
|
|
height: height*0.8,
|
|
child: ListView.separated(
|
|
separatorBuilder: (context,index){
|
|
return Divider();
|
|
},
|
|
itemCount: resultadoPesquisa.length,
|
|
itemBuilder:(context,index){
|
|
|
|
final items = filtroEstudante||filtroData||filtroRA||filtroSerie||filtroTurma||filtroEscola?resultadoPesquisa.reversed.toList():resultadoPesquisa;
|
|
|
|
return DadosAlunosContainer(alunoModel: items[index]);
|
|
}
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|