Add ReviewListPage and show list of reviews

Co-authored-by: Reimar <mail@reim.ar>
This commit is contained in:
Sandertp 2024-09-04 11:53:32 +02:00
parent f7d9cc0fa0
commit 6fd77b3330
3 changed files with 90 additions and 7 deletions

View File

@ -6,6 +6,7 @@ import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart'; import 'package:latlong2/latlong.dart';
import 'package:mobile/favorites.dart'; import 'package:mobile/favorites.dart';
import 'package:mobile/register.dart'; import 'package:mobile/register.dart';
import 'package:mobile/reviewList.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'login.dart'; import 'login.dart';
import 'base/sidemenu.dart'; import 'base/sidemenu.dart';
@ -45,6 +46,7 @@ class MyApp extends StatelessWidget {
'/favorites': (context) => const FavoritesPage(), '/favorites': (context) => const FavoritesPage(),
'/login': (context) => const LoginPage(), '/login': (context) => const LoginPage(),
'/register': (context) => const RegisterPage(), '/register': (context) => const RegisterPage(),
'/reviews': (context) => const ReviewListPage(),
}, },
); );
} }
@ -128,6 +130,7 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() => _selectedPoint = null); setState(() => _selectedPoint = null);
} }
// Open location bottom menu
Future<void> _showLocation(LatLng point, String name, String description) async { Future<void> _showLocation(LatLng point, String name, String description) async {
await showModalBottomSheet( await showModalBottomSheet(
barrierColor: Colors.black.withOpacity(0.3), barrierColor: Colors.black.withOpacity(0.3),
@ -140,6 +143,7 @@ class _MyHomePageState extends State<MyHomePage> {
padding: const EdgeInsets.all(20), padding: const EdgeInsets.all(20),
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
child: Row(children: [ child: Row(children: [
// Location information
Expanded(child: Column( Expanded(child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@ -148,14 +152,27 @@ class _MyHomePageState extends State<MyHomePage> {
Text(description), Text(description),
], ],
)), )),
Column(children: [ Column(children: [
// Toggle favorite button
IconButton( IconButton(
icon: const Icon(Icons.star), icon: const Icon(Icons.star),
iconSize: 32, iconSize: 32,
color: _favorites.where((fav) => fav.lat == point.latitude && fav.lng == point.longitude).isEmpty ? Colors.grey : Colors.yellow, color: _favorites.where((fav) => fav.lat == point.latitude && fav.lng == point.longitude).isEmpty ? Colors.grey : Colors.yellow,
onPressed: () => _toggleFavorite(point, name, description, setModalState, context) 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),
]), ]),
]), ]),
), ),

View File

@ -30,9 +30,10 @@ class Review {
String place_name; String place_name;
String place_description; String place_description;
String title; String title;
String content;
int rating; 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<String, dynamic> json) { factory Review.fromJson(Map<String, dynamic> json) {
return Review( return Review(
@ -43,7 +44,8 @@ class Review {
json['place_name'], json['place_name'],
json['place_description'], json['place_description'],
json['title'], json['title'],
json['rating'] json['content'],
json['rating'],
); );
} }
} }

View File

@ -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<ReviewListPage> createState() => _ReviewListState();
}
class _ReviewListState extends State<ReviewListPage> {
@override
Widget build(BuildContext context) {
// TODO: implement build
final reviews = ModalRoute.of(context)!.settings.arguments as List<Review>;
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(),
),
)),
);
}
}