diff --git a/Mobile/lib/createreview.dart b/Mobile/lib/createreview.dart index 4d5d5aa..b944fd2 100644 --- a/Mobile/lib/createreview.dart +++ b/Mobile/lib/createreview.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:mobile/base/sidemenu.dart'; import 'models.dart'; +import 'api.dart' as api; class CreateReviewPage extends StatefulWidget { const CreateReviewPage({super.key}); @@ -13,15 +14,17 @@ class CreateReviewPage extends StatefulWidget { class _CreateReviewState extends State { final titleInput = TextEditingController(); final contentInput = TextEditingController(); + Place? place; + var rating = 0; @override Widget build(BuildContext context) { - final place = ModalRoute.of(context)!.settings.arguments as Place; + place = ModalRoute.of(context)!.settings.arguments as Place; return SideMenu( selectedIndex: -1, body: Scaffold( - backgroundColor: Color(0xFFF9F9F9), + backgroundColor: const Color(0xFFF9F9F9), body: SingleChildScrollView( child: Center( child: Container( @@ -29,8 +32,8 @@ class _CreateReviewState extends State { padding: const EdgeInsets.all(40), constraints: const BoxConstraints(maxWidth: 400), child: Column(children: [ - Text(place.name, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 24)), - Text(place.description, style: const TextStyle(color: Colors.grey)), + Text(place!.name, style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 24)), + Text(place!.description, style: const TextStyle(color: Colors.grey)), const SizedBox(height: 50), TextField( controller: titleInput, @@ -48,7 +51,21 @@ class _CreateReviewState extends State { decoration: const InputDecoration( hintText: 'Write a review...', ) - ) + ), + const SizedBox(height: 30), + + // Review Stars + + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + for (var i = 0; i < rating; i++) IconButton(onPressed: () => setState(() => rating = i+1), icon: const Icon(Icons.star, color: Colors.yellow)), + for (var i = rating; i < 5; i++) IconButton(onPressed: () => setState(() => rating = i+1), icon: const Icon(Icons.star_border)), + ], + ), + + const SizedBox(height: 30), + ElevatedButton(onPressed: _submitReview, child: const Text('Submit Review')), ]), ) ) @@ -59,7 +76,20 @@ class _CreateReviewState extends State { @override void dispose() { + super.dispose(); titleInput.dispose(); contentInput.dispose(); } + + Future _submitReview() async { + final response = await api.request(context, api.ApiService.app, 'POST', '/reviews', { + 'title': titleInput.text, + 'content': contentInput.text, + 'place_name': place!.name, + 'place_description': place!.description, + 'rating': rating, + 'lat': place!.point.latitude, + 'lng': place!.point.longitude, + }); + } } \ No newline at end of file diff --git a/Mobile/lib/main.dart b/Mobile/lib/main.dart index a65b7ce..47354dd 100644 --- a/Mobile/lib/main.dart +++ b/Mobile/lib/main.dart @@ -173,7 +173,7 @@ class _MyHomePageState extends State { Navigator.pushReplacementNamed( context, '/reviews', - arguments: ReviewList(_reviews.where((review) => review.lat == point.latitude && review.lng == point.longitude).toList(), Place(name, description)) + arguments: ReviewList(_reviews.where((review) => review.lat == point.latitude && review.lng == point.longitude).toList(), Place(name, description, point)) ), ), ]), diff --git a/Mobile/lib/models.dart b/Mobile/lib/models.dart index f11b733..e0c0cfa 100644 --- a/Mobile/lib/models.dart +++ b/Mobile/lib/models.dart @@ -53,8 +53,9 @@ class Review { class Place { String name; String description; + LatLng point; - Place(this.name, this.description); + Place(this.name, this.description, this.point); } class ReviewList { @@ -98,10 +99,10 @@ class User { } } -class SearchResults{ +class SearchResults { LatLng location; String name; String description; -SearchResults(this.location, this.name, this.description); + SearchResults(this.location, this.name, this.description); }