Show reviews on frontend with colored pins

Co-authored-by: Reimar <mail@reim.ar>
This commit is contained in:
Sandertp 2024-09-03 13:33:50 +02:00
parent d58df6e529
commit f7d9cc0fa0
4 changed files with 68 additions and 7 deletions

View File

@ -60,6 +60,7 @@ class MyHomePage extends StatefulWidget {
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
List<Favorite> _favorites = [];
List<Review> _reviews = [];
LatLng? _selectedPoint;
LatLng _currentPosition = LatLng(55.656707, 10.563214);
LatLng? _userPosition;
@ -81,6 +82,7 @@ class _MyHomePageState extends State<MyHomePage> {
if (!isLoggedIn || !mounted) return;
_fetchFavorites();
_fetchReviews();
});
}
@ -216,7 +218,16 @@ class _MyHomePageState extends State<MyHomePage> {
});
}
Future<void> _fetchReviews() async {
final response = await api.request(context, api.ApiService.app, 'GET', '/reviews', null);
if (response == null) return;
final List<dynamic> reviews = jsonDecode(response);
setState(() {
_reviews = reviews.map((review) => Review.fromJson(review)).toList();
debugPrint(_reviews.length.toString());
});
}
Future<void> GetOpenStreetMapArea() async {
final dynamic location;
@ -329,6 +340,30 @@ class _MyHomePageState extends State<MyHomePage> {
)
],
)),
..._reviews.map((review) => MarkerLayer(
markers: [
Marker(
point: LatLng(review.lat, review.lng),
width: 30,
height: 50,
alignment: Alignment.center,
child: Stack(
children: [
IconButton(
padding: const EdgeInsets.only(bottom: 10),
icon: const Icon(Icons.location_pin, size: 30, color:Colors.purpleAccent),
onPressed: () => _showLocation(LatLng(review.lat, review.lng), review.place_name, review.place_description),
),
IconButton(
padding: const EdgeInsets.only(bottom: 10),
icon: const Icon(Icons.location_on_outlined, size: 30, color: Colors.purple),
onPressed: () => _showLocation(LatLng(review.lat, review.lng), review.place_name, review.place_description),
),
],
)
)
],
)),
..._favorites.map((favorite) => MarkerLayer(
markers: [
Marker(

View File

@ -22,6 +22,32 @@ class Favorite {
}
}
class Review {
int id;
String userId;
double lat;
double lng;
String place_name;
String place_description;
String title;
int rating;
Review(this.id, this.userId, this.lat, this.lng, this.place_name, this.place_description, this.title, this.rating);
factory Review.fromJson(Map<String, dynamic> json) {
return Review(
json['id'],
json['user_id'],
json['lat'],
json['lng'],
json['place_name'],
json['place_description'],
json['title'],
json['rating']
);
}
}
class Login {
String token;
String id;

View File

@ -396,10 +396,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_android
sha256: a7e8467e9181cef109f601e3f65765685786c1a738a83d7fbbde377589c0d974
sha256: "480ba4345773f56acda9abf5f50bd966f581dac5d514e5fc4a18c62976bbba7e"
url: "https://pub.dev"
source: hosted
version: "2.3.1"
version: "2.3.2"
shared_preferences_foundation:
dependency: transitive
description:
@ -521,10 +521,10 @@ packages:
dependency: transitive
description:
name: uuid
sha256: "83d37c7ad7aaf9aa8e275490669535c8080377cfa7a7004c24dfac53afffaa90"
sha256: f33d6bb662f0e4f79dcd7ada2e6170f3b3a2530c28fc41f49a411ddedd576a77
url: "https://pub.dev"
source: hosted
version: "4.4.2"
version: "4.5.0"
vector_math:
dependency: transitive
description:

View File

@ -7,6 +7,6 @@ CREATE TABLE reviews (
place_description TEXT NOT NULL,
title TEXT NOT NULL,
content TEXT NOT NULL,
rating REAL NOT NULL
rating INTEGER NOT NULL
);