From 74c47d78100be9f29bd5976a57be52061a7cec40 Mon Sep 17 00:00:00 2001 From: devendra <devendra@devendras-MacBook-Pro.local> Date: Fri, 16 Dec 2022 18:57:24 +0530 Subject: [PATCH] Feat: Pass location in the submit inspection api --- lib/pages/application_details_page.dart | 14 +++++++++++++- lib/pages/inspection_summary.dart | 12 +----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/lib/pages/application_details_page.dart b/lib/pages/application_details_page.dart index 0dca045..849d091 100644 --- a/lib/pages/application_details_page.dart +++ b/lib/pages/application_details_page.dart @@ -19,6 +19,8 @@ import 'package:smf_mobile/widgets/people_card.dart'; import 'package:smf_mobile/widgets/silverappbar_delegate.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'dart:async'; +import 'package:geolocator/geolocator.dart'; +import 'package:smf_mobile/services/location_service.dart'; // import 'package:connectivity_plus/connectivity_plus.dart'; // import 'package:smf_mobile/util/connectivity_helper.dart'; @@ -262,16 +264,26 @@ class _ApplicationDetailsPageState extends State<ApplicationDetailsPage> Future<void> _submitInspection() async { bool isInternetConnected = await Helper.isInternetConnected(); + Position position; // await Future.delayed(const Duration(milliseconds: 10)); if (isInternetConnected) { _validateUser(); } + try { + position = await LocationService.getCurrentPosition(); + } catch (error) { + Helper.toastMessage(error.toString()); + return; + } + if (_isleadInspector) { Map data = { 'applicationId': widget.application.applicationId, 'userId': _userId, - 'dataObject': _data + 'dataObject': _data, + 'latitude': position.latitude, + 'longitude': position.longitude, }; //Validate assessment form to make sure some inputs are given by the assessor diff --git a/lib/pages/inspection_summary.dart b/lib/pages/inspection_summary.dart index 6fa260a..6ca2d98 100644 --- a/lib/pages/inspection_summary.dart +++ b/lib/pages/inspection_summary.dart @@ -7,8 +7,6 @@ import 'package:smf_mobile/constants/color_constants.dart'; // import 'package:smf_mobile/models/form_model.dart'; import 'package:smf_mobile/pages/login_email_page.dart'; import 'package:smf_mobile/repositories/application_repository.dart'; -import 'package:geolocator/geolocator.dart'; -import 'package:smf_mobile/services/location_service.dart'; // import 'package:smf_mobile/repositories/form_repository.dart'; import 'package:smf_mobile/util/helper.dart'; import 'package:smf_mobile/widgets/people_card.dart'; @@ -128,16 +126,7 @@ class _InspectionSummaryPageState extends State<InspectionSummaryPage> { } Future<void> _submitInspection() async { - Position position; bool isInternetConnected = await Helper.isInternetConnected(); - - try { - position = await LocationService.getCurrentPosition(); - } catch (error) { - Helper.toastMessage(error.toString()); - return; - } - // await Future.delayed(const Duration(milliseconds: 10)); if (isInternetConnected) { _validateUser(); @@ -154,6 +143,7 @@ class _InspectionSummaryPageState extends State<InspectionSummaryPage> { 'Enter the summary of this inspection': _summaryController.text } }; + print(data); final responseCode = await Provider.of<ApplicationRespository>(context, listen: false) .submitInspection(isInternetConnected, data); -- GitLab