ajustes para salvar acessos liberados
This commit is contained in:
@@ -20,7 +20,7 @@ class MyApp extends StatelessWidget {
|
||||
title: 'CONTROLE DE ACESSO',
|
||||
routes: {
|
||||
'/': (_)=> LoginScreen(),
|
||||
'/home':(context)=> HomeScreen(cidade: ModalRoute.of(context)!.settings.arguments as String),
|
||||
'/home':(context)=> HomeScreen(dados: ModalRoute.of(context)!.settings.arguments as List),
|
||||
'/cadastro':(context)=>ResponsibleRegisterScreen(ModalRoute.of(context)!.settings.arguments as AlunoModel),
|
||||
},
|
||||
);
|
||||
|
||||
9
lib/models/login_model.dart
Normal file
9
lib/models/login_model.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
class LoginModel{
|
||||
String login;
|
||||
bool check;
|
||||
|
||||
LoginModel({
|
||||
required this.login,
|
||||
required this.check,
|
||||
});
|
||||
}
|
||||
@@ -4,14 +4,15 @@ 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 '../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 {
|
||||
String cidade;
|
||||
HomeScreen({required this.cidade});
|
||||
List dados;
|
||||
HomeScreen({required this.dados,});
|
||||
|
||||
@override
|
||||
State<HomeScreen> createState() => _HomeScreenState();
|
||||
@@ -21,6 +22,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
|
||||
var inputPesquisa = TextEditingController();
|
||||
List<AlunoModel> alunos = [];
|
||||
List<LoginModel> logins = [];
|
||||
List resultadoPesquisa = [];
|
||||
bool filtroEstudante = false;
|
||||
bool filtroData = false;
|
||||
@@ -29,13 +31,14 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
bool filtroTurma = false;
|
||||
bool filtroEscola = false;
|
||||
bool buscandoDados = false;
|
||||
bool showEscola = false;
|
||||
|
||||
carregarAlunos()async{
|
||||
resultadoPesquisa.clear();
|
||||
alunos.clear();
|
||||
String q = inputPesquisa.text.replaceAll(' ', '%20').toUpperCase();
|
||||
// print(q);
|
||||
final url = 'http://192.168.18.2:8000/aluno?NOME=$q&CIDADE=${widget.cidade}';
|
||||
final url = 'http://192.168.18.2:8000/aluno?NOME=$q&CIDADE=${widget.dados[0]}';
|
||||
print(url);
|
||||
final response = await http.get(Uri.parse(url));
|
||||
var map = json.decode(response.body);
|
||||
@@ -67,7 +70,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
serie: list[i]['DESC_SERIE'],
|
||||
turma: list[i]['TURMA'],
|
||||
dados: list[i],
|
||||
cidade: widget.cidade
|
||||
cidade: widget.dados[0]
|
||||
)
|
||||
);
|
||||
resultadoPesquisa.add(alunos[i]);
|
||||
@@ -86,34 +89,75 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
// 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();
|
||||
// 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(() {});
|
||||
// }
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
getAcessos()async{
|
||||
logins.clear();
|
||||
setState(() {
|
||||
buscandoDados = true;
|
||||
});
|
||||
final url = 'http://192.168.18.2:8000/acesso?LOGIN=${inputPesquisa.text}&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;
|
||||
for(int i=0;list.length>i;i++){
|
||||
logins.add(LoginModel(login: list[i]['NO_USERNAME'],check: false));
|
||||
}
|
||||
|
||||
setState(() {
|
||||
buscandoDados = false;
|
||||
});
|
||||
}
|
||||
|
||||
inserirAcessos(int index)async{
|
||||
final url = 'http://192.168.18.2:8000/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].login,
|
||||
'CIDADE': widget.dados[0],
|
||||
'NOVO' : 'NAO'
|
||||
}
|
||||
);
|
||||
print(response.body);
|
||||
if(response.body == 'cadastrado com sucesso' || response.body == 'editado com sucesso'){
|
||||
showSnackBar(context, '${response.body}!', Colors.green);
|
||||
}
|
||||
buscandoDados = false;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
@@ -123,7 +167,7 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
double height = MediaQuery.of(context).size.height;
|
||||
|
||||
return widget.cidade==null || widget.cidade == ''?Container():Scaffold(
|
||||
return widget.dados[0]==null || widget.dados[0] == ''?Container():Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Row(
|
||||
children: [
|
||||
@@ -132,7 +176,18 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
TextCustom(text: '- PESQUISAR ALUNO',color: Colors.white,),
|
||||
Spacer(),
|
||||
TextCustom(text: widget.cidade,color: Colors.white,)
|
||||
widget.dados[1].toString().toUpperCase()=='ADMIN'?ButtonCustom(
|
||||
onPressed: ()=>setState(()=>showEscola?showEscola=false:showEscola=true),
|
||||
text: showEscola?'Acesso Pais':'Acesso Escola',
|
||||
size: 15,
|
||||
widthCustom: 0.1,
|
||||
heightCustom: 0.05,
|
||||
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,)
|
||||
],
|
||||
),
|
||||
backgroundColor: PaletteColors.grey,
|
||||
@@ -148,7 +203,82 @@ class _HomeScreenState extends State<HomeScreen> {
|
||||
),
|
||||
):Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
child: showEscola?ListView(
|
||||
children: [
|
||||
SizedBox(height: height*0.05),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: width>900?width*0.1:width*0.05),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
InputText(
|
||||
hint: 'Pesquisar por login do usuário'.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;
|
||||
});
|
||||
getAcessos();
|
||||
}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(
|
||||
padding: EdgeInsets.symmetric(horizontal: width>900?width*0.1:width*0.05),
|
||||
height: height*0.2,
|
||||
child: ListView.builder(
|
||||
itemCount: logins.length,
|
||||
itemBuilder: (context,index){
|
||||
return Row(
|
||||
children: [
|
||||
Checkbox(
|
||||
value: logins[index].check,
|
||||
onChanged: (v){
|
||||
buscandoDados = true;
|
||||
setState(()=>logins[index].check=v!);
|
||||
inserirAcessos(index);
|
||||
}
|
||||
),
|
||||
TextCustom(text: logins[index].login),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
):ListView(
|
||||
children: [
|
||||
SizedBox(height: height*0.05),
|
||||
Padding(
|
||||
|
||||
@@ -23,7 +23,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
//ibueno
|
||||
final inputLogin = TextEditingController(text: 'admin');
|
||||
final inputSenha = TextEditingController(text: 'las1594@@');
|
||||
final inputCodigo = TextEditingController(text: 'e001');
|
||||
final inputCodigo = TextEditingController(text: 'e003');
|
||||
bool loading = false;
|
||||
List listCodigo = [];
|
||||
|
||||
@@ -76,14 +76,16 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
if(map['NO_USERNAME']==map['SENHA']){
|
||||
if(map['NO_USERNAME']==inputLogin.text.toUpperCase() && map['SENHA']==inputSenha.text.toUpperCase()){
|
||||
showSnackBar(context, 'Acesso validado', Colors.green);
|
||||
Navigator.pushNamed(context, '/home',arguments: cidade);
|
||||
List dados = [cidade,inputLogin.text];
|
||||
Navigator.pushNamed(context, '/home',arguments: dados);
|
||||
}else{
|
||||
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red);
|
||||
}
|
||||
}else{
|
||||
if(MainControllers().encrypt(inputSenha.text,map['SENHA']) == map['SENHA']){
|
||||
showSnackBar(context, 'Acesso validado', Colors.green);
|
||||
Navigator.pushNamed(context, '/home',arguments: cidade);
|
||||
List dados = [cidade,inputLogin.text];
|
||||
Navigator.pushNamed(context, '/home',arguments: dados);
|
||||
}else{
|
||||
showSnackBar(context, 'Login não cadastrado e/ou senha incorreta', Colors.red);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user