From f5058c506a08daec43e117c26c376a3842a01b32 Mon Sep 17 00:00:00 2001 From: Siahlooei Date: Sat, 20 Jul 2024 15:47:21 +0330 Subject: [PATCH] Starting using geolocation. --- lib/provider/location.dart | 51 +++++++++++++++++++++++ pubspec.lock | 85 ++++++++++++++++++++++++++++++++------ pubspec.yaml | 1 + 3 files changed, 125 insertions(+), 12 deletions(-) create mode 100644 lib/provider/location.dart diff --git a/lib/provider/location.dart b/lib/provider/location.dart new file mode 100644 index 0000000..4fb16b9 --- /dev/null +++ b/lib/provider/location.dart @@ -0,0 +1,51 @@ +import 'package:geolocator/geolocator.dart'; +import 'package:riverpod_annotation/riverpod_annotation.dart'; + +part 'location.g.dart'; + +@riverpod +class MyLocation extends _$MyLocation { + + MyLocation() { + /* + bool serviceEnabled; + LocationPermission permission; + + // Test if location services are enabled. + serviceEnabled = Geolocator.isLocationServiceEnabled().then(onValue); + if (!serviceEnabled) { + // Location services are not enabled don't continue + // accessing the position and request users of the + // App to enable the location services. + return Future.error('Location services are disabled.'); + } + + permission = await Geolocator.checkPermission(); + if (permission == LocationPermission.denied) { + permission = await Geolocator.requestPermission(); + if (permission == LocationPermission.denied) { + // 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'); + } + } + + if (permission == LocationPermission.deniedForever) { + // Permissions are denied forever, handle appropriately. + return Future.error( + 'Location permissions are permanently denied, we cannot request permissions.'); + }*/ + } + + @override + Future build() async{ + Position l = Position(longitude: 0, latitude: 0, + timestamp: DateTime.timestamp(), accuracy: 0, altitude: 0, + altitudeAccuracy: 0, heading: 0, headingAccuracy: 0, + speed: 0, speedAccuracy: 0); + return Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high); + } +} \ No newline at end of file diff --git a/pubspec.lock b/pubspec.lock index 4633907..b163211 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -275,6 +275,11 @@ packages: description: flutter source: sdk version: "0.0.0" + flutter_web_plugins: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" freezed: dependency: "direct dev" description: @@ -287,10 +292,10 @@ packages: dependency: "direct main" description: name: freezed_annotation - sha256: f9f6597ac43cc262fa7d7f2e65259a6060c23a560525d1f2631be374540f2a9b + sha256: c2e2d632dd9b8a2b7751117abcfc2b4888ecfe181bd9fca7170d9ef02e595fe2 url: "https://pub.dev" source: hosted - version: "2.4.3" + version: "2.4.4" frontend_server_client: dependency: transitive description: @@ -299,6 +304,54 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.0" + geolocator: + dependency: "direct main" + description: + name: geolocator + sha256: "6cb9fb6e5928b58b9a84bdf85012d757fd07aab8215c5205337021c4999bad27" + url: "https://pub.dev" + source: hosted + version: "11.1.0" + geolocator_android: + dependency: transitive + description: + name: geolocator_android + sha256: "00c7177a95823dd3ee35ef42fd8666cd27d219ae14cea472ac76a21dff43000b" + url: "https://pub.dev" + source: hosted + version: "4.6.0" + geolocator_apple: + dependency: transitive + description: + name: geolocator_apple + sha256: bc2aca02423ad429cb0556121f56e60360a2b7d694c8570301d06ea0c00732fd + url: "https://pub.dev" + source: hosted + version: "2.3.7" + geolocator_platform_interface: + dependency: transitive + description: + name: geolocator_platform_interface + sha256: "386ce3d9cce47838355000070b1d0b13efb5bc430f8ecda7e9238c8409ace012" + url: "https://pub.dev" + source: hosted + version: "4.2.4" + geolocator_web: + dependency: transitive + description: + name: geolocator_web + sha256: "49d8f846ebeb5e2b6641fe477a7e97e5dd73f03cbfef3fd5c42177b7300fb0ed" + url: "https://pub.dev" + source: hosted + version: "3.0.0" + geolocator_windows: + dependency: transitive + description: + name: geolocator_windows + sha256: "53da08937d07c24b0d9952eb57a3b474e29aae2abf9dd717f7e1230995f13f0e" + url: "https://pub.dev" + source: hosted + version: "0.2.3" glob: dependency: transitive description: @@ -311,10 +364,10 @@ packages: dependency: transitive description: name: graphs - sha256: aedc5a15e78fc65a6e23bcd927f24c64dd995062bcd1ca6eda65a3cff92a4d19 + sha256: "741bbf84165310a68ff28fe9e727332eef1407342fca52759cb21ad8177bb8d0" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" hotreloader: dependency: transitive description: @@ -327,10 +380,10 @@ packages: dependency: "direct main" description: name: http - sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" + sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010 url: "https://pub.dev" source: hosted - version: "1.2.1" + version: "1.2.2" http_multi_server: dependency: transitive description: @@ -467,6 +520,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.9.0" + plugin_platform_interface: + dependency: transitive + description: + name: plugin_platform_interface + sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02" + url: "https://pub.dev" + source: hosted + version: "2.1.8" pool: dependency: transitive description: @@ -700,26 +761,26 @@ packages: dependency: transitive description: name: web - sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" + sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 url: "https://pub.dev" source: hosted - version: "0.5.1" + version: "1.0.0" web_socket: dependency: transitive description: name: web_socket - sha256: "24301d8c293ce6fe327ffe6f59d8fd8834735f0ec36e4fd383ec7ff8a64aa078" + sha256: "3c12d96c0c9a4eec095246debcea7b86c0324f22df69893d538fcc6f1b8cce83" url: "https://pub.dev" source: hosted - version: "0.1.5" + version: "0.1.6" web_socket_channel: dependency: transitive description: name: web_socket_channel - sha256: a2d56211ee4d35d9b344d9d4ce60f362e4f5d1aafb988302906bd732bc731276 + sha256: "9f187088ed104edd8662ca07af4b124465893caf063ba29758f97af57e61da8f" url: "https://pub.dev" source: hosted - version: "3.0.0" + version: "3.0.1" yaml: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2e0e10d..6de8688 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,6 +40,7 @@ dependencies: freezed_annotation: ^2.4.3 json_annotation: ^4.9.0 http: ^1.2.1 + geolocator: ^11.1.0 dev_dependencies: flutter_test: