criado o modelo city_load_model.dart a tela login_load_screen.dart e sync_unit_screen.dart
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rkm/screens/sync_unit_screen.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.dart';
|
||||
import '../service/db/db_sqlite.dart';
|
||||
import '../utils/const_variable.dart';
|
||||
|
||||
class LoadInitScreen extends StatefulWidget {
|
||||
ArgsLoadInitModel args;
|
||||
@@ -21,20 +22,12 @@ class LoadInitScreen extends StatefulWidget {
|
||||
class _LoadInitScreenState extends State<LoadInitScreen> {
|
||||
|
||||
String messageSteps = 'Aguarde ...';
|
||||
bool finish = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// initLoading();
|
||||
finishLoad();
|
||||
}
|
||||
|
||||
finishLoad()async{
|
||||
await ApiData().loadCompetencia(widget.args).then((value)async{
|
||||
await DbSqlite().saveCompetence(value,widget.args).then((value)async{
|
||||
Navigator.pushReplacementNamed(context, '/home');
|
||||
});
|
||||
});
|
||||
initLoading();
|
||||
}
|
||||
|
||||
initLoading()async{
|
||||
@@ -105,7 +98,10 @@ class _LoadInitScreenState extends State<LoadInitScreen> {
|
||||
print('loadEquipeComponentes');
|
||||
await DbSqlite().saveTeamComponents(value).then((value)async{
|
||||
print('finalizou saveTeamComponents');
|
||||
finishLoad();
|
||||
setState(() {
|
||||
finish = true;
|
||||
});
|
||||
// Navigator.pushReplacementNamed(context, '/home');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -147,12 +143,34 @@ class _LoadInitScreenState extends State<LoadInitScreen> {
|
||||
width: width,
|
||||
height: height*0.05,
|
||||
color: ColorPalette.appBar,
|
||||
padding: EdgeInsets.all(10),
|
||||
child: TextDefault(
|
||||
text: messageSteps,
|
||||
color: ColorPalette.white,
|
||||
maxLines: 2,
|
||||
),
|
||||
child: finish
|
||||
?Row(
|
||||
children: [
|
||||
Spacer(),
|
||||
ButtonDefault(
|
||||
onPressed: (){
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SyncUnitScreen(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),
|
||||
@@ -166,7 +184,12 @@ class _LoadInitScreenState extends State<LoadInitScreen> {
|
||||
),
|
||||
)
|
||||
),
|
||||
child: ListView(
|
||||
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),
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.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';
|
||||
@@ -9,17 +7,18 @@ 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 '../models/city_load_model.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);
|
||||
class LoginLoadScreen extends StatefulWidget {
|
||||
const LoginLoadScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
State<LoginLoadScreen> createState() => _LoginLoadScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> {
|
||||
class _LoginLoadScreenState extends State<LoginLoadScreen> {
|
||||
|
||||
var inputUser = TextEditingController();
|
||||
var inputPassword = TextEditingController();
|
||||
@@ -33,45 +32,56 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
bool loading = false;
|
||||
|
||||
checkLogin()async{
|
||||
CityLoadModel? model;
|
||||
ArgsLoadInitModel? args;
|
||||
if(inputUser.text.isNotEmpty && inputPassword.text.isNotEmpty && inputUser.text.length>3 && inputPassword.text.length>3){
|
||||
if(selectCity!=null){
|
||||
setState(() {
|
||||
error = '';
|
||||
loading = true;
|
||||
});
|
||||
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';
|
||||
});
|
||||
}else if(response['status']==0) {
|
||||
setState(() {
|
||||
error = 'Usuário não encontrado';
|
||||
});
|
||||
}else if(response['status']==1) {
|
||||
setState((){
|
||||
error = '';
|
||||
});
|
||||
//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)),
|
||||
);
|
||||
for(int i=0;ConstVariable().itensCity.length > i;i++){
|
||||
if(ConstVariable().itensCity[i].nameCityFront == selectCity!){
|
||||
model = ConstVariable().itensCity[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
if(model!=null){
|
||||
args = ArgsLoadInitModel(
|
||||
mode: mode,
|
||||
model:model!,
|
||||
user: inputUser.text,
|
||||
password: inputPassword.text,
|
||||
urlAPI: urlAPI
|
||||
);
|
||||
}
|
||||
if(args!=null){
|
||||
await ApiData().apiConect(args!).then((response) async {
|
||||
if(inputUser.text == inputPassword.text || response['bloqueio']==1){
|
||||
setState(() {
|
||||
error = 'Usuário bloqueado/senha incorreta';
|
||||
});
|
||||
}else if(response['status']==0) {
|
||||
setState(() {
|
||||
error = 'Usuário não encontrado';
|
||||
});
|
||||
}else if(response['status']==1) {
|
||||
setState((){
|
||||
error = '';
|
||||
});
|
||||
//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{
|
||||
setState(() {
|
||||
error = 'Selecione sua cidade';
|
||||
@@ -84,14 +94,6 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
now = DateFormat('dd/MM/yyyy kk:mm:ss').format(DateTime.now());
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -103,15 +105,6 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
centerTitle: true,
|
||||
title: TextDefault(text: 'RKM AB - Carga Inicial',fontSize: ConstVariable().fontSizeTitleAppBar,color: ColorPalette.white),
|
||||
),
|
||||
// bottomSheet: Container(
|
||||
// color: ColorPalette.secundary,
|
||||
// padding: EdgeInsets.all(8.0),
|
||||
// child: TextDefault(
|
||||
// text: 'Última sincronização $now',
|
||||
// fontSize: 15,
|
||||
// color: ColorPalette.gray,
|
||||
// ),
|
||||
// ),
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: height*0.2),
|
||||
@@ -148,8 +141,9 @@ class _LoginScreenState extends State<LoginScreen> {
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
TextDefault(text: 'Carregando dados...',color: ColorPalette.black54,)
|
||||
Image.asset('assets/images/loading.gif'),
|
||||
SizedBox(height: 10),
|
||||
TextDefault(text: 'Carregando dados...',color: ColorPalette.black54,fontSize: 20,fontWeigth: FontWeight.bold,)
|
||||
],
|
||||
),
|
||||
):Form(
|
||||
235
lib/screens/login_saved_screen.dart
Normal file
235
lib/screens/login_saved_screen.dart
Normal file
@@ -0,0 +1,235 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:rkm/models/args_load_init_model.dart';
|
||||
import 'package:rkm/service/api/url_api_const.dart';
|
||||
import 'package:rkm/service/db/db_sqlite.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 'package:sqflite/sqflite.dart';
|
||||
import '../models/city_load_model.dart';
|
||||
import '../service/api/api_data.dart';
|
||||
import '../service/api/encrypt_password.dart';
|
||||
import 'load_init_screen.dart';
|
||||
class LoginSavedScreen extends StatefulWidget {
|
||||
List listControl;
|
||||
|
||||
LoginSavedScreen({
|
||||
required this.listControl
|
||||
});
|
||||
|
||||
@override
|
||||
State<LoginSavedScreen> createState() => _LoginSavedScreenState();
|
||||
}
|
||||
|
||||
class _LoginSavedScreenState extends State<LoginSavedScreen> {
|
||||
|
||||
var inputUser = TextEditingController();
|
||||
var inputPassword = TextEditingController();
|
||||
String error = '';
|
||||
String? now;
|
||||
String? selectCity;
|
||||
bool validatorDropDown= false;
|
||||
int contLogo = 0;
|
||||
String mode = 'homologacao';
|
||||
String urlAPI = UrlApiConst.ModeHomologacao;
|
||||
bool loading = false;
|
||||
|
||||
checkLogin()async{
|
||||
CityLoadModel? model;
|
||||
ArgsLoadInitModel? args;
|
||||
if(inputUser.text.isNotEmpty && inputPassword.text.isNotEmpty && inputUser.text.length>3 && inputPassword.text.length>3){
|
||||
if(selectCity!=null){
|
||||
setState(() {
|
||||
error = '';
|
||||
loading = true;
|
||||
for(int i=0;ConstVariable().itensCity.length > i;i++){
|
||||
if(ConstVariable().itensCity[i].nameCityFront == selectCity!){
|
||||
model = ConstVariable().itensCity[i];
|
||||
}
|
||||
}
|
||||
});
|
||||
if(model!=null){
|
||||
args = ArgsLoadInitModel(
|
||||
mode: mode,
|
||||
model:model!,
|
||||
user: inputUser.text,
|
||||
password: inputPassword.text,
|
||||
urlAPI: urlAPI
|
||||
);
|
||||
}
|
||||
if(args!=null){
|
||||
await ApiData().apiConect(args!).then((response) async {
|
||||
if(inputUser.text == inputPassword.text || response['bloqueio']==1){
|
||||
setState(() {
|
||||
error = 'Usuário bloqueado/senha incorreta';
|
||||
});
|
||||
}else if(response['status']==0) {
|
||||
setState(() {
|
||||
error = 'Usuário não encontrado';
|
||||
});
|
||||
}else if(response['status']==1) {
|
||||
setState((){
|
||||
error = '';
|
||||
});
|
||||
//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{
|
||||
setState(() {
|
||||
error = 'Selecione sua cidade';
|
||||
});
|
||||
}
|
||||
}else{
|
||||
setState(() {
|
||||
error = 'Usuário/senha inválido(s)';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
if(widget.listControl.length!=0){
|
||||
mode = widget.listControl[0]['AMBIENTE'];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
double height = MediaQuery.of(context).size.height;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: TextDefault(text: 'RKM AB - Carga Inicial',fontSize: ConstVariable().fontSizeTitleAppBar,color: ColorPalette.white),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: height*0.1),
|
||||
width: width,
|
||||
height: height,
|
||||
decoration: ConstVariable().backgroundGradient,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
Image.asset('assets/images/logo.PNG',width: width*0.4),
|
||||
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),
|
||||
loading?Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Image.asset('assets/images/loading.gif'),
|
||||
SizedBox(height: 10),
|
||||
TextDefault(text: 'Carregando dados...',color: ColorPalette.black54,fontSize: 20,fontWeigth: FontWeight.bold,)
|
||||
],
|
||||
),
|
||||
):Form(
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Container(
|
||||
width: width*0.6,
|
||||
height: height*0.2,
|
||||
child: ListView(
|
||||
children: [
|
||||
InputText(
|
||||
hint: 'Usuário',
|
||||
label: inputUser.text.isNotEmpty?'':'Usuário',
|
||||
error: 'Campo obrigatório',
|
||||
controller: inputUser,
|
||||
width: width*0.6,
|
||||
colorBorder: Colors.white,
|
||||
onChanged: (v)=>setState((){}),
|
||||
),
|
||||
InputText(
|
||||
hint: 'Senha',
|
||||
label: inputPassword.text.isNotEmpty?'':'Senha',
|
||||
error: 'Campo obrigatório',
|
||||
obscure: true,
|
||||
controller: inputPassword,
|
||||
width: width*0.6,
|
||||
colorBorder: Colors.white,
|
||||
onChanged: (v)=>setState((){}),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
loading?Container():ButtonDefault(
|
||||
onPressed: ()=>checkLogin(),
|
||||
title: 'Entrar',
|
||||
width: width*0.6,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextDefault(text: error,color: ColorPalette.red),
|
||||
widget.listControl.length==0?Container():Container(
|
||||
width: width*0.6,
|
||||
child: TextDefault(
|
||||
text: 'Última sincronização: '+DateFormat('dd/MM/yyyy kk:mm:ss').format(DateTime.parse(widget.listControl[0]['ULTIMA_SINCRONIZACAO'])),
|
||||
fontWeigth: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
),
|
||||
),
|
||||
widget.listControl.length==0?Container():Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 5),
|
||||
width: width*0.6,
|
||||
child: TextDefault(
|
||||
text: 'Unidade: '+widget.listControl[0]['UNIDADE'].toString(),
|
||||
fontWeigth: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
),
|
||||
),
|
||||
widget.listControl.length==0?Container():Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 5),
|
||||
width: width*0.6,
|
||||
child: TextDefault(
|
||||
text: 'Competência: '+widget.listControl[0]['COMPETENCIA'].toString(),
|
||||
fontWeigth: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
),
|
||||
),
|
||||
widget.listControl.length==0?Container():Container(
|
||||
padding: EdgeInsets.symmetric(vertical: 5),
|
||||
width: width*0.6,
|
||||
child: TextDefault(
|
||||
text: 'Área: '+widget.listControl[0]['AREA'].toString(),
|
||||
fontWeigth: FontWeight.bold,
|
||||
color: Colors.black,
|
||||
textAlign: TextAlign.center,
|
||||
maxLines: 2,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -297,13 +297,13 @@ class _RegisterCitizenScreenState extends State<RegisterCitizenScreen> {
|
||||
child: ListTile(
|
||||
onTap: (){
|
||||
setState(() {
|
||||
cityBirthController.text = ConstVariable().itensCity[index];
|
||||
cityBirthController.text = ConstVariable().itensCity[index].nameCityFront;
|
||||
Navigator.pop(context);
|
||||
});
|
||||
},
|
||||
title: TextDefault(
|
||||
color: ColorPalette.black54,
|
||||
text: ConstVariable().itensCity[index],
|
||||
text: ConstVariable().itensCity[index].nameCityFront,
|
||||
fontSize: 16,
|
||||
maxLines: 2,
|
||||
),
|
||||
@@ -572,14 +572,14 @@ class _RegisterCitizenScreenState extends State<RegisterCitizenScreen> {
|
||||
child: ListTile(
|
||||
onTap: (){
|
||||
setState(() {
|
||||
cityController.text = ConstVariable().itensCity[index];
|
||||
codIBGEController.text = '353870';
|
||||
cityController.text = ConstVariable().itensCity[index].nameCityFront;
|
||||
codIBGEController.text = ConstVariable().itensCity[index].codCityIbge.toString();
|
||||
Navigator.pop(context);
|
||||
});
|
||||
},
|
||||
title: TextDefault(
|
||||
color: ColorPalette.black54,
|
||||
text: ConstVariable().itensCity[index],
|
||||
text: ConstVariable().itensCity[index].nameCityFront,
|
||||
fontSize: 16,
|
||||
maxLines: 2,
|
||||
),
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rkm/models/args_load_init_model.dart';
|
||||
import 'package:rkm/models/city_load_model.dart';
|
||||
import 'package:rkm/screens/sync_unit_screen.dart';
|
||||
import 'package:rkm/utils/const_variable.dart';
|
||||
|
||||
import '../service/db/db_sqlite.dart';
|
||||
import 'login_saved_screen.dart';
|
||||
|
||||
class SplashScreen extends StatefulWidget {
|
||||
const SplashScreen({Key? key}) : super(key: key);
|
||||
@@ -16,16 +19,33 @@ class _SplashScreenState extends State<SplashScreen> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
DbSqlite().intialDB().then((value){
|
||||
|
||||
});
|
||||
DbSqlite().intialDB();
|
||||
timer();
|
||||
}
|
||||
|
||||
timer()async{
|
||||
Future.delayed(Duration(seconds: 3),(){
|
||||
Navigator.pushReplacementNamed(context, '/login');
|
||||
});
|
||||
await DbSqlite().intialDB().then((db)async{
|
||||
List data = await db.query('MUNICIPIOS');
|
||||
if(data.length != 0){
|
||||
var query = "SELECT * FROM CONTROLE_INTERNO";
|
||||
data = await db.rawQuery(query);
|
||||
if(data.length != 0){
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => LoginSavedScreen(listControl: data)),
|
||||
);
|
||||
}else{
|
||||
CityLoadModel model = CityLoadModel(codCity: 0, nameCityApi: '', nameCityFront: '', codState: '', codCityIbge: 0);
|
||||
ArgsLoadInitModel args = ArgsLoadInitModel(mode: '', model: model, user: '', password: '', urlAPI: '');
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => SyncUnitScreen(args: args)),
|
||||
);
|
||||
}
|
||||
}else{
|
||||
Navigator.pushReplacementNamed(context, '/login_load');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
263
lib/screens/sync_unit_screen.dart
Normal file
263
lib/screens/sync_unit_screen.dart
Normal file
@@ -0,0 +1,263 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.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/dropdown_button_default.dart';
|
||||
import 'package:rkm/widgets/input_text.dart';
|
||||
import 'package:rkm/widgets/text_default.dart';
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import '../models/city_load_model.dart';
|
||||
import '../service/api/api_data.dart';
|
||||
import '../service/api/encrypt_password.dart';
|
||||
import '../service/db/db_sqlite.dart';
|
||||
import 'load_init_screen.dart';
|
||||
class SyncUnitScreen extends StatefulWidget {
|
||||
ArgsLoadInitModel args;
|
||||
|
||||
SyncUnitScreen({
|
||||
required this.args
|
||||
});
|
||||
|
||||
@override
|
||||
State<SyncUnitScreen> createState() => _SyncUnitScreenState();
|
||||
}
|
||||
|
||||
class _SyncUnitScreenState extends State<SyncUnitScreen> {
|
||||
|
||||
var inputUser = TextEditingController();
|
||||
var inputPassword = TextEditingController();
|
||||
String error = '';
|
||||
String? now;
|
||||
String? selectUnit;
|
||||
String? selectTeam;
|
||||
bool validatorDropDown= false;
|
||||
int contLogo = 0;
|
||||
String mode = 'desenvolvimento';
|
||||
String urlAPI = UrlApiConst.ApiUrlDesenvolvimento;
|
||||
bool loading = false;
|
||||
List<String> listUnit=[];
|
||||
List searchUnitCodList=[];
|
||||
List listTeam = [];
|
||||
String idUnidade ='';
|
||||
checkLogin()async{
|
||||
CityLoadModel? model;
|
||||
ArgsLoadInitModel? args;
|
||||
if(inputUser.text.isNotEmpty && inputPassword.text.isNotEmpty && inputUser.text.length>3 && inputPassword.text.length>3){
|
||||
if(selectUnit!=null){
|
||||
setState(() {
|
||||
error = '';
|
||||
loading = true;
|
||||
});
|
||||
await DbSqlite().saveCityInit(widget.args).then((value)async{
|
||||
|
||||
});
|
||||
if(model!=null){
|
||||
args = ArgsLoadInitModel(
|
||||
mode: mode,
|
||||
model:model!,
|
||||
user: inputUser.text,
|
||||
password: inputPassword.text,
|
||||
urlAPI: urlAPI
|
||||
);
|
||||
}
|
||||
if(args!=null){
|
||||
await ApiData().apiConect(args!).then((response) async {
|
||||
if(inputUser.text == inputPassword.text || response['bloqueio']==1){
|
||||
setState(() {
|
||||
error = 'Usuário bloqueado/senha incorreta';
|
||||
});
|
||||
}else if(response['status']==0) {
|
||||
setState(() {
|
||||
error = 'Usuário não encontrado';
|
||||
});
|
||||
}else if(response['status']==1) {
|
||||
setState((){
|
||||
error = '';
|
||||
});
|
||||
//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{
|
||||
setState(() {
|
||||
error = 'Selecione sua cidade';
|
||||
});
|
||||
}
|
||||
}else{
|
||||
setState(() {
|
||||
error = 'Usuário/senha inválido(s)';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
setState(() {
|
||||
mode = widget.args.mode;
|
||||
inputUser.text = widget.args.user;
|
||||
inputPassword.text = widget.args.password;
|
||||
});
|
||||
getUnit();
|
||||
}
|
||||
|
||||
getUnit()async{
|
||||
Database db = await DbSqlite().intialDB();
|
||||
var query = "SELECT * FROM UNIDADES";
|
||||
List list = await db.rawQuery(query);
|
||||
// print("SELECT * FROM UNIDADES");
|
||||
// print(await db.rawQuery("SELECT * FROM UNIDADES"));
|
||||
for(int i=0; list.length > i;i++){
|
||||
listUnit.add(list[i]['NOME_UNIDADE']);
|
||||
searchUnitCodList.add(list[i]['ID_UNIDADE']);
|
||||
}
|
||||
print('searchListUnit');
|
||||
print(searchUnitCodList);
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
getTeam()async{
|
||||
for(int i=0; listUnit.length > i;i++){
|
||||
if(listUnit[i] == selectUnit){
|
||||
idUnidade = searchUnitCodList[i].toString();
|
||||
print(searchUnitCodList[i]);
|
||||
}
|
||||
}
|
||||
if(idUnidade!=''){
|
||||
Database db = await DbSqlite().intialDB();
|
||||
var query = "SELECT * FROM EQUIPES WHERE ID_UNIDADE = $idUnidade";
|
||||
List list = await db!.rawQuery(query);
|
||||
print('getEquipes');
|
||||
print(list);
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
double width = MediaQuery.of(context).size.width;
|
||||
double height = MediaQuery.of(context).size.height;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
centerTitle: true,
|
||||
title: TextDefault(text: 'RKM AB - Sincronização de Unidade',fontSize: ConstVariable().fontSizeTitleAppBar,color: ColorPalette.white),
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
padding: EdgeInsets.only(top: height*0.2),
|
||||
width: width,
|
||||
height: height,
|
||||
decoration: ConstVariable().backgroundGradient,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: loading?null:()=>setState((){
|
||||
contLogo++;
|
||||
if(contLogo>=5 && contLogo<=10){
|
||||
mode = UrlApiConst.ModeHomologacao;
|
||||
urlAPI = UrlApiConst.ApiUrlHomologacao;
|
||||
}
|
||||
if(contLogo>10){
|
||||
mode = UrlApiConst.ModeDesenvolvimento;
|
||||
urlAPI = UrlApiConst.ApiUrlDesenvolvimento;
|
||||
if(contLogo==15){
|
||||
contLogo=0;
|
||||
mode = UrlApiConst.ModeOnline;
|
||||
urlAPI = UrlApiConst.ApiUrlOnline;
|
||||
}
|
||||
}
|
||||
}),
|
||||
child: Image.asset('assets/images/logo.PNG',width: width*0.4)
|
||||
),
|
||||
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),
|
||||
loading?Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Image.asset('assets/images/loading.gif'),
|
||||
SizedBox(height: 10),
|
||||
TextDefault(text: 'Carregando dados...',color: ColorPalette.black54,fontSize: 20,fontWeigth: FontWeight.bold,)
|
||||
],
|
||||
),
|
||||
):Form(
|
||||
autovalidateMode: AutovalidateMode.onUserInteraction,
|
||||
child: Container(
|
||||
width: width*0.6,
|
||||
height: height*0.3,
|
||||
child: ListView(
|
||||
children: [
|
||||
InputText(
|
||||
hint: 'Usuário',
|
||||
label: inputUser.text.isNotEmpty?'':'Usuário',
|
||||
error: 'Campo obrigatório',
|
||||
controller: inputUser,
|
||||
width: width*0.6,
|
||||
colorBorder: Colors.white,
|
||||
onChanged: (v)=>setState((){}),
|
||||
),
|
||||
InputText(
|
||||
hint: 'Senha',
|
||||
label: inputPassword.text.isNotEmpty?'':'Senha',
|
||||
error: 'Campo obrigatório',
|
||||
obscure: true,
|
||||
controller: inputPassword,
|
||||
width: width*0.6,
|
||||
colorBorder: Colors.white,
|
||||
onChanged: (v)=>setState((){}),
|
||||
),
|
||||
DropDownButtonDefault(
|
||||
width: width*0.6,
|
||||
title: 'Unidade',
|
||||
list: listUnit,
|
||||
select: selectUnit,
|
||||
onChanged: (value){
|
||||
// for(int i=0;listUnit.length > i;i++){
|
||||
// if(listUnit[i] == selectUnit){
|
||||
//
|
||||
// }
|
||||
// }
|
||||
setState(() {
|
||||
selectUnit = value!;
|
||||
validatorDropDown = true;
|
||||
});
|
||||
getTeam();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
loading?Container():ButtonDefault(
|
||||
onPressed: ()=>checkLogin(),
|
||||
title: 'Sincronizar',
|
||||
width: width*0.6,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextDefault(text: error,color: ColorPalette.red),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user