567 lines
23 KiB
Dart
567 lines
23 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/item_acesso.dart';
|
|
import 'package:educa_controle_acesso/widgets/text_custom.dart';
|
|
import 'package:flutter/material.dart';
|
|
import '../models/aluno_model.dart';
|
|
import '../models/login_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 {
|
|
List dados;
|
|
HomeScreen({required this.dados,});
|
|
|
|
@override
|
|
State<HomeScreen> createState() => _HomeScreenState();
|
|
}
|
|
|
|
class _HomeScreenState extends State<HomeScreen> {
|
|
|
|
var inputPesquisa = TextEditingController();
|
|
List<AlunoModel> alunos = [];
|
|
List<LoginModel> logins = [];
|
|
List resultadoPesquisa = [];
|
|
bool filtroEstudante = false;
|
|
bool filtroData = false;
|
|
bool filtroRA = false;
|
|
bool filtroSerie = false;
|
|
bool filtroTurma = false;
|
|
bool filtroEscola = false;
|
|
bool buscandoDados = false;
|
|
bool showEscola = false;
|
|
|
|
String mensagem = 'BUSCANDO DADOS ...';
|
|
|
|
carregarAlunos()async{
|
|
resultadoPesquisa.clear();
|
|
alunos.clear();
|
|
String aluno = inputPesquisa.text.replaceAll(' ', '%20').toUpperCase();
|
|
String escola = widget.dados[3].replaceAll(' ', '%20').toUpperCase();
|
|
// print(q);
|
|
final url = '${widget.dados[2]}/aluno?NOME=$aluno&CIDADE=${widget.dados[0]}&ANO=${DateTime.now().year}&ESCOLA=$escola';
|
|
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: list[i]['NO_RAZAO_SOCIAL']==''||list[i]['NO_RAZAO_SOCIAL']==null?list[i]['NO_FANTASIA']:list[i]['NO_RAZAO_SOCIAL'],
|
|
serie: list[i]['DESC_SERIE'],
|
|
turma: list[i]['TURMA'],
|
|
dados: list[i],
|
|
cidade: widget.dados[0],
|
|
login: widget.dados[1],
|
|
URL: widget.dados[2],
|
|
)
|
|
);
|
|
resultadoPesquisa.add(alunos[i]);
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'Aluno(a) não matriculado em ${DateTime.now().year}', Colors.red);
|
|
}
|
|
setState(() {
|
|
buscandoDados = false;
|
|
});
|
|
}
|
|
}
|
|
|
|
getAcessosMariaDB()async{
|
|
logins.clear();
|
|
setState(() {
|
|
buscandoDados = true;
|
|
});
|
|
final url = '${widget.dados[2]}/acesso_maria?LOGIN=${inputPesquisa.text.toUpperCase()}&CIDADE=${widget.dados[0]}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
print(map);
|
|
List list = map;
|
|
if(list.length != 0 ){
|
|
for(int i=0;list.length>i;i++){
|
|
logins.add(
|
|
LoginModel(
|
|
ID_USUARIO: list[i]['ID_USUARIO'],
|
|
NO_USUARIO_SISTEMA:list[i]['NO_USUARIO_SISTEMA']??'',
|
|
CHECK:list[i]['CONDICAO']=='1'?true: false,
|
|
STATUS: 'CADASTRADO',
|
|
CADASTRADO_POR:list[i]['CADASTRADO_POR'],
|
|
CIDADE: list[i]['CIDADE'],
|
|
DATA: list[i]['DATA'],
|
|
)
|
|
);
|
|
}
|
|
setState(() {
|
|
buscandoDados = false;
|
|
});
|
|
}else{
|
|
getAcessosBasePrincipal();
|
|
}
|
|
}
|
|
|
|
getAcessosBasePrincipal()async{
|
|
logins.clear();
|
|
setState(() {
|
|
buscandoDados = true;
|
|
});
|
|
final url = '${widget.dados[2]}/acesso_base?LOGIN=${inputPesquisa.text.toUpperCase()}&CIDADE=${widget.dados[0]}';
|
|
print(url);
|
|
final response = await http.get(Uri.parse(url));
|
|
var map = json.decode(response.body);
|
|
print(map);
|
|
List list = map;
|
|
if(list.length!=0){
|
|
for(int i=0;list.length>i;i++){
|
|
if(list[i]['NO_USERNAME']!='ADMIN'){
|
|
logins.add(LoginModel(ID_USUARIO: list[i]['NO_USERNAME'],NO_USUARIO_SISTEMA:list[i]['NO_USUARIO_SISTEMA']??'',CHECK: false,STATUS: 'NOVO',CIDADE: widget.dados[0],CADASTRADO_POR: 'NÃO CADASTRADO',DATA: '00/00/0000'));
|
|
}
|
|
}
|
|
}else{
|
|
showSnackBar(context, 'NENHUM USUÁRIO ENCONTRADO!', Colors.red);
|
|
}
|
|
setState(() {
|
|
buscandoDados = false;
|
|
});
|
|
}
|
|
|
|
inserirAcessos(int index)async{
|
|
final url = '${widget.dados[2]}/inserir_acesso';
|
|
final response = await http.post(
|
|
Uri.parse(url),
|
|
body:{
|
|
'DATA' : DateTime.now().toString(),
|
|
'CONDICAO': logins[index].CHECK?"1":"2",
|
|
'CADASTRADO_POR': widget.dados[1].toString().toUpperCase(),
|
|
'ID_USUARIO' : logins[index].ID_USUARIO,
|
|
'NO_USUARIO_SISTEMA': logins[index].NO_USUARIO_SISTEMA,
|
|
'CIDADE': widget.dados[0],
|
|
'NOVO' : logins[index].STATUS == 'NOVO'? 'SIM':'NAO'
|
|
}
|
|
);
|
|
// print(response.body);
|
|
showSnackBar(context, '${response.body.toUpperCase()}!', Colors.green);
|
|
logins[index].STATUS == 'NAO';
|
|
buscandoDados = false;
|
|
setState(() {});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
double width = MediaQuery.of(context).size.width;
|
|
double height = MediaQuery.of(context).size.height;
|
|
|
|
return widget.dados[0]==null || widget.dados[0] == ''?Container():Scaffold(
|
|
appBar: AppBar(
|
|
title: Row(
|
|
children: [
|
|
Container(
|
|
child: Image.asset("assets/images/logoEduca.png",width:width * 0.08,height: height * 0.12)
|
|
),
|
|
TextCustom(text: showEscola?'- PESQUISAR USUÁRIOS':'- PESQUISAR ESTUDANTES',color: Colors.white,),
|
|
Spacer(),
|
|
widget.dados[1].toString().toUpperCase()=='ADMIN'?ButtonCustom(
|
|
onPressed: (){
|
|
inputPesquisa.clear();
|
|
setState(()=>showEscola?showEscola=false:showEscola=true);
|
|
},
|
|
text: showEscola?'Cadastrar Pais':'Cadastrar Usuários',
|
|
fontSize: 15,
|
|
widthCustom: 0.1,
|
|
colorButton: PaletteColors.primaryColor,
|
|
colorText: PaletteColors.white,
|
|
colorBorder: PaletteColors.white
|
|
):Container(),
|
|
SizedBox(width: width * 0.02),
|
|
TextCustom(text: widget.dados[0]==null?'':widget.dados[0],color: Colors.white,),
|
|
TextCustom(text:widget.dados[1]==null?'':' - '+widget.dados[1].toString().toUpperCase(),color: Colors.white,),
|
|
],
|
|
),
|
|
backgroundColor: PaletteColors.grey,
|
|
),
|
|
body: buscandoDados?Center(
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
CircularProgressIndicator(),
|
|
SizedBox(width: 20,),
|
|
TextCustom(text: mensagem)
|
|
],
|
|
),
|
|
):Padding(
|
|
padding: const EdgeInsets.all(8.0),
|
|
child: showEscola?ListView(
|
|
children: [
|
|
SizedBox(height: height*0.05),
|
|
Container(
|
|
margin: EdgeInsets.symmetric(horizontal: width*0.1),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Container(
|
|
height: 35,
|
|
width: 70,
|
|
alignment: Alignment.center,
|
|
child: TextCustom(text: 'BUSCAR',color: Colors.black,size: 12.0),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(3.0),bottomLeft: Radius.circular(3.0),),
|
|
color: PaletteColors.greySearch,
|
|
border: Border.all(color: PaletteColors.grey)
|
|
),
|
|
),
|
|
InputText(
|
|
borderRadius: 0,
|
|
hint: 'Pesquisar por login do usuário'.toUpperCase(),
|
|
controller: inputPesquisa,
|
|
width: width*0.662,
|
|
inputFormatters: [],
|
|
fontSize: 14,
|
|
colorBackground: Colors.white,
|
|
),
|
|
ButtonCustom(
|
|
borderRadiusbottomLeft: 0,
|
|
borderRadiustopLeft: 0,
|
|
borderRadiusbottomRight: 0,
|
|
borderRadiustopRight: 0,
|
|
widthCustom: 0.05,
|
|
text: "PESQUISAR",
|
|
fontSize: 10.0,
|
|
colorText: PaletteColors.white,
|
|
colorButton: PaletteColors.green,
|
|
colorBorder: PaletteColors.green,
|
|
onPressed: (){
|
|
if(inputPesquisa.text.isNotEmpty){
|
|
setState(() {
|
|
buscandoDados = true;
|
|
});
|
|
// getAcessosBasePrincipal();
|
|
getAcessosMariaDB();
|
|
}else{
|
|
showSnackBar(context, 'Digite alguma informação para pesquisar', Colors.red);
|
|
}
|
|
},
|
|
),
|
|
ButtonCustom(
|
|
borderRadiusbottomLeft: 0,
|
|
borderRadiustopLeft: 0,
|
|
widthCustom: 0.05,
|
|
text: "LIMPAR",
|
|
fontSize: 10.0,
|
|
colorText: PaletteColors.white,
|
|
colorButton: PaletteColors.grey,
|
|
colorBorder: PaletteColors.grey,
|
|
onPressed: ()=>setState((){
|
|
inputPesquisa.clear();
|
|
resultadoPesquisa.clear();
|
|
alunos.clear();
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 20,right: width*0.1,left: width*0.1),
|
|
width: width,
|
|
height: 42,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: PaletteColors.greySearch,
|
|
border: Border.all(color: PaletteColors.grey)
|
|
),
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 30,),
|
|
Container(
|
|
width: width*0.12,
|
|
child: TextCustom(text: 'USUÁRIO',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
),
|
|
Container(
|
|
width: width*0.2,
|
|
child: TextCustom(text: 'NOME',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
),
|
|
Container(
|
|
width: width*0.1,
|
|
child: TextCustom(text: 'DATA DO CADASTRO',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
),
|
|
Container(
|
|
width: width*0.1,
|
|
child: TextCustom(text: 'CADASTRADO POR',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
),
|
|
Container(
|
|
width: width*0.1,
|
|
child: TextCustom(text: 'BASE',size: 12,fontWeight: FontWeight.bold,color: Colors.black87,),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
Container(
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: logins.length==0?Colors.white:PaletteColors.grey)
|
|
),
|
|
margin: EdgeInsets.symmetric(horizontal: width>900?width*0.1:width*0.05),
|
|
height: height*0.74,
|
|
child: ListView.builder(
|
|
itemCount: logins.length,
|
|
itemBuilder: (context,index){
|
|
return ItemAcesso(
|
|
index: index,
|
|
check: logins[index].CHECK,
|
|
ID_USUARIO: logins[index].ID_USUARIO,
|
|
NO_USUARIO_SISTEMA: logins[index].NO_USUARIO_SISTEMA,
|
|
CADASTRADO_POR: logins[index].CADASTRADO_POR,
|
|
CIDADE: logins[index].CIDADE,
|
|
DATA: logins[index].DATA,
|
|
onChanged: (v){
|
|
buscandoDados = true;
|
|
mensagem = 'SALVANDO DADOS ...';
|
|
setState(()=>logins[index].CHECK=v!);
|
|
inserirAcessos(index);
|
|
}
|
|
);
|
|
},
|
|
),
|
|
)
|
|
],
|
|
):ListView(
|
|
children: [
|
|
SizedBox(height: height*0.05),
|
|
Container(
|
|
margin: EdgeInsets.symmetric(horizontal: width*0.1),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
children: [
|
|
Container(
|
|
height: 35,
|
|
width: 70,
|
|
alignment: Alignment.center,
|
|
child: TextCustom(text: 'BUSCAR',color: Colors.black,size: 12.0),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.only(topLeft: Radius.circular(3.0),bottomLeft: Radius.circular(3.0),),
|
|
color: PaletteColors.greySearch,
|
|
border: Border.all(color: PaletteColors.grey)
|
|
),
|
|
),
|
|
InputText(
|
|
hint: 'Pesquisar por nome do aluno(a)'.toUpperCase(),
|
|
controller: inputPesquisa,
|
|
width: width*0.662,
|
|
inputFormatters: [],
|
|
fontSize: 14,
|
|
colorBackground: Colors.white,
|
|
borderRadius: 0,
|
|
),
|
|
ButtonCustom(
|
|
borderRadiusbottomLeft: 0,
|
|
borderRadiustopLeft: 0,
|
|
borderRadiusbottomRight: 0,
|
|
borderRadiustopRight: 0,
|
|
widthCustom: 0.05,
|
|
text: "PESQUISAR",
|
|
fontSize: 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(
|
|
borderRadiusbottomLeft: 0,
|
|
borderRadiustopLeft: 0,
|
|
widthCustom: 0.05,
|
|
text: "LIMPAR",
|
|
fontSize: 10.0,
|
|
colorText: PaletteColors.white,
|
|
colorButton: PaletteColors.grey,
|
|
colorBorder: PaletteColors.grey,
|
|
onPressed: ()=>setState((){
|
|
inputPesquisa.clear();
|
|
resultadoPesquisa.clear();
|
|
alunos.clear();
|
|
}),
|
|
)
|
|
],
|
|
)
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.only(top: 20,right: width*0.1,left: width*0.1),
|
|
width: width,
|
|
alignment: Alignment.center,
|
|
decoration: BoxDecoration(
|
|
color: PaletteColors.greySearch,
|
|
border: Border.all(color: PaletteColors.grey)
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: width*0.2,
|
|
child: Row(
|
|
children: [
|
|
SizedBox(width: 10,),
|
|
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.07,
|
|
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.07,
|
|
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.2,
|
|
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(
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: resultadoPesquisa.length==0?Colors.white:PaletteColors.grey)
|
|
),
|
|
margin: EdgeInsets.symmetric(horizontal: width>900?width*0.1:width*0.05),
|
|
width: width*0.75,
|
|
height: height*0.74,
|
|
child: ListView.builder(
|
|
itemCount: resultadoPesquisa.length,
|
|
itemBuilder:(context,index){
|
|
|
|
final items = filtroEstudante||filtroData||filtroRA||filtroSerie||filtroTurma||filtroEscola?resultadoPesquisa.reversed.toList():resultadoPesquisa;
|
|
return DadosAlunosContainer(alunoModel: items[index],index: index,);
|
|
}
|
|
),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|