From 5c818643db0414cc341323439c006714d2ccf7f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincze=20J=C3=B3zsef?= Date: Mon, 20 Jan 2025 16:27:24 +0100 Subject: [PATCH] =?UTF-8?q?Napi=20jelent=C3=A9s=20bet=C3=B6lt=C5=91d=C3=A9?= =?UTF-8?q?s=20jav=C3=ADtva?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/main_page.dart | 365 ++++++++++++++++++---------------- lib/report_selectWork.dart | 10 +- lib/services/device_info.dart | 4 +- lib/widgets/reportList.dart | 13 +- pubspec.yaml | 4 +- 5 files changed, 205 insertions(+), 191 deletions(-) diff --git a/lib/main_page.dart b/lib/main_page.dart index 81c6e91..3594d5d 100644 --- a/lib/main_page.dart +++ b/lib/main_page.dart @@ -22,7 +22,6 @@ 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); @@ -69,9 +68,8 @@ class _MainPageState extends State with TickerProviderStateMixin{ String currentWorkState=""; QRCodeModel currentQRcode=QRCodeModel(); WorkStateModel workState=WorkStateModel(); - EmployeeArguments? ea; + late EmployeeArguments ea; EmployeePageArguments employeePageArgs = EmployeePageArguments(); - //device_info.DeviceInfo di=device_info.DeviceInfo(); //late FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin; //var deviceData = {}; @@ -150,19 +148,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 = employeePageArgs.isForeman!; + _reportButtonDisabled = !ea.isForeman!; }); - if (employeePageArgs.id!.isNotEmpty) { + if (ea.id!.isNotEmpty) { return true; } else { return false; @@ -188,7 +186,6 @@ 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!")) { @@ -198,23 +195,8 @@ 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([ @@ -222,71 +204,78 @@ 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 resAPI= storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API'); - //Future resUUID1= storage.SecureStorage().checkContainsKey('UUID1') ; - //Future resUUID2= storage.SecureStorage().checkContainsKey('UUID2') ; - + Future res= storage.SecureStorage().checkContainsKey('API');// sc.checkContainsKey('API'); + res.then((value) { //_isApiKeyValid=value; //apiKeyValid=value; - _checkUUIDS().then((val){ - if (val==false) + if (value==false) { - - Navigator.pushNamed( - context, '/register', arguments: DeviceArguments( + 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"); + 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(); - } - else { - _showNFClogo = false; - } - }); - getWorkState(apiKey); - getQRCode(apiKey); - } - _getLocation(); - // _getCurrentLocation(); - _isApiKeyValid = 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 { - getDeviceUUID(); + Future userApiKey=sc.readSecureData("API"); userApiKey.then((apiKey) => checkApiKeyValidity(apiKey).then((apiKeyState) { // print("API key State: $apiKeyState"); setState(() { _isApiKeyValid = apiKeyState; - if (ea == null) return; - if (ea?.isForeman==true) + if (ea.isForeman==true) { _reportButtonDisabled=false; } - if (ea?.mobilePortalAccessEnabled==true) + if (ea.mobilePortalAccessEnabled==true) { NfcManager.instance.isAvailable().then((nfcState){ if (_isApiKeyValid && !_isLocationMocked) @@ -311,12 +300,12 @@ class _MainPageState extends State with TickerProviderStateMixin{ ); } - }); + //sc.writeSecureData("API", deviceData['id']); //sc.checkContainsKey('API'); //sc.readSecureData("API"); - //); + }); _getLocation(); PackageInfo.fromPlatform().then((value) => { @@ -366,34 +355,6 @@ 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) { @@ -419,17 +380,48 @@ 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); - _loginQR(qrCode) async { + _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) { setState(() { _showNFClogo = false; }); - - bool r=await getDeviceUUID(); - if (!r) return; - // _showMyDialog(); //DeviceInfo devInfo = _getDeviceInfo() as DeviceInfo; - _getLocation(); + String indexRequest = '{' '"cmd":"ACCESSNOGEOQR",' '"CID1":"$deviceUUID1",' //$"{deviceData['id']}",' @@ -505,13 +497,12 @@ class _MainPageState extends State with TickerProviderStateMixin{ socket.flush(); }); } - _login(rfid) async { + _login(rfid) { setState(() { _showNFClogo = false; }); //DeviceInfo devInfo = _getDeviceInfo() as DeviceInfo; - bool r=await getDeviceUUID(); - if (!r) return; + String indexRequest = '{' '"cmd":"ACCESSNOGEO",' // '"CID1":"${deviceData['id']}",' @@ -590,6 +581,30 @@ 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( @@ -679,72 +694,75 @@ class _MainPageState extends State with TickerProviderStateMixin{ style: const TextStyle(fontSize: 24.0), textAlign: TextAlign.center, ), - content: SingleChildScrollView( - padding: const EdgeInsets.all(8.0), - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisSize: MainAxisSize.min, - children: [ + content: Container( + //height: 400, + child: 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); - }, + 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: 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: () { + 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'}'); + } + }, + 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); + }, + ),*/ + ), + ], + ), ), ), ); @@ -840,7 +858,7 @@ class _MainPageState extends State with TickerProviderStateMixin{ Padding( padding: const EdgeInsets.all(14.0), - child: _initOK || _loading + child: _initOK ? Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, @@ -857,7 +875,7 @@ class _MainPageState extends State with TickerProviderStateMixin{ Column( children: [ - Text(currentWorkState), + Text(currentWorkState ?? ""), Text(currentQRcode.name ?? "", style: const TextStyle( fontSize: 16, @@ -1037,8 +1055,7 @@ class _MainPageState extends State with TickerProviderStateMixin{ fontWeight: FontWeight.bold), ), Text( - 'Location: ${_error ?? result}', - // result, + result, style: const TextStyle( color: Colors.white, fontSize: 30.0, diff --git a/lib/report_selectWork.dart b/lib/report_selectWork.dart index 3ecb56b..2b0192d 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 workList2 = []; + List workList = []; if (_showFaworites) { - workList2 = workList + workList = workList .where((element) => favoriteWorks.contains(element.sId)) .toList(); } else { - workList2 = workList; + workList = workList; } return Container( color: const Color(0xffECF0F1), child: ListView.builder( - itemCount: workList2.length, // The length Of the array + itemCount: workList.length, // The length Of the array padding: const EdgeInsets.all(5), shrinkWrap: true, itemBuilder: (context, index) => Container( - child: reportCard(context, workList2[index]), + child: reportCard(context, workList[index]), ), ), ); diff --git a/lib/services/device_info.dart b/lib/services/device_info.dart index 4922d99..914e101 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 2f6b94f..68b0ea0 100644 --- a/lib/widgets/reportList.dart +++ b/lib/widgets/reportList.dart @@ -50,9 +50,8 @@ class _dailyReportListState extends State { for (var item in data) { reportList.add(ModelReportList.fromJson(item)); } - + _isData = true; setState(() { - _isData = true; debugPrint('Fetch ok.'); }); } else { @@ -211,25 +210,25 @@ Container page(BuildContext context) { } Container gridList(BuildContext context) { - List reportList2 = []; + List reportList = []; if (_showFaworites) { - reportList2 = reportList + reportList = reportList .where((element) => favoriteWorks.contains(element.sId)) .toList(); } else { - reportList2 = reportList; + reportList = reportList; } return Container( color: const Color(0xffECF0F1), child: ListView.builder( - itemCount: reportList2.length, // The length Of the array + itemCount: reportList.length, // The length Of the array padding: const EdgeInsets.all(5), shrinkWrap: true, itemBuilder: (context, index) => Container( child: reportCardWidget( - reportList2[index]) //reportCard(context, _reportList[index]), + reportList[index]) //reportCard(context, _reportList[index]), ), ), ); diff --git a/pubspec.yaml b/pubspec.yaml index 0b2d80b..e7898b7 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.4+1 +version: 1.0.3+1 environment: sdk: '>=3.2.0 <4.0.0' @@ -56,8 +56,6 @@ 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: