264 lines
9.0 KiB
Dart
264 lines
9.0 KiB
Dart
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),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|