Commit ef4e3a5e authored by devendra's avatar devendra
Browse files

Feat: Capture device location when assessor submits the form

1 merge request!2Add assessor location
Showing with 106 additions and 0 deletions
+106 -0
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.upsmf.beta">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:label="UP SMF"
android:usesCleartextTraffic="true"
......
......@@ -7,6 +7,8 @@ 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';
......@@ -126,7 +128,16 @@ 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();
......
import 'package:geolocator/geolocator.dart';
import 'package:smf_mobile/util/helper.dart';
class LocationService {
/// Determine the current position of the device.
///
/// When the location services are not enabled or permissions
/// are denied the `Future` will return an error.
static Future<Position> getCurrentPosition() async {
bool serviceEnabled;
LocationPermission permission;
// Test if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
permission = await Geolocator.checkPermission();
if (!serviceEnabled) {
// Location services are not enabled don't continue
// accessing the position and request users of the
// App to enable the location services.
Helper.toastMessage(
"Location service is turned off on the device, turn on to submit the form");
permission = await Geolocator.requestPermission();
}
if (permission == LocationPermission.denied) {
// permission = await Geolocator.requestPermission();
// Permissions are denied, next time you could try
// requesting permissions again (this is also where
// Android's shouldShowRequestPermissionRationale
// returned true. According to Android guidelines
// your App should show an explanatory UI now.
return Future.error(
'Location permissions are denied, turn on location to submit the form');
}
if (permission == LocationPermission.deniedForever) {
// Permissions are denied forever, handle appropriately.
return Future.error(
'Location permissions are permanently denied, turn on location to submit the form');
}
// When we reach here, permissions are granted and we can
// continue accessing the position of the device.
return await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
}
......@@ -371,6 +371,48 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.1.1"
geolocator:
dependency: "direct main"
description:
name: geolocator
url: "https://pub.dartlang.org"
source: hosted
version: "9.0.2"
geolocator_android:
dependency: transitive
description:
name: geolocator_android
url: "https://pub.dartlang.org"
source: hosted
version: "4.1.4"
geolocator_apple:
dependency: transitive
description:
name: geolocator_apple
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.3"
geolocator_platform_interface:
dependency: transitive
description:
name: geolocator_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "4.0.7"
geolocator_web:
dependency: transitive
description:
name: geolocator_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.6"
geolocator_windows:
dependency: transitive
description:
name: geolocator_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1"
google_fonts:
dependency: "direct main"
description:
......
......@@ -56,6 +56,7 @@ dependencies:
image_cropper: ^3.0.1
dio: ^4.0.4
webview_flutter: ^3.0.1
geolocator: ^9.0.2
dev_dependencies:
flutter_test:
......
......@@ -8,10 +8,13 @@
#include <connectivity_plus_windows/connectivity_plus_windows_plugin.h>
#include <flutter_secure_storage_windows/flutter_secure_storage_windows_plugin.h>
#include <geolocator_windows/geolocator_windows.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
ConnectivityPlusWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("ConnectivityPlusWindowsPlugin"));
FlutterSecureStorageWindowsPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin"));
GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows"));
}
......@@ -5,6 +5,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
connectivity_plus_windows
flutter_secure_storage_windows
geolocator_windows
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment