ciada a tela sync_init_screen.dart com a api_data_sync.dart, shared_preferences_service.dart e db_sqlite_sync.dart
This commit is contained in:
231
lib/screens/sync_init_screen.dart
Normal file
231
lib/screens/sync_init_screen.dart
Normal file
@@ -0,0 +1,231 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rkm/screens/login/sync_login_screen.dart';
|
||||
import 'package:rkm/service/api/api_data_sync.dart';
|
||||
import 'package:rkm/service/db/db_sqlite_sync.dart';
|
||||
import 'package:rkm/utils/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 '../models/args_load_init_model.dart';
|
||||
import '../service/api/api_data_load.dart';
|
||||
import '../service/db/db_sqlite_load.dart';
|
||||
import '../service/shared_preferences/shared_preferences_service.dart';
|
||||
|
||||
class SyncInitScreen extends StatefulWidget {
|
||||
ArgsLoadInitModel args;
|
||||
|
||||
SyncInitScreen({
|
||||
required this.args,
|
||||
});
|
||||
|
||||
@override
|
||||
State<SyncInitScreen> createState() => _SyncInitScreenState();
|
||||
}
|
||||
|
||||
class _SyncInitScreenState extends State<SyncInitScreen> {
|
||||
|
||||
final PrefService _prefService = PrefService();
|
||||
String messageSteps = 'Aguarde ...';
|
||||
bool finish = false;
|
||||
String idUsuario = '';
|
||||
String idUnidade = '';
|
||||
String area = '';
|
||||
String microarea = '';
|
||||
bool foraArea = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
dataUser();
|
||||
}
|
||||
|
||||
dataUser()async{
|
||||
_prefService.readCacheIdUnidade('idUnidade').then((id)async{
|
||||
_prefService.readCacheSync('area', false).then((list){
|
||||
foraArea = list[1];
|
||||
List splited = list[0].split(': ');
|
||||
area = splited[2].toString().substring(0,1);
|
||||
microarea = splited[3];
|
||||
idUnidade = id;
|
||||
initSync();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
initSync()async{
|
||||
await DbSqliteSync().deleteSync().then((_)async{
|
||||
await ApiDataSync().syncPerm(widget.args).then((response)async{
|
||||
if(response['status'] == 0 || response['sync_perm'] != "S"){
|
||||
AlertDialogDefault().alert(context, 'Erro', 'Usuário sem permissão para Sincronização de Unidade!', 'Voltar');
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 1 de 10 - Importando informações do CONECTASUS");
|
||||
await ApiDataSync().syncBairros(widget.args).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Bairros - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 2 de 10 - Gravando os Bairros no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertBairros(value).then((value)async{
|
||||
await ApiDataSync().syncTiposLogradouros(widget.args).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Tipos de Logradouros - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 3 de 10 - Gravando os Tipos de Logradouros no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertTiposLogradouros(value).then((value)async{
|
||||
await ApiDataSync().syncLogradouros(widget.args).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Logradouros - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 4 de 10 - Gravando os Logradouros no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertLogradouros(value).then((value)async{
|
||||
await ApiDataSync().syncLoteamentos(widget.args).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Loteamentos - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 5 de 10 - Gravando os Loteamentos no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertLoteamentos(value).then((value)async{
|
||||
await ApiDataSync().syncProfissionais(widget.args,idUnidade).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Profissionais - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 6 de 10 - Gravando os Profissionais no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertProfissionais(value).then((value)async{
|
||||
await ApiDataSync().syncProfissionaisCBOs(widget.args,idUnidade).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os CBOs dos Profissionais - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 7 de 10 - Gravando os CBO´s dos Profissionais no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertProfissionaisCBOs(value).then((value)async{
|
||||
await ApiDataSync().syncCidadaos(widget.args,idUnidade,area,microarea,foraArea).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Cadastros dos Cidadãos - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 8 de 10 - Gravando os Cidadãos no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertCidadaos(value).then((value)async{
|
||||
await ApiDataSync().syncCadastrosDomiciliares(widget.args,idUnidade,area,microarea,foraArea).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Cadastros Domiciliares - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 9 de 10 - Gravando os Cadastros Domiciliares no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertCadastrosDomiciliares(value).then((value)async{
|
||||
await ApiDataSync().syncCadastrosIndividuais(widget.args,idUnidade,area,microarea,foraArea).then((value)async{
|
||||
if(value.length == 0){
|
||||
setState(()=> messageSteps = "ERRO: Erro para carregar os Cadastros Individuais - Por favor, tente novamente!");
|
||||
}else{
|
||||
setState(()=> messageSteps = "Etapa 10 de 10 - Gravando os Cadastros Individuais no Aplicativo");
|
||||
}
|
||||
await DbSqliteSync().insertCadastrosIndividuais(value).then((value)async{
|
||||
//agora salvar controle interno
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@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,
|
||||
child: finish
|
||||
?Row(
|
||||
children: [
|
||||
Spacer(),
|
||||
ButtonDefault(
|
||||
onPressed: (){
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SyncLoginScreen(args: widget.args)),
|
||||
);
|
||||
},
|
||||
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(
|
||||
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 Sincronização da Unidade é 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,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user