import 'dart:async'; import 'dart:convert'; import 'dart:io'; import 'package:flutter/material.dart'; import 'package:unit2/model/login_data/user_info/user_data.dart'; import 'package:unit2/model/login_data/version_info.dart'; import 'package:http/http.dart' as http; import 'package:unit2/utils/request.dart'; import '../../utils/text_container.dart'; import '../../utils/urls.dart'; class AuthService { static final AuthService _instance = AuthService(); static AuthService get instance => _instance; Future getVersionInfo() async { VersionInfo versionInfo = VersionInfo(); Map headers = { 'Content-Type': 'application/json; charset=UTF-8', HttpHeaders.authorizationHeader: 'UniT2', 'X-User': "" }; try { http.Response response = await http.get( Uri.https('unitylb1.agusandelnorte.gov.ph', '/unit2/api/sys/apk_version/latest/'), headers: headers); if (response.statusCode == 200) { Map data = jsonDecode(response.body); versionInfo = VersionInfo.fromJson(data['data']); } } on TimeoutException catch (_) { throw (timeoutError); } on SocketException catch (_) { throw (timeoutError); } catch (e) { throw (e.toString()); } return versionInfo; } Future webLogin({String? username, String? password})async{ Map body ={'username':username!,'password':password!}; Map baseHeaders = { 'Content-Type': 'application/json' }; String path = Url.instance.authentication(); UserData? userData; try{ http.Response response = await Request.instance.postRequest(path: path,param: {},headers: baseHeaders,body: body); if(response.statusCode == 200){ Map data = jsonDecode(response.body); userData = UserData.fromJson(data['data']); } }catch(e){ throw (e.toString()); } return userData!; } Future qrLogin({String? uuid, String? password})async{ Map body ={'uuid':uuid!,'password':password!}; Map baseHeaders = { 'Content-Type': 'application/json' }; String path = Url.instance.authentication(); UserData? userData; try{ http.Response response = await Request.instance.postRequest(path: path,param: {},headers: baseHeaders,body: body); if(response.statusCode == 200){ Map data = jsonDecode(response.body); userData = UserData.fromJson(data['data']); } }catch(e){ throw (e.toString()); } return userData!; } }