From 0816439595e067c8f08be23232c9aa9c6dbcb7af Mon Sep 17 00:00:00 2001 From: Reginaldo Date: Thu, 29 Jun 2023 17:16:16 -0300 Subject: [PATCH] ajustes para salvar acessos liberados --- lib/main.dart | 2 +- lib/models/login_model.dart | 9 ++ lib/screens/home_screen.dart | 196 ++++++++++++++++++++++++++++------ lib/screens/login_screen.dart | 8 +- 4 files changed, 178 insertions(+), 37 deletions(-) create mode 100644 lib/models/login_model.dart diff --git a/lib/main.dart b/lib/main.dart index 452de41..63de738 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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), }, ); diff --git a/lib/models/login_model.dart b/lib/models/login_model.dart new file mode 100644 index 0000000..e5cffc3 --- /dev/null +++ b/lib/models/login_model.dart @@ -0,0 +1,9 @@ +class LoginModel{ + String login; + bool check; + + LoginModel({ + required this.login, + required this.check, +}); +} \ No newline at end of file diff --git a/lib/screens/home_screen.dart b/lib/screens/home_screen.dart index 8a085ee..d913ebb 100644 --- a/lib/screens/home_screen.dart +++ b/lib/screens/home_screen.dart @@ -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 createState() => _HomeScreenState(); @@ -21,6 +22,7 @@ class _HomeScreenState extends State { var inputPesquisa = TextEditingController(); List alunos = []; + List logins = []; List resultadoPesquisa = []; bool filtroEstudante = false; bool filtroData = false; @@ -29,13 +31,14 @@ class _HomeScreenState extends State { 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 { 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 { // 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;ii;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 { 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 { ), 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 { ), ):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( diff --git a/lib/screens/login_screen.dart b/lib/screens/login_screen.dart index dba53cf..50e98e0 100644 --- a/lib/screens/login_screen.dart +++ b/lib/screens/login_screen.dart @@ -23,7 +23,7 @@ class _LoginScreenState extends State { //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 { 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); }