criado o banco de dados db_sqlite.dart, criado as conexões com as api_data.dart e criada e tela load_init_screen.dart
This commit is contained in:
178
lib/screens/load_init_screen.dart
Normal file
178
lib/screens/load_init_screen.dart
Normal file
@@ -0,0 +1,178 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rkm/utils/color_palette.dart';
|
||||
import 'package:rkm/widgets/alert_dialog_default.dart';
|
||||
import 'package:rkm/widgets/text_default.dart';
|
||||
import '../models/args_load_init_model.dart';
|
||||
import '../service/api/api_data.dart';
|
||||
import '../service/db/db_sqlite.dart';
|
||||
|
||||
class LoadInitScreen extends StatefulWidget {
|
||||
ArgsLoadInitModel args;
|
||||
|
||||
LoadInitScreen({
|
||||
required this.args,
|
||||
});
|
||||
|
||||
@override
|
||||
State<LoadInitScreen> createState() => _LoadInitScreenState();
|
||||
}
|
||||
|
||||
class _LoadInitScreenState extends State<LoadInitScreen> {
|
||||
|
||||
String messageSteps = 'Aguarde ...';
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
initLoading();
|
||||
}
|
||||
|
||||
initLoading()async{
|
||||
await DbSqlite().deleteDB().then((_)async{
|
||||
await ApiData().loadPerm(widget.args).then((response)async{
|
||||
if(response['status'] == 0){
|
||||
AlertDialogDefault().alert(context, 'Error', 'Permissão negada', 'Voltar');
|
||||
} else if(response['status'] == 1 && response['load_perm'] == "S") {
|
||||
await ApiData().loadUnidades(widget.args).then((value)async{
|
||||
if(value.length !=0){
|
||||
setState(() {
|
||||
messageSteps = "Etapa 1 de 7 - Gravando as Unidades no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveUnidadesDB(value).then((value)async{
|
||||
await ApiData().loadProcedimentos(widget.args).then((value)async{
|
||||
setState(() {
|
||||
messageSteps = "Etapa 2 de 7 - Gravando os Procedimentos no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveProceduresDB(value).then((value)async{
|
||||
print('finalizou save Procedures');
|
||||
await ApiData().loadProcedimentosRegistros(widget.args).then((value)async{
|
||||
await DbSqlite().saveProceduresRegisterDB(value).then((value)async{
|
||||
print('finalizou saveProceduresRegisterDB');
|
||||
await ApiData().loadCID(widget.args).then((value)async{
|
||||
print('loadCID');
|
||||
setState(() {
|
||||
messageSteps = "Etapa 3 de 7 - Gravando os CIDs no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveCID(value).then((value)async{
|
||||
print('finalizou saveCID');
|
||||
await ApiData().loadProcedimentosCID(widget.args).then((value)async{
|
||||
print('loadProcedimentosCID');
|
||||
await DbSqlite().saveProceduresCID(value).then((value)async{
|
||||
print('finalizou saveProceduresCID');
|
||||
await ApiData().loadCBO(widget.args).then((value)async{
|
||||
print('loadCBO');
|
||||
setState(() {
|
||||
messageSteps = "Etapa 4 de 7 - Gravando os CBOs no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveCBO(value).then((value)async{
|
||||
print('finalizou saveCBO');
|
||||
await ApiData().loadProcedimentosCBO(widget.args).then((value)async{
|
||||
print('loadProcedimentosCBO');
|
||||
await DbSqlite().saveProceduresCBO(value).then((value)async{
|
||||
print('finalizou saveProceduresCBO');
|
||||
await ApiData().loadCIAP(widget.args).then((value)async{
|
||||
print('loadCIAP');
|
||||
setState(() {
|
||||
messageSteps = "Etapa 5 de 7 - Gravando os CIAPs no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveCIAP(value).then((value)async{
|
||||
print('finalizou saveCIAP');
|
||||
await ApiData().loadMunicipios(widget.args).then((value)async{
|
||||
print('loadMunicipios');
|
||||
setState(() {
|
||||
messageSteps = "Etapa 6 de 7 - Gravando os Municípios no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveCity(value).then((value)async{
|
||||
print('finalizou saveCity');
|
||||
await ApiData().loadEquipes(widget.args).then((value)async{
|
||||
print('loadEquipes');
|
||||
setState(() {
|
||||
messageSteps = "Etapa 7 de 7 - Gravando as Equipes no Aplicativo";
|
||||
});
|
||||
await DbSqlite().saveTeam(value).then((value)async{
|
||||
print('finalizou saveTeam');
|
||||
Navigator.pushReplacementNamed(context, '/home');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}else{
|
||||
AlertDialogDefault().alert(context, 'Error', 'Unidades não carregada, tente novamente!', 'Voltar');
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
double height = MediaQuery.of(context).size.height;
|
||||
|
||||
return Scaffold(
|
||||
bottomSheet: Container(
|
||||
width: width,
|
||||
height: height*0.05,
|
||||
color: ColorPalette.appBar,
|
||||
padding: EdgeInsets.all(10),
|
||||
child: TextDefault(
|
||||
text: messageSteps,
|
||||
color: ColorPalette.white,
|
||||
maxLines: 2,
|
||||
),
|
||||
),
|
||||
body: Container(
|
||||
padding: EdgeInsets.all(50),
|
||||
width: width,
|
||||
height: height,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorPalette.grayBackground,
|
||||
image: DecorationImage(
|
||||
fit: BoxFit.fitHeight,
|
||||
image: AssetImage('assets/images/load_image.png'
|
||||
),
|
||||
)
|
||||
),
|
||||
child: ListView(
|
||||
children: [
|
||||
Image.asset('assets/images/logo.PNG',width: width*0.2,height: height*0.1,),
|
||||
SizedBox(height: height*0.1),
|
||||
Image.asset('assets/images/loading.gif',width: width*0.2,height: height*0.1,),
|
||||
SizedBox(height: height*0.1),
|
||||
TextDefault(
|
||||
text: 'Aguarde enquanto a Carga Inicial é realizada.\n',
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
color: Colors.black,
|
||||
fontWeigth: FontWeight.bold,
|
||||
),
|
||||
TextDefault(
|
||||
text: 'Esse processo pode levar vários minutos dependendo da sua conexão!',
|
||||
color: Colors.black,
|
||||
fontWeigth: FontWeight.bold,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 3,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:rkm/service/url_api_const.dart';
|
||||
import 'package:rkm/models/args_load_init_model.dart';
|
||||
import 'package:rkm/service/api/url_api_const.dart';
|
||||
import 'package:rkm/utils/color_palette.dart';
|
||||
import 'package:rkm/utils/const_variable.dart';
|
||||
import 'package:rkm/widgets/button_default.dart';
|
||||
import 'package:rkm/widgets/dropdown_button_city.dart';
|
||||
import 'package:rkm/widgets/input_text.dart';
|
||||
import 'package:rkm/widgets/text_default.dart';
|
||||
|
||||
import '../service/api_get_pass.dart';
|
||||
import '../service/encrypt_password.dart';
|
||||
import '../service/api/api_data.dart';
|
||||
import '../service/api/encrypt_password.dart';
|
||||
import 'load_init_screen.dart';
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({Key? key}) : super(key: key);
|
||||
|
||||
@@ -27,19 +28,25 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
String? selectCity;
|
||||
bool validatorDropDown= false;
|
||||
int contLogo = 0;
|
||||
String mode = 'online';
|
||||
String url = UrlApiConst.ApiUrlOnline;
|
||||
String mode = 'desenvolvimento';
|
||||
String urlAPI = UrlApiConst.ApiUrlDesenvolvimento;
|
||||
bool loading = false;
|
||||
|
||||
checkLogin()async{
|
||||
if(inputUser.text.isNotEmpty && inputPassword.text.isNotEmpty && inputUser.text.length>3 && inputPassword.text.length>3){
|
||||
if(selectCity!=null){
|
||||
setState(() {
|
||||
error = '';
|
||||
loading = true;
|
||||
});
|
||||
await ApiGetPass().apiConect(selectCity,mode,inputUser.text,url).then((response){
|
||||
print(response);
|
||||
print(inputUser.text);
|
||||
print(inputPassword.text);
|
||||
ArgsLoadInitModel args = ArgsLoadInitModel(
|
||||
mode: mode,
|
||||
city: selectCity!,
|
||||
user: inputUser.text,
|
||||
password: inputPassword.text,
|
||||
urlAPI: urlAPI
|
||||
);
|
||||
await ApiData().apiConect(args).then((response) async {
|
||||
if(inputUser.text == inputPassword.text || response['bloqueio']==1){
|
||||
setState(() {
|
||||
error = 'Usuário bloqueado/senha incorreta';
|
||||
@@ -51,8 +58,18 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
}else if(response['status']==1) {
|
||||
setState((){
|
||||
error = '';
|
||||
print(EncryptPassword().encrypt(inputPassword.text,response['userPass']));
|
||||
});
|
||||
//verificar se a criptografia identificou se a senha está correta
|
||||
if(EncryptPassword().encrypt(inputPassword.text,response['userPass']) == response['userPass']){
|
||||
print(EncryptPassword().encrypt(inputPassword.text,response['userPass']));
|
||||
setState(() {
|
||||
loading = false;
|
||||
});
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => LoadInitScreen(args: args)),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}else{
|
||||
@@ -106,19 +123,19 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: ()=>setState((){
|
||||
onTap: loading?null:()=>setState((){
|
||||
contLogo++;
|
||||
if(contLogo>=5 && contLogo<=10){
|
||||
mode = 'homologacao';
|
||||
url = UrlApiConst.ApiUrlHomologacao;
|
||||
mode = UrlApiConst.ModeHomologacao;
|
||||
urlAPI = UrlApiConst.ApiUrlHomologacao;
|
||||
}
|
||||
if(contLogo>10){
|
||||
mode = 'desenvolvimento';
|
||||
url = UrlApiConst.ApiUrlDesenvolvimento;
|
||||
mode = UrlApiConst.ModeDesenvolvimento;
|
||||
urlAPI = UrlApiConst.ApiUrlDesenvolvimento;
|
||||
if(contLogo==15){
|
||||
contLogo=0;
|
||||
mode = 'online';
|
||||
url = UrlApiConst.ApiUrlOnline;
|
||||
mode = UrlApiConst.ModeOnline;
|
||||
urlAPI = UrlApiConst.ApiUrlOnline;
|
||||
}
|
||||
}
|
||||
}),
|
||||
@@ -127,7 +144,15 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
mode == 'homologacao'?Image.asset('assets/images/homologacao.png',width: width*0.4):Container(),
|
||||
mode == 'desenvolvimento'?Image.asset('assets/images/desenvolvimento.png',width: width*0.4):Container(),
|
||||
SizedBox(height: 10),
|
||||
Form(
|
||||
loading?Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
TextDefault(text: 'Carregando dados...',color: ColorPalette.black54,)
|
||||
],
|
||||
),
|
||||
):Form(
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Container(
|
||||
width: width*0.6,
|
||||
@@ -168,7 +193,7 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
),
|
||||
),
|
||||
),
|
||||
ButtonDefault(
|
||||
loading?Container():ButtonDefault(
|
||||
onPressed: ()=>checkLogin(),
|
||||
title: 'Carga Inicial',
|
||||
width: width*0.6,
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rkm/utils/const_variable.dart';
|
||||
|
||||
import '../service/db/db_sqlite.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
const SplashScreen({Key? key}) : super(key: key);
|
||||
|
||||
@@ -13,6 +16,7 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
DbSqlite().intialDB();
|
||||
timer();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user