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,
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user