Skip to content

Commit

Permalink
Feat 🥳: Added geo-tagging📍 functionality while reporting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AM-ash-OR-AM-I committed Sep 17, 2023
1 parent 521d06a commit e12bd0f
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 33 deletions.
15 changes: 1 addition & 14 deletions app/jal_dristi_app/.github/workflows/build-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ jobs:
with:
distribution: 'zulu'
java-version: '12.x'
- run: echo "test" > test.txt
- run: cat test.txt
- run: pwd
- uses: subosito/flutter-action@v2
with:
channel: 'stable'
Expand All @@ -33,14 +30,4 @@ jobs:
- uses: actions/upload-artifact@v1
with:
name: release-apk
path: app/jal_dristi_app/build/app/outputs/apk/release/app-release.apk

# Release APK not working
# - name: Release APK
# id: upload-release-asset
# uses: softprops/action-gh-release@v1
# with:
# name: ${{env.APP_NAME}}-${{github.ref_name}}.apk
# files: app/jal_dristi_app/build/app/outputs/apk/release/app-release.apk
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
path: app/jal_dristi_app/build/app/outputs/apk/release/app-release.apk
2 changes: 2 additions & 0 deletions app/jal_dristi_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:label="jal_dristi_app"
android:name="${applicationName}"
Expand Down
Binary file added app/jal_dristi_app/assets/applogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
65 changes: 65 additions & 0 deletions app/jal_dristi_app/lib/common/native_api_calls.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import 'dart:developer';

import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:geolocator/geolocator.dart';
import 'package:provider/provider.dart';

import '../provider/report_provider.dart';
import 'global_navigator.dart';
import 'screen_names.dart';

Future<bool> handleLocationPermission() async {
bool serviceEnabled;
LocationPermission permission;
final context = navigatorKey.currentContext!;
var scaffold = ScaffoldMessenger.of(context);

serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) {
scaffold.showSnackBar(const SnackBar(
content: Text(
'Location services are disabled. Please enable the services',
)));
return false;
}
permission = await Geolocator.checkPermission();
if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) {
scaffold.showSnackBar(
const SnackBar(
content: Text('Location permissions are denied'),
),
);
return false;
}
}
if (permission == LocationPermission.deniedForever) {
scaffold.showSnackBar(
const SnackBar(
content: Text(
'Location permissions are permanently denied, we cannot request permissions.',
),
),
);
return false;
}
return true;
}

Future<void> chooseImageFromGallery() async {
final context = navigatorKey.currentContext!;
final navigator = Navigator.of(context);
final model = context.read<ReportProvider>();
FilePickerResult? result = await FilePicker.platform.pickFiles();

if (result != null) {
final String imagePath = result.files.single.path ?? "";
model.path = imagePath;
navigator.pushNamed(
Screens.reportScreen.route,
);
log("imagePath = $imagePath");
}
}
1 change: 1 addition & 0 deletions app/jal_dristi_app/lib/components/button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class MyNeumorphicButton extends StatelessWidget {
Radius.circular(35),
)),
depth: 5,
lightSource: LightSource.top,
),
child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
Expand Down
6 changes: 5 additions & 1 deletion app/jal_dristi_app/lib/components/textfield.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,31 @@ class NeumorphicTextField extends StatelessWidget {
final String? Function(String?)? validator;
final int? maxLines;
final TextEditingController? controller;
final bool last;
const NeumorphicTextField({
super.key,
this.hintText,
this.controller,
this.labelText,
this.validator,
this.maxLines,
this.last = false,
});

@override
Widget build(BuildContext context) {
return Neumorphic(
margin: const EdgeInsets.all(20),
margin: const EdgeInsets.all(15),
padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 25),
style: NeumorphicStyle(
lightSource: LightSource.top,
depth: -5,
shadowDarkColorEmboss: Colors.grey.withOpacity(.6),
shadowLightColorEmboss: Colors.white,
boxShape: NeumorphicBoxShape.roundRect(BorderRadius.circular(30)),
),
child: TextFormField(
textInputAction: last ? TextInputAction.done : TextInputAction.next,
validator: validator,
decoration: InputDecoration(
border: InputBorder.none,
Expand Down
2 changes: 1 addition & 1 deletion app/jal_dristi_app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MyApp extends StatelessWidget {
navigatorKey: navigatorKey,
theme: NeumorphicThemeData(
textTheme: GoogleFonts.josefinSansTextTheme(),
lightSource: LightSource.bottomRight,
lightSource: LightSource.top,
baseColor: kBaseColor,
shadowLightColor: kShadowLightColor,
shadowDarkColor: kShadowDarkColor,
Expand Down
4 changes: 2 additions & 2 deletions app/jal_dristi_app/lib/provider/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ class Api {
required String departmentId,
required String description,
required String category,
String latitude = "27.717245",
String longitude = "85.323959",
String latitude = "NA",
String longitude = "NA",
}) async {
final authToken = await getAuthToken();
MultipartRequest request = MultipartRequest(
Expand Down
38 changes: 36 additions & 2 deletions app/jal_dristi_app/lib/provider/report_provider.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import 'dart:convert';
import 'dart:developer';

import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:geolocator/geolocator.dart';
import 'package:jal_dristi_app/provider/api.dart';
import 'package:jal_dristi_app/provider/model/department.dart';

import '../common/native_api_calls.dart';

class ReportProvider extends ChangeNotifier {
String path = "/home/ashucoder/Downloads/flood.jpg";
String _category = 'Flood';
Expand Down Expand Up @@ -50,6 +54,36 @@ class ReportProvider extends ChangeNotifier {
notifyListeners();
}

String description = "";
String address = "";
String longitude = "";
String latitude = "";

Future<void> getCurrentPosition() async {
final hasPermission = await handleLocationPermission();
if (!hasPermission) return;
final position = await Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high,
);
log("position = $position");
longitude = position.longitude.toString();
latitude = position.latitude.toString();
}

Future<String> reportIncident(
String description,
) async {
log("reportIncident called");

// Get the current location
await getCurrentPosition();
final response = await Api.createIncident(
description: description,
category: category,
departmentId: selectedDepartment!.id.toString(),
imagePath: path,
latitude: latitude,
longitude: longitude,
);
log("response = $response");
return response;
}
}
3 changes: 2 additions & 1 deletion app/jal_dristi_app/lib/screens/camera_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:path_provider/path_provider.dart';
import 'package:provider/provider.dart';

import '../common/image_picker.dart';
import '../common/native_api_calls.dart';
import '../common/screen_names.dart';
import '../provider/report_provider.dart';

Expand Down Expand Up @@ -82,6 +82,7 @@ class _CameraScreenState extends State<CameraScreen> {
navigator.pushNamed(
Screens.reportScreen.route,
);


// DiseaseProvider.detectDisease(imagePath).then((value) {
// log("value : $value");
Expand Down
2 changes: 1 addition & 1 deletion app/jal_dristi_app/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:jal_dristi_app/common/screen_names.dart';
import 'package:jal_dristi_app/provider/api.dart';

import '../common/image_picker.dart';
import '../common/native_api_calls.dart';
import '../components/menu_item.dart';
import 'camera_screen.dart';

Expand Down
13 changes: 12 additions & 1 deletion app/jal_dristi_app/lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ class _LoginScreenState extends State<LoginScreen> {
body: SingleChildScrollView(
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 80, bottom: 20),
child: Center(
child: Icon(
Icons.water_drop_rounded,
size: 100,
color: Colors.blue.shade900,
),
),
),
const Padding(
padding: EdgeInsets.all(100.0),
child: Center(
child: Text(
"Login",
"Jal Drishti",
style: TextStyle(fontSize: 40),
),
),
Expand All @@ -49,6 +59,7 @@ class _LoginScreenState extends State<LoginScreen> {
NeumorphicTextField(
hintText: "Password",
controller: _passwordController,
last: true,
),
const SizedBox(height: 20),
MyNeumorphicButton(
Expand Down
11 changes: 3 additions & 8 deletions app/jal_dristi_app/lib/screens/report_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_neumorphic/flutter_neumorphic.dart';
import 'package:jal_dristi_app/common/colors.dart';
import 'package:jal_dristi_app/components/button.dart';
import 'package:jal_dristi_app/components/textfield.dart';
import 'package:jal_dristi_app/provider/api.dart';
import 'package:provider/provider.dart';

import '../provider/report_provider.dart';
Expand All @@ -29,13 +28,9 @@ class _ReportingScreenState extends State<ReportingScreen> {

void reportIssue() async {
if (_validateForm()) {
final response = await Api.createIncident(
imagePath: context.read<ReportProvider>().path,
description: _issueController.text,
category: context.read<ReportProvider>().category,
departmentId:
(context.read<ReportProvider>().selectedDepartment!.id).toString(),
);
final response = await context
.read<ReportProvider>()
.reportIncident(_issueController.text);
log(response);
if (response == "Success") {
// ignore: use_build_context_synchronously
Expand Down
10 changes: 10 additions & 0 deletions app/jal_dristi_app/lib/screens/review_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'package:flutter/material.dart';

class ReviewScreen extends StatelessWidget {
const ReviewScreen({super.key});

@override
Widget build(BuildContext context) {
return const Placeholder();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import FlutterMacOS
import Foundation

import geolocator_apple
import path_provider_foundation
import shared_preferences_foundation
import wakelock_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin"))
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))
Expand Down
Loading

0 comments on commit e12bd0f

Please sign in to comment.