Skip to content

Commit

Permalink
feat: added Prediction screen and changed firebase project (#58)
Browse files Browse the repository at this point in the history
* feat: added Prediction screen and changed firebase project

* fix: failing CI
  • Loading branch information
arteevraina authored Mar 11, 2021
1 parent 088f0ee commit 4d1df6e
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@ app.*.symbols

# Obfuscation related
app.*.map.json

# Credentials
lib/credentials.dart
22 changes: 7 additions & 15 deletions android/app/google-services.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,33 @@
{
"project_info": {
"project_number": "843330251909",
"project_id": "knowyourdonor-629c5",
"storage_bucket": "knowyourdonor-629c5.appspot.com"
"project_number": "323588121894",
"project_id": "know-your-donor-7827f",
"storage_bucket": "know-your-donor-7827f.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:843330251909:android:d568979585a28c71078dec",
"mobilesdk_app_id": "1:323588121894:android:c7776eda904216585d4de7",
"android_client_info": {
"package_name": "com.example.knowyourdonor"
}
},
"oauth_client": [
{
"client_id": "843330251909-nbal54886gevbka2d19sjln80la9e9v0.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "com.example.knowyourdonor",
"certificate_hash": "0a2cdb9335c8c3a60b78c8225b90d7da01523dad"
}
},
{
"client_id": "843330251909-g9t7htv3f4990ei59chhbo8pd938t706.apps.googleusercontent.com",
"client_id": "323588121894-lll12gs2ek3basf64kggbdemf8fqhuc1.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCks3_SXgVLdXf7zgZT51w0dZA057IXhLU"
"current_key": "AIzaSyCRI6XggOjexcbfIjTqaE79rsLSb-xgsH0"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "843330251909-g9t7htv3f4990ei59chhbo8pd938t706.apps.googleusercontent.com",
"client_id": "323588121894-lll12gs2ek3basf64kggbdemf8fqhuc1.apps.googleusercontent.com",
"client_type": 3
}
]
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
}

dependencies {
classpath 'com.google.gms:google-services:4.3.4'
classpath 'com.google.gms:google-services:4.3.0'
classpath 'com.android.tools.build:gradle:3.5.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
Expand Down
14 changes: 14 additions & 0 deletions lib/models/Place.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Model for Place.
class Place {
Place(
this.placeId,
this.address,
this.lat,
this.long,
);

final String placeId;
final String address;
final double lat;
final double long;
}
49 changes: 49 additions & 0 deletions lib/repository/locationRepository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_google_places/flutter_google_places.dart';
import 'package:google_maps_webservice/places.dart';
import 'package:knowyourdonor/models/Place.dart';

// const kGoogleApiKey = API_KEY;
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: "");

class Location {
Future<Place> predictionScreen(BuildContext context) async {
Prediction p = await PlacesAutocomplete.show(
context: context,
apiKey: "",
onError: onError,
mode: Mode.fullscreen,
language: "eng",
components: [Component(Component.country, "ind")],
);
return displayPrediction(p);
}

Future<Place> displayPrediction(Prediction p) async {
if (p != null) {
PlacesDetailsResponse detail =
await _places.getDetailsByPlaceId(p.placeId);

var placeId = p.placeId;
var lat = detail.result.geometry.location.lat;
var long = detail.result.geometry.location.lng;

var address = detail.result.formattedAddress;

Place place = Place(placeId, address, lat, long);

print("Lat " + lat.toString());
print("Long " + long.toString());
print(address);

return place;
}

return null;
}

void onError(PlacesAutocompleteResponse response) {
print('${response.errorMessage}');
}
}
31 changes: 22 additions & 9 deletions lib/views/request_blood_form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:knowyourdonor/constants/colors.dart';
import 'package:knowyourdonor/constants/text_styles.dart';
import 'package:knowyourdonor/constants/validators.dart';
import 'package:knowyourdonor/repository/seekerRepository.dart';
import 'package:knowyourdonor/repository/locationRepository.dart';

class RequestBlood extends StatefulWidget {
@override
Expand All @@ -26,6 +27,9 @@ class _RequestBloodState extends State<RequestBlood> {
TextEditingController _unitsController = TextEditingController();
TextEditingController _phoneNumberController = TextEditingController();

// Instance for Location Class.
Location location = Location();

@override
Widget build(BuildContext context) {
// Provider for SeekerRepository.
Expand Down Expand Up @@ -85,15 +89,24 @@ class _RequestBloodState extends State<RequestBlood> {
SizedBox(
height: 8.0,
),
TextFormField(
controller: _addressController,
validator: addressValidator,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Address Line",
hintText: "Enter your address",
prefixIcon: Icon(
Icons.home,
GestureDetector(
onTap: () async {
/// Calling [Prediction Screen] for
/// selecting address with [lat] and [long].
await location.predictionScreen(context);
print("display prediction screen called");
},
child: TextFormField(
enabled: false,
controller: _addressController,
validator: addressValidator,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Address Line",
hintText: "Enter your address",
prefixIcon: Icon(
Icons.home,
),
),
),
),
Expand Down
35 changes: 35 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_google_places:
dependency: "direct main"
description:
name: flutter_google_places
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.8"
flutter_plugin_android_lifecycle:
dependency: transitive
description:
Expand Down Expand Up @@ -219,6 +226,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "7.1.8"
google_api_headers:
dependency: transitive
description:
name: google_api_headers
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.1+2"
google_fonts:
dependency: "direct main"
description:
Expand All @@ -240,6 +254,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.0"
google_maps_webservice:
dependency: transitive
description:
name: google_maps_webservice
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.19"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -289,6 +310,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
package_info:
dependency: transitive
description:
name: package_info
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.3+4"
path:
dependency: transitive
description:
Expand Down Expand Up @@ -394,6 +422,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.5"
rxdart:
dependency: transitive
description:
name: rxdart
url: "https://pub.dartlang.org"
source: hosted
version: "0.25.0"
sky_engine:
dependency: transitive
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies:
provider: ^4.3.2+3
fluttertoast: ^7.1.6
carousel_slider: ^3.0.0
flutter_google_places: ^0.2.8

dev_dependencies:
flutter_test:
Expand Down

0 comments on commit 4d1df6e

Please sign in to comment.