diff --git a/README.md b/README.md index 7cef7673274fbb17de83613703c6fa1b993a6ce1..6c1d17266d846fb33002a2abbb76f8f0f0796827 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ samples, guidance on mobile development, and a full API reference. ## Configuration Details -* Flutter 2.10.3 • channel stable • https://github.com/flutter/flutter.git -* Framework • revision 7e9793dee1 (2 weeks ago) • 2022-03-02 11:23:12 -0600 -* Engine • revision bd539267b4 -* Tools • Dart 2.16.1 • DevTools 2.9.2 +* Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git +* Framework • revision c860cba910 (12 days ago) • 2022-03-25 00:23:12 -0500 +* Engine • revision 57d3bac3dd +* Tools • Dart 2.16.2 • DevTools 2.9.2 diff --git a/lib/constants/api_endpoints.dart b/lib/constants/api_endpoints.dart index 9255dc199a1b7d27200aa9a2406056c1b6a6d6b9..e1773c915e9ab0245d09fe35cc2e613596868e2f 100644 --- a/lib/constants/api_endpoints.dart +++ b/lib/constants/api_endpoints.dart @@ -15,4 +15,6 @@ class ApiUrl { static const getAllForms = '$baseUrl/api/forms/getAllForms?isDetail=true'; static const fileUpload = '$baseUrl/api/forms/fileUpload'; static const deleteFile = '$baseUrl/api/forms/deleteCloudFile'; + static const deleteDeviceToken = + '$baseUrl/api/user/deleteDeviceToken?deviceId='; } diff --git a/lib/constants/app_constants.dart b/lib/constants/app_constants.dart index 34c32dc49d7e73836cb24780a257a8acb7f88c29..1e46751271b25eaa6376a1b96aeb2eaed0b17fc7 100644 --- a/lib/constants/app_constants.dart +++ b/lib/constants/app_constants.dart @@ -1,4 +1,4 @@ -const String appVersion = '1.0'; +const String appVersion = '1.3'; const String appName = 'UP SMF'; const int inspectorRoleId = 2093; @@ -52,6 +52,7 @@ class Storage { static const String lastname = 'smf_user_last_name'; static const String authtoken = 'smf_user_auth_token'; static const String applicationId = 'smf_application_id'; + static const String deviceIdentifier = 'smf_device_identifier'; } class Inspector { diff --git a/lib/main.dart b/lib/main.dart index 3e5d5dac11f3897019b3e0056ee7585a7ac2437c..9d7b5bdb8b86e32a278e28981c6cb4363458d796 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -10,3 +10,4 @@ void main() { }, )); } + \ No newline at end of file diff --git a/lib/pages/home_page.dart b/lib/pages/home_page.dart index 05c79cc87c0d4072aea7417ede560622151db4f6..f7b19c6f19d5e116427216280837a04e1f535a3a 100644 --- a/lib/pages/home_page.dart +++ b/lib/pages/home_page.dart @@ -133,9 +133,10 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver { // await Future.delayed(const Duration(milliseconds: 10)); if (isInternetConnected) { _validateUser(); - _getForms(); - _syncApplications(); + await _getForms(); + await _syncApplications(); } + _allApplications = await Provider.of<ApplicationRespository>(context, listen: false) .getApplications(isInternetConnected); diff --git a/lib/repositories/application_repository.dart b/lib/repositories/application_repository.dart index 9fc3d05720c39726cb881c1f6f28c9b9bdd2532a..9fe111178face44dafebc20da0eb294dcbd925fe 100644 --- a/lib/repositories/application_repository.dart +++ b/lib/repositories/application_repository.dart @@ -100,7 +100,9 @@ class ApplicationRespository with ChangeNotifier { bool response = false; List<Map> attachments = []; try { + // await OfflineModel.deleteInspections(); List<Map> rawInspections = await OfflineModel.getInspections(); + // print(rawInspections); for (var inspection in rawInspections) { Map inspectionData = jsonDecode(inspection['inspection_data']); attachments = @@ -118,11 +120,14 @@ class ApplicationRespository with ChangeNotifier { consents.add(inspectionData); } } + // print('inspections: ' + inspections.toString()); + // print('concents: ' + consents.toString()); if (inspections.isNotEmpty) { final request1 = await ApplicationService.submitBulkInspection(inspections); data1 = json.decode(request1.body); } + if (consents.isNotEmpty) { final request2 = await ApplicationService.submitBulkConsent(consents); data2 = json.decode(request2.body); @@ -154,7 +159,7 @@ class ApplicationRespository with ChangeNotifier { if (!internetConnected) { Map<String, Object> applicationData = { 'inspector_type': Inspector.assistantInspector, - 'inspection_data': data + 'inspection_data': json.encode(data) }; await OfflineModel.saveInspection(applicationData); diff --git a/lib/repositories/login_repository.dart b/lib/repositories/login_repository.dart index bbcdfacdb9140d5eb3efdb01c1494929d164fdad..15216c55dac23979745ec815882bc527111edc3e 100644 --- a/lib/repositories/login_repository.dart +++ b/lib/repositories/login_repository.dart @@ -8,6 +8,7 @@ import 'package:smf_mobile/landing_page.dart'; import 'package:smf_mobile/models/login_model.dart'; import 'package:flutter_secure_storage/flutter_secure_storage.dart'; import 'package:smf_mobile/services/login_service.dart'; +import 'package:smf_mobile/util/helper.dart'; // import 'package:smf_mobile/util/notification_helper.dart'; class LoginRespository with ChangeNotifier { @@ -74,6 +75,7 @@ class LoginRespository with ChangeNotifier { _storage.write(key: Storage.firstname, value: _loginDetails.firstName); _storage.write(key: Storage.lastname, value: _loginDetails.lastName); _storage.write(key: Storage.authtoken, value: _loginDetails.authToken); + _storage.write(key: Storage.deviceIdentifier, value: identifier); _firebaseMessaging.getToken().then((token) async { final request = await LoginService.updateUserDeviceToken( token.toString(), @@ -92,16 +94,16 @@ class LoginRespository with ChangeNotifier { } void _configureMessaging(context) async { - NotificationSettings settings = await _firebaseMessaging.requestPermission( - alert: true, - announcement: false, - badge: true, - carPlay: false, - criticalAlert: false, - provisional: false, - sound: true, - ); - print('User granted permission: ${settings.authorizationStatus}'); + // NotificationSettings settings = await _firebaseMessaging.requestPermission( + // alert: true, + // announcement: false, + // badge: true, + // carPlay: false, + // criticalAlert: false, + // provisional: false, + // sound: true, + // ); + // print('User granted permission: ${settings.authorizationStatus}'); FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); @@ -114,6 +116,10 @@ class LoginRespository with ChangeNotifier { } Future<void> clearData() async { + String deviceIdentifier = await Helper.getUser(Storage.deviceIdentifier); + // print(deviceIdentifier); + await LoginService.deleteDeviceToken(deviceIdentifier); + // print(request.body); await _storage.deleteAll(); } diff --git a/lib/services/application_service.dart b/lib/services/application_service.dart index fbb5fb580a9342b23b1482eee38cef0172515890..2020ae4cd2bb8ff0b6d667eeaf2751d440f22b77 100644 --- a/lib/services/application_service.dart +++ b/lib/services/application_service.dart @@ -64,7 +64,7 @@ class ApplicationService extends BaseService { final response = await http.post(Uri.parse(ApiUrl.submitBulkConcent), headers: headers, body: body); - // developer.log(ApiUrl.submitInspection); + // developer.log(ApiUrl.submitBulkConcent); // developer.log(body); // developer.log(response.body); return response; diff --git a/lib/services/login_service.dart b/lib/services/login_service.dart index 83d6400b7dcef36aac8665f84026539471a99673..4f63d7d4600c72abb3dcc09a75f0389bbc5f7c1f 100644 --- a/lib/services/login_service.dart +++ b/lib/services/login_service.dart @@ -61,4 +61,13 @@ class LoginService extends BaseService { headers: headers, body: body); return response; } + + static Future<dynamic> deleteDeviceToken(String identifier) async { + Map<String, String> headers = await BaseService.getHeaders(); + final response = await http.delete( + Uri.parse(ApiUrl.deleteDeviceToken + identifier), + headers: headers, + ); + return response; + } }