Device info package eltávolítva, google megszorítás miatt.
Helyette UUID használva.
This commit is contained in:
parent
8ea1190b4c
commit
af41592029
|
|
@ -22,6 +22,7 @@ import 'package:simple_barcode_scanner/simple_barcode_scanner.dart';
|
|||
import 'dart:io';
|
||||
import 'package:qr_flutter/qr_flutter.dart';
|
||||
import 'package:lite_rolling_switch/lite_rolling_switch.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
//AutoUpdateApk aua = new AutoUpdateApk(getApplicationContext(), UPDATE_URL);
|
||||
|
||||
|
||||
|
|
@ -68,8 +69,9 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
String currentWorkState="";
|
||||
QRCodeModel currentQRcode=QRCodeModel();
|
||||
WorkStateModel workState=WorkStateModel();
|
||||
late EmployeeArguments ea;
|
||||
EmployeeArguments? ea;
|
||||
EmployeePageArguments employeePageArgs = EmployeePageArguments();
|
||||
|
||||
//device_info.DeviceInfo di=device_info.DeviceInfo();
|
||||
//late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin;
|
||||
//var deviceData = <String, dynamic>{};
|
||||
|
|
@ -148,19 +150,19 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
setState(() {
|
||||
_reportButtonDisabled = false;
|
||||
});
|
||||
if (ea.mobilePortalAccessEnabled == false) {
|
||||
if (ea?.mobilePortalAccessEnabled == false) {
|
||||
_showAccessDeniedDialog();
|
||||
}
|
||||
employeePageArgs = EmployeePageArguments(
|
||||
name: ea.name,
|
||||
id: ea.id,
|
||||
name: ea?.name,
|
||||
id: ea?.id,
|
||||
apiKey: userApiKey,
|
||||
isForeman: ea.isForeman,
|
||||
mobilePortalAccessEnabled: ea.mobilePortalAccessEnabled);
|
||||
isForeman: ea?.isForeman,
|
||||
mobilePortalAccessEnabled: ea?.mobilePortalAccessEnabled);
|
||||
setState(() {
|
||||
_reportButtonDisabled = !ea.isForeman!;
|
||||
_reportButtonDisabled = employeePageArgs.isForeman!;
|
||||
});
|
||||
if (ea.id!.isNotEmpty) {
|
||||
if (employeePageArgs.id!.isNotEmpty) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -186,6 +188,7 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
}
|
||||
Future<bool> getDeviceUUID() async{
|
||||
storage.SecureStorage sc= storage.SecureStorage();
|
||||
|
||||
deviceUUID1= await sc.readSecureData('UUID1');
|
||||
deviceUUID2= await sc.readSecureData('UUID2');
|
||||
if (deviceUUID1!.startsWith("No data found!") || deviceUUID2!.startsWith("No data found!")) {
|
||||
|
|
@ -195,8 +198,23 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> _checkUUIDS() async {
|
||||
storage.SecureStorage sc= storage.SecureStorage();
|
||||
//sc.deleteSecureData('API');
|
||||
bool resAPI= await storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API');
|
||||
bool resUUID1= await storage.SecureStorage().checkContainsKey('UUID1') ;
|
||||
bool resUUID2= await storage.SecureStorage().checkContainsKey('UUID2') ;
|
||||
if (resAPI==false || resUUID1==false || resUUID2==false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Future<void> _registerDevicePage() async {
|
||||
|
||||
}
|
||||
@override
|
||||
void initState() {
|
||||
void initState() {
|
||||
// TODO: implement initStateA
|
||||
super.initState();
|
||||
SystemChrome.setPreferredOrientations([
|
||||
|
|
@ -204,78 +222,71 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
|
||||
getDeviceUUID().then((value)
|
||||
//di.initPlatformState().then((value)
|
||||
{
|
||||
// deviceData = value;
|
||||
if (value==false) {
|
||||
Navigator.pushNamed(context, '/register', arguments: DeviceArguments(
|
||||
//deviceData['id'], deviceData['device'], deviceData['brand'])).then((value)
|
||||
"", "", ""));
|
||||
}
|
||||
//checkApiKey();
|
||||
//saveApiKey();
|
||||
storage.SecureStorage sc= storage.SecureStorage();
|
||||
//sc.deleteSecureData('API');
|
||||
Future<bool> res= storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API');
|
||||
res.then((value) {
|
||||
//Future<bool> resAPI= storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API');
|
||||
//Future<bool> resUUID1= storage.SecureStorage().checkContainsKey('UUID1') ;
|
||||
//Future<bool> resUUID2= storage.SecureStorage().checkContainsKey('UUID2') ;
|
||||
|
||||
//_isApiKeyValid=value;
|
||||
//apiKeyValid=value;
|
||||
if (value==false)
|
||||
_checkUUIDS().then((val){
|
||||
if (val==false)
|
||||
{
|
||||
Navigator.pushNamed(context, '/register', arguments: DeviceArguments(
|
||||
//deviceData['id'], deviceData['device'], deviceData['brand'])).then((value)
|
||||
deviceUUID1!, deviceUUID2!, deviceBrand!)).then((value)
|
||||
{
|
||||
Future<String> userApiKey=sc.readSecureData("API");
|
||||
userApiKey.then((apiKey) => checkApiKeyValidity(apiKey).then((apiKeyState) {
|
||||
// print("API key State: $apiKeyState");
|
||||
|
||||
setState(() {
|
||||
_isApiKeyValid = apiKeyState;
|
||||
if (ea.isForeman==true)
|
||||
{
|
||||
_reportButtonDisabled=false;
|
||||
}
|
||||
if (ea.mobilePortalAccessEnabled==true)
|
||||
{
|
||||
NfcManager.instance.isAvailable().then((nfcState){
|
||||
if (_isApiKeyValid && !_isLocationMocked)
|
||||
{
|
||||
_showNFClogo=true;
|
||||
_tagRead();
|
||||
Navigator.pushNamed(
|
||||
context, '/register', arguments: DeviceArguments(
|
||||
//deviceData['id'], deviceData['device'], deviceData['brand'])).then((value)
|
||||
//deviceUUID1!, deviceUUID2!, deviceBrand!)).then((value) {
|
||||
"", "", "")).then((value) {
|
||||
Future<String> userApiKey = sc.readSecureData("API");
|
||||
userApiKey.then((apiKey) =>
|
||||
checkApiKeyValidity(apiKey).then((apiKeyState) {
|
||||
// print("API key State: $apiKeyState");
|
||||
|
||||
setState(() {
|
||||
_isApiKeyValid = apiKeyState;
|
||||
if (ea?.isForeman == true) {
|
||||
_reportButtonDisabled = false;
|
||||
}
|
||||
if (ea?.mobilePortalAccessEnabled == true) {
|
||||
NfcManager.instance.isAvailable().then((nfcState) {
|
||||
if (_isApiKeyValid && !_isLocationMocked) {
|
||||
_showNFClogo = true;
|
||||
_tagRead();
|
||||
}
|
||||
else {
|
||||
_showNFClogo = false;
|
||||
}
|
||||
});
|
||||
getWorkState(apiKey);
|
||||
getQRCode(apiKey);
|
||||
}
|
||||
_getLocation();
|
||||
// _getCurrentLocation();
|
||||
_isApiKeyValid = apiKeyState;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_showNFClogo=false;
|
||||
}
|
||||
} );
|
||||
getWorkState(apiKey);
|
||||
getQRCode(apiKey);
|
||||
}
|
||||
_getLocation();
|
||||
// _getCurrentLocation();
|
||||
_isApiKeyValid = apiKeyState;
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
getDeviceUUID();
|
||||
Future<String> userApiKey=sc.readSecureData("API");
|
||||
userApiKey.then((apiKey) => checkApiKeyValidity(apiKey).then((apiKeyState) {
|
||||
// print("API key State: $apiKeyState");
|
||||
|
||||
setState(() {
|
||||
_isApiKeyValid = apiKeyState;
|
||||
if (ea.isForeman==true)
|
||||
if (ea == null) return;
|
||||
if (ea?.isForeman==true)
|
||||
{
|
||||
_reportButtonDisabled=false;
|
||||
}
|
||||
if (ea.mobilePortalAccessEnabled==true)
|
||||
if (ea?.mobilePortalAccessEnabled==true)
|
||||
{
|
||||
NfcManager.instance.isAvailable().then((nfcState){
|
||||
if (_isApiKeyValid && !_isLocationMocked)
|
||||
|
|
@ -300,12 +311,12 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
//sc.writeSecureData("API", deviceData['id']);
|
||||
//sc.checkContainsKey('API');
|
||||
//sc.readSecureData("API");
|
||||
});
|
||||
//);
|
||||
|
||||
_getLocation();
|
||||
PackageInfo.fromPlatform().then((value) => {
|
||||
|
|
@ -355,6 +366,34 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
}
|
||||
}
|
||||
|
||||
/*Future<void> _showMyDialog(String message1) async {
|
||||
return showDialog<void>(
|
||||
context: context,
|
||||
barrierDismissible: false, // user must tap button!
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('Figyelmeztetés'),
|
||||
content: const SingleChildScrollView(
|
||||
child: ListBody(
|
||||
children: <Widget>[
|
||||
Text(message1 as String),
|
||||
Text('Would you like to approve of this message?'),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('Bezár'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}*/
|
||||
|
||||
|
||||
Widget nfcLogo() {
|
||||
if (_location?.isMock==true) {
|
||||
|
|
@ -380,48 +419,17 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
);
|
||||
}
|
||||
}
|
||||
Future _scanQR() async {
|
||||
/*try {
|
||||
String qrResult = await BarcodeScanner.scan();
|
||||
setState(() {
|
||||
_login(qrResult);
|
||||
/* result = qrResult;
|
||||
TcpClient a = new TcpClient(socket, 'iotechnic.eu', 8080);
|
||||
|
||||
_getId();
|
||||
a.sendAccess(
|
||||
deviceId,
|
||||
result,
|
||||
_currentAddress,
|
||||
_currentPosition.latitude.toString(),
|
||||
_currentPosition.longitude.toString());*/
|
||||
});
|
||||
} on PlatformException catch (ex) {
|
||||
if (ex.code == BarcodeScanner.CameraAccessDenied) {
|
||||
setState(() {
|
||||
result = "Camera permission was denied";
|
||||
});
|
||||
} else {
|
||||
setState(() {
|
||||
result = "Unknown Error $ex";
|
||||
});
|
||||
}
|
||||
} on FormatException {
|
||||
setState(() {
|
||||
result = "You pressed the back button before scanning anything";
|
||||
});
|
||||
} catch (ex) {
|
||||
setState(() {
|
||||
result = "Unknown Error $ex";
|
||||
});
|
||||
}*/
|
||||
}
|
||||
_loginQR(qrCode) {
|
||||
_loginQR(qrCode) async {
|
||||
setState(() {
|
||||
_showNFClogo = false;
|
||||
});
|
||||
//DeviceInfo devInfo = _getDeviceInfo() as DeviceInfo;
|
||||
|
||||
bool r=await getDeviceUUID();
|
||||
if (!r) return;
|
||||
// _showMyDialog();
|
||||
//DeviceInfo devInfo = _getDeviceInfo() as DeviceInfo;
|
||||
_getLocation();
|
||||
String indexRequest = '{'
|
||||
'"cmd":"ACCESSNOGEOQR",'
|
||||
'"CID1":"$deviceUUID1",' //$"{deviceData['id']}",'
|
||||
|
|
@ -497,12 +505,13 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
socket.flush();
|
||||
});
|
||||
}
|
||||
_login(rfid) {
|
||||
_login(rfid) async {
|
||||
setState(() {
|
||||
_showNFClogo = false;
|
||||
});
|
||||
//DeviceInfo devInfo = _getDeviceInfo() as DeviceInfo;
|
||||
|
||||
bool r=await getDeviceUUID();
|
||||
if (!r) return;
|
||||
String indexRequest = '{'
|
||||
'"cmd":"ACCESSNOGEO",'
|
||||
// '"CID1":"${deviceData['id']}",'
|
||||
|
|
@ -581,30 +590,6 @@ class _MainPageState extends State<MainPage> with TickerProviderStateMixin{
|
|||
});
|
||||
}
|
||||
|
||||
/*Future<void> _showNotification() async {
|
||||
var dateTime = DateTime(DateTime.now().year, DateTime.now().month,
|
||||
DateTime.now().day, 10, 46, 0);
|
||||
const AndroidNotificationDetails androidNotificationDetails =
|
||||
AndroidNotificationDetails('your channel id', 'your channel name',
|
||||
channelDescription: 'your channel description',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
ticker: 'ticker');
|
||||
const NotificationDetails notificationDetails =
|
||||
NotificationDetails(android: androidNotificationDetails);
|
||||
/*await flutterLocalNotificationsPlugin.show(
|
||||
1234, 'plain title', 'plain body', notificationDetails,
|
||||
payload: 'item x');*/
|
||||
await flutterLocalNotificationsPlugin.zonedSchedule(
|
||||
0,
|
||||
'title',
|
||||
'body',
|
||||
tz.TZDateTime.from(dateTime, tz.local),
|
||||
notificationDetails,
|
||||
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
|
||||
matchDateTimeComponents: DateTimeComponents.time);
|
||||
}*/
|
||||
|
||||
_getAddressFromLatLng(lat,lon) async {
|
||||
try {
|
||||
List<geocoding.Placemark> placemarks = await geocoding.placemarkFromCoordinates(
|
||||
|
| ||||