Skip to content

Commit

Permalink
Merge pull request #100 from fleetimee/add_geolocator_tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
fleetimee authored Nov 27, 2022
2 parents b39a015 + 7ce131d commit 294128d
Show file tree
Hide file tree
Showing 14 changed files with 221 additions and 8 deletions.
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@
android:value="2" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>
66 changes: 66 additions & 0 deletions lib/app/modules/home/controllers/home_controller.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
// 🐦 Flutter imports:

// 📦 Package imports:
import 'dart:async';
import 'dart:io';

import 'package:akm/app/utils/capitalize.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:faker_dart/faker_dart.dart';
import 'package:geocoding/geocoding.dart';
import 'package:geolocator/geolocator.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:nekos/nekos.dart';
Expand Down Expand Up @@ -34,11 +37,74 @@ class HomeController extends GetxController {
productName.value = 'Unknown Device';
brandName.value = '';
}
getLocation();
}

void onClosed() {
streamSubscription.cancel();
}

var productName = ''.obs;
var brandName = ''.obs;

var latitude = 'Getting latitude'.obs;
var longtitude = 'Getting longtitude'.obs;
var address = 'Getting address'.obs;
late StreamSubscription<Position> streamSubscription;

void getLocation() async {
/// Determine the current position of the device.
///
/// When the location services are not enabled or permissions
/// are denied the `Future` will return an error.
bool serviceEnabled;
LocationPermission permission;

// Test if location services are enabled.
serviceEnabled = await Geolocator.isLocationServiceEnabled();
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.');
}

// When we reach here, permissions are granted and we can
// continue accessing the position of the device.
streamSubscription =
Geolocator.getPositionStream().listen((Position position) {
latitude.value = 'Latitude: ${position.latitude}';
longtitude.value = 'Longtitude: ${position.longitude}';
getAddressFromLatlang(position);
});
}

Future<void> getAddressFromLatlang(Position position) async {
List<Placemark> placemark =
await placemarkFromCoordinates(position.latitude, position.longitude);
Placemark place = placemark[0];
address.value = '${place.locality}, ${place.administrativeArea}';
}

// void deviceInfo() async {
// DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();

Expand Down
37 changes: 36 additions & 1 deletion lib/app/modules/home/views/components/home_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ class HomeMenu extends StatelessWidget {
],
),
),
const SizedBox(
height: 10,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: Row(
children: [
Obx(() => controller.address.value == 'Getting address'
? const SizedBox(
height: 20,
width: 20,
child: CircularProgressIndicator(
color: Colors.white,
),
)
: const Icon(
FontAwesomeIcons.mapMarkerAlt,
color: GFColors.DANGER,
)),
const SizedBox(
width: 8,
),
Obx(() => SizedBox(
width: 400,
child: Text(
controller.address.value,
style: const TextStyle(
color: Colors.white,
fontSize: 20,
),
),
)),
],
),
),

const SizedBox(
height: 20,
Expand All @@ -75,7 +110,7 @@ class HomeMenu extends StatelessWidget {
),

const SizedBox(
height: 60,
height: 40,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// 🐦 Flutter imports:
import 'package:akm/app/modules/home/controllers/home_controller.dart';
import 'package:flutter/material.dart';

// 📦 Package imports:
Expand All @@ -20,6 +21,8 @@ class ListAgunanLosController extends GetxController {
getAllAgunanLos(agunanId.id);
}

final homeController = Get.put(HomeController());

var listAgunanLos = List<FormLo>.empty(growable: true).obs;

final insightDebiturController = Get.put(InsightDebiturController());
Expand Down
16 changes: 14 additions & 2 deletions lib/app/modules/list_agunan_los/views/list_agunan_los_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,13 @@ class FormUpdateAgunanKios extends StatelessWidget {
enableDrag: false,
builder: (context) {
return OpenStreetMapSearchAndPick(
center: LatLong(-7.8013753, 110.3647927),
center: LatLong(
double.parse(controller.homeController.latitude.value
.split(' ')[1]),
double.parse(controller
.homeController.longtitude.value
.split(' ')[1]),
),
buttonColor: primaryColor,
buttonText: 'Pilih Lokasi',
onPicked: (pickedData) {
Expand Down Expand Up @@ -1942,7 +1948,13 @@ class FormInputAgunanLos extends StatelessWidget {
enableDrag: false,
builder: (context) {
return OpenStreetMapSearchAndPick(
center: LatLong(-7.8013753, 110.3647927),
center: LatLong(
double.parse(controller.homeController.latitude.value
.split(' ')[1]),
double.parse(controller
.homeController.longtitude.value
.split(' ')[1]),
),
buttonColor: primaryColor,
buttonText: 'Pilih Lokasi',
onPicked: (pickedData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ignore_for_file: unnecessary_overrides

// 🐦 Flutter imports:
import 'package:akm/app/modules/home/controllers/home_controller.dart';
import 'package:flutter/material.dart';

// 📦 Package imports:
Expand All @@ -21,6 +22,8 @@ class ListAgunanTanahController extends GetxController {
getAllAgunanTanah(agunanId.id);
}

final homeController = Get.put(HomeController());

var listAgunanTanah = List<FormTanah>.empty(growable: true).obs;

final isAgunanTanahProcessing = false.obs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,13 @@ class FormUpdateAgunanTanah extends StatelessWidget {
enableDrag: false,
builder: (context) {
return OpenStreetMapSearchAndPick(
center: LatLong(-7.8013753, 110.3647927),
center: LatLong(
double.parse(controller.homeController.latitude.value
.split(' ')[1]),
double.parse(controller
.homeController.longtitude.value
.split(' ')[1]),
),
buttonColor: primaryColor,
buttonText: 'Pilih Lokasi',
onPicked: (pickedData) {
Expand Down Expand Up @@ -1357,7 +1363,13 @@ class FormInputAgunanTanah extends StatelessWidget {
enableDrag: false,
builder: (context) {
return OpenStreetMapSearchAndPick(
center: LatLong(-7.8013753, 110.3647927),
center: LatLong(
double.parse(controller.homeController.latitude.value
.split(' ')[1]),
double.parse(controller
.homeController.longtitude.value
.split(' ')[1]),
),
buttonColor: primaryColor,
buttonText: 'Pilih Lokasi',
onPicked: (pickedData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// 🐦 Flutter imports:
import 'package:akm/app/modules/home/controllers/home_controller.dart';
import 'package:flutter/material.dart';

// 📦 Package imports:
Expand All @@ -19,6 +20,8 @@ class ListAgunanTanahBangunanController extends GetxController {
getAllAgunanTanahBangunan(agunanId.id);
}

final homeController = Get.put(HomeController());

var listAgunanTanahBangunan =
List<FormTanahBangunan>.empty(growable: true).obs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,14 @@ class FormUpdateAgunanTanahBangunan extends StatelessWidget {
builder: (context) {
return SizedBox(
child: OpenStreetMapSearchAndPick(
center: LatLong(-7.8013753, 110.3647927),
center: LatLong(
double.parse(controller
.homeController.latitude.value
.split(' ')[1]),
double.parse(controller
.homeController.longtitude.value
.split(' ')[1]),
),
buttonColor: primaryColor,
buttonText: 'Pilih Lokasi',
onPicked: (pickedData) {
Expand Down Expand Up @@ -1716,7 +1723,13 @@ class FormInputAgunanTanahBangunan extends StatelessWidget {
enableDrag: false,
builder: (context) {
return OpenStreetMapSearchAndPick(
center: LatLong(-7.8013753, 110.3647927),
center: LatLong(
double.parse(controller.homeController.latitude.value
.split(' ')[1]),
double.parse(controller
.homeController.longtitude.value
.split(' ')[1]),
),
buttonColor: primaryColor,
buttonText: 'Pilih Lokasi',
onPicked: (pickedData) {
Expand Down
2 changes: 2 additions & 0 deletions macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import FlutterMacOS
import Foundation

import device_info_plus
import geolocator_apple
import path_provider_macos
import printing
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin"))
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
PrintingPlugin.register(with: registry.registrar(forPlugin: "PrintingPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
Expand Down
56 changes: 56 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,62 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "8.4.0"
geocoding:
dependency: "direct main"
description:
name: geocoding
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
geocoding_platform_interface:
dependency: transitive
description:
name: geocoding_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.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"
get:
dependency: "direct main"
description:
Expand Down
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: akm
version: 1.0.5+12
version: 1.0.6+13
publish_to: none
description: Mobile app untuk Analisis Kredit Mikro built with Flutter and NodeJS.
environment:
Expand Down Expand Up @@ -44,6 +44,8 @@ dependencies:
form_builder_extra_fields: ^8.3.0
form_builder_image_picker: ^3.1.0
form_builder_validators: ^8.4.0
geocoding: ^2.0.5
geolocator: ^9.0.2
get: 4.6.5
getwidget: ^3.0.1
google_fonts: ^3.0.1
Expand Down
3 changes: 3 additions & 0 deletions windows/flutter/generated_plugin_registrant.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

#include "generated_plugin_registrant.h"

#include <geolocator_windows/geolocator_windows.h>
#include <printing/printing_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>

void RegisterPlugins(flutter::PluginRegistry* registry) {
GeolocatorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("GeolocatorWindows"));
PrintingPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("PrintingPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
Expand Down
Loading

1 comment on commit 294128d

@vercel
Copy link

@vercel vercel bot commented on 294128d Nov 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.