From 6fd77b3330666b9517709508d9169305bc92b7ad Mon Sep 17 00:00:00 2001 From: Sandertp Date: Wed, 4 Sep 2024 11:53:32 +0200 Subject: [PATCH] Add ReviewListPage and show list of reviews Co-authored-by: Reimar --- Mobile/lib/main.dart | 27 +++++++++++++--- Mobile/lib/models.dart | 6 ++-- Mobile/lib/reviewList.dart | 64 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 Mobile/lib/reviewList.dart diff --git a/Mobile/lib/main.dart b/Mobile/lib/main.dart index e71f742..de4136f 100644 --- a/Mobile/lib/main.dart +++ b/Mobile/lib/main.dart @@ -6,6 +6,7 @@ import 'package:flutter_map/flutter_map.dart'; import 'package:latlong2/latlong.dart'; import 'package:mobile/favorites.dart'; import 'package:mobile/register.dart'; +import 'package:mobile/reviewList.dart'; import 'package:shared_preferences/shared_preferences.dart'; import 'login.dart'; import 'base/sidemenu.dart'; @@ -45,6 +46,7 @@ class MyApp extends StatelessWidget { '/favorites': (context) => const FavoritesPage(), '/login': (context) => const LoginPage(), '/register': (context) => const RegisterPage(), + '/reviews': (context) => const ReviewListPage(), }, ); } @@ -128,6 +130,7 @@ class _MyHomePageState extends State { setState(() => _selectedPoint = null); } + // Open location bottom menu Future _showLocation(LatLng point, String name, String description) async { await showModalBottomSheet( barrierColor: Colors.black.withOpacity(0.3), @@ -140,6 +143,7 @@ class _MyHomePageState extends State { padding: const EdgeInsets.all(20), width: MediaQuery.of(context).size.width, child: Row(children: [ + // Location information Expanded(child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ @@ -148,14 +152,27 @@ class _MyHomePageState extends State { Text(description), ], )), + Column(children: [ + // Toggle favorite button IconButton( - icon: const Icon(Icons.star), - iconSize: 32, - color: _favorites.where((fav) => fav.lat == point.latitude && fav.lng == point.longitude).isEmpty ? Colors.grey : Colors.yellow, - onPressed: () => _toggleFavorite(point, name, description, setModalState, context) + icon: const Icon(Icons.star), + iconSize: 32, + color: _favorites.where((fav) => fav.lat == point.latitude && fav.lng == point.longitude).isEmpty ? Colors.grey : Colors.yellow, + onPressed: () => _toggleFavorite(point, name, description, setModalState, context) + ), + + // View reviews button + IconButton( + icon: const Icon(Icons.rate_review), + iconSize: 32, + onPressed: () => + Navigator.pushReplacementNamed( + context, + '/reviews', + arguments: _reviews.where((review) => review.lat == point.latitude && review.lng == point.longitude).toList() + ), ), - const IconButton(icon: Icon(Icons.rate_review), iconSize: 32, onPressed: null), ]), ]), ), diff --git a/Mobile/lib/models.dart b/Mobile/lib/models.dart index 92b5730..2a55ccf 100644 --- a/Mobile/lib/models.dart +++ b/Mobile/lib/models.dart @@ -30,9 +30,10 @@ class Review { String place_name; String place_description; String title; + String content; int rating; - Review(this.id, this.userId, this.lat, this.lng, this.place_name, this.place_description, this.title, this.rating); + Review(this.id, this.userId, this.lat, this.lng, this.place_name, this.place_description, this.title, this.content, this.rating); factory Review.fromJson(Map json) { return Review( @@ -43,7 +44,8 @@ class Review { json['place_name'], json['place_description'], json['title'], - json['rating'] + json['content'], + json['rating'], ); } } diff --git a/Mobile/lib/reviewList.dart b/Mobile/lib/reviewList.dart new file mode 100644 index 0000000..d75f656 --- /dev/null +++ b/Mobile/lib/reviewList.dart @@ -0,0 +1,64 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:mobile/base/sidemenu.dart'; +import 'models.dart'; + +class ReviewListPage extends StatefulWidget { + const ReviewListPage({super.key}); + + @override + State createState() => _ReviewListState(); +} + +class _ReviewListState extends State { + @override + Widget build(BuildContext context) { + // TODO: implement build + final reviews = ModalRoute.of(context)!.settings.arguments as List; + + return SideMenu( + selectedIndex: -1, + body: SingleChildScrollView(child: Container( + decoration: const BoxDecoration(color: Color(0xFFF9f9f9)), + width: MediaQuery.of(context).size.width, + padding: const EdgeInsets.all(20.0), + child: Column(children: + reviews.map((review) => Container( + width: double.infinity, + padding: const EdgeInsets.all(20), + margin: const EdgeInsets.only(bottom: 10), + decoration: const BoxDecoration( + boxShadow: [ + BoxShadow( + color: Color(0x20000000), + offset: Offset(0,1), + blurRadius: 4, + ), + ], + color: Colors.white, + ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Padding( + padding: EdgeInsets.only(top: 3), + child: Icon(Icons.radio, color: Colors.purple, size: 36), + ), + const SizedBox(width: 20), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(review.title, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 24)), + Text(review.content), + ], + ), + ), + ], + ) + )).toList(), + ), + )), + ); + } +} \ No newline at end of file