From af41592029339f1cecf3c3670e9a665a97c30b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincze=20J=C3=B3zsef?= Date: Mon, 20 Jan 2025 16:26:06 +0100 Subject: [PATCH] =?UTF-8?q?Device=20info=20package=20elt=C3=A1vol=C3=ADtva?= =?UTF-8?q?,=20google=20megszor=C3=ADt=C3=A1s=20miatt.=20Helyette=20UUID?= =?UTF-8?q?=20haszn=C3=A1lva.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main_page.dart | 367 ++++++++++++++++------------------ lib/report_selectWork.dart | 10 +- lib/services/device_info.dart | 4 +- lib/widgets/reportList.dart | 13 +- pubspec.yaml | 4 +- 5 files changed, 192 insertions(+), 206 deletions(-) diff --git a/lib/main_page.dart b/lib/main_page.dart index 3594d5d..81c6e91 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -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 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 = {}; @@ -148,19 +150,19 @@ class _MainPageState extends State 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 with TickerProviderStateMixin{ } Future 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 with TickerProviderStateMixin{ } } + Future _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 _registerDevicePage() async { + + } @override - void initState() { + void initState() { // TODO: implement initStateA super.initState(); SystemChrome.setPreferredOrientations([ @@ -204,78 +222,71 @@ class _MainPageState extends State 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 res= storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API'); - res.then((value) { + //Future resAPI= storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API'); + //Future resUUID1= storage.SecureStorage().checkContainsKey('UUID1') ; + //Future 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 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 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 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 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 with TickerProviderStateMixin{ } } + /*Future _showMyDialog(String message1) async { + return showDialog( + context: context, + barrierDismissible: false, // user must tap button! + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Figyelmeztetés'), + content: const SingleChildScrollView( + child: ListBody( + children: [ + Text(message1 as String), + Text('Would you like to approve of this message?'), + ], + ), + ), + actions: [ + 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 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 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 with TickerProviderStateMixin{ }); } - /*Future _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 placemarks = await geocoding.placemarkFromCoordinates( @@ -694,75 +679,72 @@ class _MainPageState extends State with TickerProviderStateMixin{ style: const TextStyle(fontSize: 24.0), textAlign: TextAlign.center, ), - content: Container( - //height: 400, - child: SingleChildScrollView( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ + content: SingleChildScrollView( + padding: const EdgeInsets.all(8.0), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisSize: MainAxisSize.min, + children: [ - Container( - padding: const EdgeInsets.all(8.0), + Container( + padding: const EdgeInsets.all(8.0), - child: qrdata.isNotEmpty ? QrImageView( - data: qrdata, - version: QrVersions.auto, - size: 200.0, - embeddedImageEmitsError: true, - ) - : const Text('HIBA!'), - ), - Container( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - child: const Text('Bezár'), - onPressed: () { - Navigator.pop(context); - }, - ), - ), - Container( - padding: const EdgeInsets.all(8.0), - child: LiteRollingSwitch( - value: _WorkTimeState, - width: 200, - textOn: currentWorkState, - textOff: currentWorkState, - colorOn: Colors.deepOrange, - colorOff: Colors.blueGrey, - iconOn: Icons.work, - iconOff: Icons.work_off, - animationDuration: const Duration(milliseconds: 300), - onChanged: (bool state) { - if (kDebugMode) { - print('turned ${(state) ? 'on' : 'off'}'); - } + child: qrdata.isNotEmpty ? QrImageView( + data: qrdata, + version: QrVersions.auto, + size: 200.0, + embeddedImageEmitsError: true, + ) + : const Text('HIBA!'), + ), + Container( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + child: const Text('Bezár'), + onPressed: () { + Navigator.pop(context); }, - onDoubleTap: () {}, - onSwipe: () { - if (kDebugMode) { - print('Swiped!'); - } + ), + ), + Container( + padding: const EdgeInsets.all(8.0), + child: LiteRollingSwitch( + value: _WorkTimeState, + width: 200, + textOn: currentWorkState, + textOff: currentWorkState, + colorOn: Colors.deepOrange, + colorOff: Colors.blueGrey, + iconOn: Icons.work, + iconOff: Icons.work_off, + animationDuration: const Duration(milliseconds: 300), + onChanged: (bool state) { + if (kDebugMode) { + print('turned ${(state) ? 'on' : 'off'}'); + } + }, + onDoubleTap: () {}, + onSwipe: () { + if (kDebugMode) { + print('Swiped!'); + } + _loginQR(currentQRcode.qrCode); + Navigator.pop(context); + }, + onTap: () {}, + ), + /*ElevatedButton( + child: currentWorkState.compareTo('DOLGOZIK')==0 + ?const Text('Munkaidő befejezés', style: TextStyle(fontSize: 16)) + :const Text('Munkaidő kezdés', style: TextStyle(fontSize: 16),), + onPressed: () { _loginQR(currentQRcode.qrCode); Navigator.pop(context); }, - onTap: () {}, - ), - /*ElevatedButton( - child: currentWorkState.compareTo('DOLGOZIK')==0 - ?const Text('Munkaidő befejezés', style: TextStyle(fontSize: 16)) - :const Text('Munkaidő kezdés', style: TextStyle(fontSize: 16),), - onPressed: () { - _loginQR(currentQRcode.qrCode); - Navigator.pop(context); - }, - ),*/ - ), - ], - ), + ),*/ + ), + ], ), ), ); @@ -858,7 +840,7 @@ class _MainPageState extends State with TickerProviderStateMixin{ Padding( padding: const EdgeInsets.all(14.0), - child: _initOK + child: _initOK || _loading ? Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, @@ -875,7 +857,7 @@ class _MainPageState extends State with TickerProviderStateMixin{ Column( children: [ - Text(currentWorkState ?? ""), + Text(currentWorkState), Text(currentQRcode.name ?? "", style: const TextStyle( fontSize: 16, @@ -1055,7 +1037,8 @@ class _MainPageState extends State with TickerProviderStateMixin{ fontWeight: FontWeight.bold), ), Text( - result, + 'Location: ${_error ?? result}', + // result, style: const TextStyle( color: Colors.white, fontSize: 30.0, diff --git a/lib/report_selectWork.dart b/lib/report_selectWork.dart index 2b0192d..3ecb56b 100644 --- a/lib/report_selectWork.dart +++ b/lib/report_selectWork.dart @@ -109,24 +109,24 @@ class _reportCreateState extends State { Container gridList(BuildContext context) { //List _reportList = []; - List workList = []; + List workList2 = []; if (_showFaworites) { - workList = workList + workList2 = workList .where((element) => favoriteWorks.contains(element.sId)) .toList(); } else { - workList = workList; + workList2 = workList; } return Container( color: const Color(0xffECF0F1), child: ListView.builder( - itemCount: workList.length, // The length Of the array + itemCount: workList2.length, // The length Of the array padding: const EdgeInsets.all(5), shrinkWrap: true, itemBuilder: (context, index) => Container( - child: reportCard(context, workList[index]), + child: reportCard(context, workList2[index]), ), ), ); diff --git a/lib/services/device_info.dart b/lib/services/device_info.dart index 914e101..4922d99 100644 --- a/lib/services/device_info.dart +++ b/lib/services/device_info.dart @@ -1,4 +1,4 @@ -import 'package:device_info_plus/device_info_plus.dart'; +/*import 'package:device_info_plus/device_info_plus.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; @@ -180,4 +180,4 @@ class DeviceInfo{ 'deviceId': data.deviceId, }; } -} +}*/ diff --git a/lib/widgets/reportList.dart b/lib/widgets/reportList.dart index 68b0ea0..2f6b94f 100644 --- a/lib/widgets/reportList.dart +++ b/lib/widgets/reportList.dart @@ -50,8 +50,9 @@ class _dailyReportListState extends State { for (var item in data) { reportList.add(ModelReportList.fromJson(item)); } - _isData = true; + setState(() { + _isData = true; debugPrint('Fetch ok.'); }); } else { @@ -210,25 +211,25 @@ Container page(BuildContext context) { } Container gridList(BuildContext context) { - List reportList = []; + List reportList2 = []; if (_showFaworites) { - reportList = reportList + reportList2 = reportList .where((element) => favoriteWorks.contains(element.sId)) .toList(); } else { - reportList = reportList; + reportList2 = reportList; } return Container( color: const Color(0xffECF0F1), child: ListView.builder( - itemCount: reportList.length, // The length Of the array + itemCount: reportList2.length, // The length Of the array padding: const EdgeInsets.all(5), shrinkWrap: true, itemBuilder: (context, index) => Container( child: reportCardWidget( - reportList[index]) //reportCard(context, _reportList[index]), + reportList2[index]) //reportCard(context, _reportList[index]), ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index e7898b7..0b2d80b 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.3+1 +version: 1.0.4+1 environment: sdk: '>=3.2.0 <4.0.0' @@ -56,6 +56,8 @@ dependencies: lite_rolling_switch: ^1.0.1 permission_handler: ^11.3.1 uuid: ^4.4.2 + fluttertoast: ^8.1.1 + #flutter_local_notifications: ^17.1.2 dev_dependencies: