445 lines
27 KiB
Dart
445 lines
27 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:rkm/screens/login/sync_login_screen.dart';
|
|
import 'package:rkm/config/color_palette.dart';
|
|
import 'package:rkm/widgets/alert_dialog_default.dart';
|
|
import 'package:rkm/widgets/button_default.dart';
|
|
import 'package:rkm/widgets/text_default.dart';
|
|
import '../config/const_variable.dart';
|
|
import '../service/api/api_data_load.dart';
|
|
import '../service/db/db_querys.dart';
|
|
import '../service/db/db_sqlite_load.dart';
|
|
import '../service/shared_preferences/shared_preferences_service.dart';
|
|
|
|
class LoadInitScreen extends StatefulWidget {
|
|
|
|
@override
|
|
State<LoadInitScreen> createState() => _LoadInitScreenState();
|
|
}
|
|
|
|
class _LoadInitScreenState extends State<LoadInitScreen> {
|
|
|
|
final PrefService _prefService = PrefService();
|
|
String messageSteps = 'Aguarde ...';
|
|
bool finish = false;
|
|
String mode = '';
|
|
String urlAPI = '';
|
|
bool loading = false;
|
|
String nameCityApi = '';
|
|
String username = '';
|
|
double countProg = 0.0;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
recupDB();
|
|
}
|
|
|
|
recupDB()async{
|
|
await DbSqliteLoad().intialDB().then((db)async{
|
|
List list = await db.query('ARGS');
|
|
urlAPI = list[0]['URLAPI'];
|
|
mode = list[0]['MODE'];
|
|
nameCityApi = list[0]['NAME_CITY_API'];
|
|
username = list[0]['USER'];
|
|
if(urlAPI!=''){
|
|
initLoading();
|
|
}
|
|
});
|
|
}
|
|
|
|
initLoading()async{
|
|
await ApiDataLoad().loadPerm(urlAPI,mode,nameCityApi,username).then((response)async{
|
|
print(response);
|
|
await ApiDataLoad().loadEtniasIndigenas(urlAPI, mode, nameCityApi, username).then((value)async{
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0) {
|
|
setState(() {
|
|
messageSteps = "Etapa 1 de 12 - Gravando as Etnias Indigenas no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'ID_ETNIA_INDIGENA': list[i]['idEtniaIndigena'].toString().trim(),
|
|
'DESC_ETNIA_INDIGENA': list[i]['descEtniaIndigena'].toString().trim(),
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.05;
|
|
setState(() {});
|
|
}
|
|
}
|
|
await DbSqliteLoad().saveEtniasIndigenasDB(rows).then((value)async{
|
|
await ApiDataLoad().loadUnidades(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 2 de 12 - Gravando as Unidades no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'ID_UNIDADE': list[i]['idUnidade'],
|
|
'NOME_UNIDADE': list[i]['nomeFantasia'],
|
|
'CNES_UNIDADE': list[i]['nrCNES']
|
|
};
|
|
rows.add(row);
|
|
// countProg = 0.1;
|
|
// setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveUnidadesDB(rows).then((value)async{
|
|
await ApiDataLoad().loadProcedimentos(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 3 de 12 - Gravando os Procedimentos no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'COD_PROC_SIGTAP' : list[i]['codProcedimento'],
|
|
'DESC_PROC_SIGTAP' : list[i]['nome'],
|
|
'GRUPO_PROC_SIGTAP' : list[i]['codGrupo'],
|
|
'QTDE_MAXIMA' : list[i]['qtdeMax'],
|
|
'IDADE_MIN' : list[i]['idadeMin'],
|
|
'IDADE_MAX' : list[i]['idadeMax'],
|
|
'SEXO' : list[i]['sexo'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.2;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveProceduresDB(rows).then((value)async{
|
|
print('finalizou save Procedures');
|
|
await ApiDataLoad().loadProcedimentosRegistros(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 4 de 12 - Gravando os Procedimentos Registros no Aplicativo";
|
|
});
|
|
print('finalizou saveProceduresRegisterDB');
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'COD_PROC_SIGTAP' : list[i]['codProcedimento'],
|
|
'CODIGO_REGISTRO' : list[i]['codRegistro'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.3;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveProceduresRegisterDB(rows).then((value)async{
|
|
await ApiDataLoad().loadCID(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadCID');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 5 de 12 - Gravando os CIDs no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'CODIGO_CID' : list[i]['codCID'],
|
|
'DESCRICAO_CID' : list[i]['descCID'],
|
|
'RESTRICAO_SEXO' : list[i]['restSexo'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.4;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveCID(rows).then((value)async{
|
|
print('finalizou saveCID');
|
|
await ApiDataLoad().loadProcedimentosCID(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadProcedimentosCID');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 6 de 12 - Gravando os Procedimentos CIDs no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'COD_PROC_SIGTAP' : list[i]['codProcedimento'],
|
|
'CODIGO_CID' : list[i]['codCID'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.5;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveProceduresCID(rows).then((value)async{
|
|
print('finalizou saveProceduresCID');
|
|
await ApiDataLoad().loadCBO(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadCBO');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 8 de 12 - Gravando os CBOs no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'CODIGO_CBO' : list[i]['codCBO'],
|
|
'DESCRICAO_CBO' : list[i]['descCBO'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.6;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveCBO(rows).then((value)async{
|
|
print('finalizou saveCBO');
|
|
await ApiDataLoad().loadProcedimentosCBO(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadProcedimentosCBO');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length !=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 8 de 12 - Gravando os Procedimentos CBO no Aplicativo";
|
|
});
|
|
for (int i = 0; i < list.length; i++) {
|
|
Map<String, dynamic> row = {
|
|
'COD_PROC_SIGTAP' : value[i]['codProcedimento'],
|
|
'CODIGO_CBO' : value[i]['codCBO'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.7;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveProceduresCBO(rows).then((value)async{
|
|
print('finalizou saveProceduresCBO');
|
|
await ApiDataLoad().loadCIAP(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadCIAP');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length != 0){
|
|
setState(() {
|
|
messageSteps = "Etapa 9 de 12 - Gravando os CIAPs no Aplicativo";
|
|
});
|
|
for(int i=0;list.length > i;i++){
|
|
Map<String, dynamic> row = {
|
|
'CODIGO_CIAP' : list[i]['codCIAP'],
|
|
'DESC_CIAP' : list[i]['descCIAP'],
|
|
'TIPO_CIAP' : list[i]['tipoCIAP'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.8;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveCIAP(rows).then((value)async{
|
|
print('finalizou saveCIAP');
|
|
await ApiDataLoad().loadMunicipios(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadMunicipios');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length!=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 10 de 12 - Gravando os Municípios no Aplicativo";
|
|
});
|
|
for(int i=0;list.length > i;i++){
|
|
Map<String, dynamic> row = {
|
|
'ID_MUNICIPIO' : list[i]['idMunicipio'],
|
|
'CODIGO_IBGE' : list[i]['codIBGE'],
|
|
'NO_MUNICIPIO' : list[i]['nomeMunicipio'],
|
|
'UF_ESTADO' : list[i]['UF'],
|
|
'ID_PAIS' : list[i]['idPais'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.9;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveCity(rows).then((value)async{
|
|
await ApiDataLoad().loadEquipes(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadEquipes');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length!=0){
|
|
setState(() {
|
|
messageSteps = "Etapa 11 de 12 - Gravando as Equipes no Aplicativo";
|
|
});
|
|
for(int i=0;list.length > i;i++){
|
|
Map<String, dynamic> row = {
|
|
'ID_EQUIPE' : list[i]['idEquipe'],
|
|
'ID_UNIDADE' : list[i]['idUnidade'],
|
|
'INE' : list[i]['INE'],
|
|
'ID_ATB_AREA' : list[i]['idAtbArea'],
|
|
'AREA' : list[i]['area'],
|
|
'ID_ATB_MICROAREA': list[i]['idAtbMicroarea'],
|
|
'MICROAREA' : list[i]['microarea'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.92;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveTeam(rows).then((value)async{
|
|
countProg = 0.95;
|
|
setState(() {});
|
|
print('finalizou saveTeam');
|
|
await ApiDataLoad().loadEquipeComponentes(urlAPI,mode,nameCityApi,username).then((value)async{
|
|
print('loadEquipeComponentes');
|
|
List list = value;
|
|
List<Map<String, dynamic>> rows = [];
|
|
if(list.length!=0) {
|
|
setState(() {
|
|
messageSteps ="Etapa 12 de 12 - Gravando os Profissionais das Equipes no Aplicativo";
|
|
});
|
|
for(int i=0;list.length > i;i++){
|
|
Map<String, dynamic> row = {
|
|
'ID_EQUIPE' : list[i]['idEquipe'],
|
|
'ID_PROFISSIONAL' : list[i]['idProfissional'],
|
|
'ATIVO' : list[i]['ativo'],
|
|
};
|
|
rows.add(row);
|
|
countProg = 0.97;
|
|
setState(() {});
|
|
}
|
|
await DbSqliteLoad().saveTeamComponents(rows).then((value)async{
|
|
print('finalizou saveTeamComponents');
|
|
setState(() {
|
|
countProg = 1;
|
|
finish = true;
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Profissionais Equipes não carregadas, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Equipes não carregadas, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Municípios não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'CIAPs não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Procedimentos CBOs não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'CBOs não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Procedimentos CIDs não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'CIDs não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Procedimentos Registros não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Procedimentos não carregados, tente novamente!', 'Voltar');
|
|
}
|
|
});
|
|
});
|
|
}else{
|
|
AlertDialogDefault().alert(context, 'Error', 'Unidades não carregadas, 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: 70,
|
|
color: ColorPalette.appBar,
|
|
child: finish
|
|
?Row(
|
|
children: [
|
|
Spacer(),
|
|
ButtonDefault(
|
|
onPressed: (){
|
|
Navigator.pushReplacement(
|
|
context,
|
|
MaterialPageRoute(builder: (context) => SyncLoginScreen()),
|
|
);
|
|
},
|
|
title: 'Continuar',
|
|
width: width*0.3,
|
|
height: height*0.1,
|
|
textColor: ColorPalette.white,
|
|
background: ColorPalette.appBar,
|
|
borderColor: ColorPalette.appBar,
|
|
),
|
|
],
|
|
)
|
|
:Padding(
|
|
padding: const EdgeInsets.all(10.0),
|
|
child: TextDefault(
|
|
fontSize: 15,
|
|
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: finish?ListView(
|
|
children: [
|
|
Image.asset('assets/images/logo.PNG',width: width*0.3,height: height*0.2,),
|
|
Image.asset('assets/images/load-done.png',width: width*0.9,height: height*0.2,),
|
|
],
|
|
):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,
|
|
),
|
|
SizedBox(height: 30),
|
|
TextDefault(text: countProg>0.99?'100 % finalizando etapa atual':(countProg*100).toStringAsFixed(0) + '%',color: Colors.black,textAlign: TextAlign.center,fontWeigth: FontWeight.bold,fontSize: 20),
|
|
SizedBox(height: 10),
|
|
LinearProgressIndicator(value: countProg,minHeight: 15,color: ColorPalette.appBar,backgroundColor: ColorPalette.titleContainer,)
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|