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:
205
lib/screens/login/login_load_screen.dart
Normal file
205
lib/screens/login/login_load_screen.dart
Normal file
@@ -0,0 +1,205 @@
|
||||
import 'package:flutter/material.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/input_text.dart';
|
||||
import 'package:rkm/widgets/text_default.dart';
|
||||
import '../../models/city_load_model.dart';
|
||||
import '../../service/api/api_data_load.dart';
|
||||
import '../../service/api/encrypt_password.dart';
|
||||
import '../../service/shared_preferences/shared_preferences_service.dart';
|
||||
import '../load_init_screen.dart';
|
||||
class LoginLoadScreen extends StatefulWidget {
|
||||
const LoginLoadScreen({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LoginLoadScreen> createState() => _LoginLoadScreenState();
|
||||
}
|
||||
|
||||
class _LoginLoadScreenState extends State<LoginLoadScreen> {
|
||||
|
||||
var inputUser = TextEditingController();
|
||||
var inputPassword = TextEditingController();
|
||||
String error = '';
|
||||
String? now;
|
||||
String? selectCity;
|
||||
bool validatorDropDown= false;
|
||||
int contLogo = 0;
|
||||
String mode = 'desenvolvimento';
|
||||
String urlAPI = UrlApiConst.ApiUrlDesenvolvimento;
|
||||
bool loading = false;
|
||||
final PrefService _prefService = PrefService();
|
||||
checkLogin()async{
|
||||
CityLoadModel? model;
|
||||
ArgsLoadInitModel? args;
|
||||
if(inputUser.text.isNotEmpty && inputPassword.text.isNotEmpty && inputUser.text.length>3 && inputPassword.text.length>3){
|
||||
if(selectCity!=null){
|
||||
_prefService.createCacheModel(inputUser.text,inputPassword.text,selectCity!,mode);
|
||||
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 ApiDataLoad().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
|
||||
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.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((){}),
|
||||
),
|
||||
DropDownButtonCity(
|
||||
error: 'Campo obrigatório',
|
||||
validator: validatorDropDown,
|
||||
select: selectCity,
|
||||
onChanged: (value){
|
||||
setState(() {
|
||||
selectCity = value!;
|
||||
validatorDropDown = true;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
loading?Container():ButtonDefault(
|
||||
onPressed: ()=>checkLogin(),
|
||||
title: 'Carga Inicial',
|
||||
width: width*0.6,
|
||||
),
|
||||
SizedBox(height: 10),
|
||||
TextDefault(text: error,color: ColorPalette.red),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user