Implement submitting reviews

Co-authored-by: Reimar <mail@reim.ar>
This commit is contained in:
Alexandertp 2024-09-05 18:11:35 +02:00
parent bd9a6dfa03
commit e03131a8aa
3 changed files with 40 additions and 9 deletions

View File

@ -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<CreateReviewPage> {
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<CreateReviewPage> {
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<CreateReviewPage> {
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<CreateReviewPage> {
@override
void dispose() {
super.dispose();
titleInput.dispose();
contentInput.dispose();
}
Future<void> _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,
});
}
}

View File

@ -173,7 +173,7 @@ class _MyHomePageState extends State<MyHomePage> {
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))
),
),
]),

View File

@ -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);
}