Skip to content

Commit 2479492

Browse files
author
Isaias Nascimento
committed
inclusão de funcionalidades map/geolocalização
1 parent 457891f commit 2479492

16 files changed

+480
-25
lines changed

android/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>android</name>
4+
<comment>Project android created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
arguments=
2+
auto.sync=false
3+
build.scans.enabled=false
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
5+
connection.project.dir=app
6+
eclipse.preferences.version=1
7+
gradle.user.home=
8+
java.home=C\:/Program Files/Android/Android Studio/jre
9+
jvm.arguments=
10+
offline.mode=false
11+
override.workspace.settings=true
12+
show.console.view=true
13+
show.executions.view=true

android/app/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
4+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5+
<classpathentry kind="output" path="bin/default"/>
6+
</classpath>

android/app/.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>app</name>
4+
<comment>Project app created by Buildship.</comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
arguments=
2+
auto.sync=false
3+
build.scans.enabled=false
4+
connection.gradle.distribution=GRADLE_DISTRIBUTION(VERSION(6.3))
5+
connection.project.dir=
6+
eclipse.preferences.version=1
7+
gradle.user.home=
8+
java.home=C\:/Program Files/Android/Android Studio/jre
9+
jvm.arguments=
10+
offline.mode=false
11+
override.workspace.settings=true
12+
show.console.view=true
13+
show.executions.view=true

android/app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
android:name="io.flutter.app.FlutterApplication"
1010
android:label="features_flutter"
1111
android:icon="@mipmap/ic_launcher">
12+
<meta-data android:name="com.google.android.geo.API_KEY"
13+
android:value=""/>
1214
<activity
1315
android:name=".MainActivity"
1416
android:launchMode="singleTop"

lib/helpers/db_helper.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import 'package:sqflite/sqflite.dart' as sql;
2+
import 'package:path/path.dart' as path;
3+
4+
class DbHelper {
5+
static Future<sql.Database> dataBase() async {
6+
final dbPath = await sql.getDatabasesPath();
7+
8+
return sql.openDatabase(path.join(dbPath, 'places.db'),
9+
onCreate: (db, int version) {
10+
return db.execute(
11+
'CREATE TABLE user_places(id TEXT PRIMARY KEY,title TEXT,image TEXT, loc_lat REAL,loc_lng REAL, address TEXT)');
12+
}, version: 1);
13+
}
14+
15+
static Future<void> insert(String table, Map<String, Object> data) async {
16+
var db = await DbHelper.dataBase();
17+
db.insert(
18+
table,
19+
data,
20+
conflictAlgorithm: sql.ConflictAlgorithm.replace,
21+
);
22+
}
23+
24+
static Future<List<Map<String, dynamic>>> getData(String table) async {
25+
var db = await DbHelper.dataBase();
26+
return db.query(table);
27+
}
28+
}

lib/helpers/location_help.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import 'dart:convert';
2+
3+
import 'package:http/http.dart' as http;
4+
5+
const GOOGLE_API_KEY = "";
6+
7+
class LocationHelper {
8+
static String generateLocationPreviewImage({double lat, double lon}) {
9+
return 'https://maps.googleapis.com/maps/api/staticmap?center=$lat,$lon&zoon=16&size=600x300&maptype=roadmap&markers=color:red%7Clabel:A%7C$lat,$lon&key=$GOOGLE_API_KEY';
10+
}
11+
12+
static Future<String> getPlaceAddress(double lat, double lng) async {
13+
final url =
14+
'https://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&key=$GOOGLE_API_KEY';
15+
16+
//TODO: add try
17+
final response = await http.get(url);
18+
return json.decode(response.body)['results'][0]['formatted_address'];
19+
}
20+
}

lib/models/place.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import 'package:flutter/foundation.dart';
55
class PlaceLocation {
66
final double latitude;
77
final double longitude;
8-
final double address;
8+
final String address;
99

10-
PlaceLocation({
10+
const PlaceLocation({
1111
@required this.latitude,
1212
@required this.longitude,
1313
this.address,

lib/provider/greate_places.dart

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,64 @@
11
import 'dart:io';
22

3+
import 'package:features_flutter/helpers/db_helper.dart';
4+
import 'package:features_flutter/helpers/location_help.dart';
35
import 'package:features_flutter/models/place.dart';
46
import 'package:flutter/foundation.dart';
57

68
class GreatPlaces with ChangeNotifier {
79
List<Place> _item = [];
810
List<Place> get items => [..._item];
911

10-
void addPlace(
12+
Future<void> addPlace(
1113
String title,
1214
File image,
13-
) {
15+
PlaceLocation pikdedLocation,
16+
) async {
17+
final address = await LocationHelper.getPlaceAddress(
18+
pikdedLocation.latitude, pikdedLocation.longitude);
19+
final updateLocation = PlaceLocation(
20+
latitude: pikdedLocation.latitude,
21+
longitude: pikdedLocation.longitude,
22+
address: address);
23+
1424
final newPlace = Place(
1525
id: DateTime.now().toString(),
1626
image: image,
1727
title: title,
18-
location: null,
28+
location: updateLocation,
1929
);
30+
2031
_item.add(newPlace);
32+
33+
notifyListeners();
34+
print(newPlace);
35+
36+
DbHelper.insert('user_places', {
37+
'id': newPlace.id,
38+
'title': newPlace.title,
39+
'image': newPlace.image.path,
40+
'loc_lat': newPlace.location.latitude,
41+
'loc_lng': newPlace.location.longitude,
42+
'address': newPlace.location.address,
43+
});
44+
}
45+
46+
Future<void> fechAndSetPlaces() async {
47+
final dataList = await DbHelper.getData('user_places');
48+
_item = dataList
49+
.map(
50+
(item) => Place(
51+
id: item['id'],
52+
title: item['title'],
53+
image: File(item['image']),
54+
location: PlaceLocation(
55+
latitude: item['loc_lat'],
56+
longitude: item['loc_lng'],
57+
address: item['address'],
58+
),
59+
),
60+
)
61+
.toList();
2162
notifyListeners();
2263
}
2364
}

0 commit comments

Comments
 (0)