From 0dcfb2ea1ecded342edf7b90f88a5bc95def4d1b Mon Sep 17 00:00:00 2001 From: Alexandertp Date: Thu, 5 Sep 2024 18:23:02 +0200 Subject: [PATCH] Show newly submitted reviews on reviews list Co-authored-by: Reimar --- Mobile/lib/createreview.dart | 10 ++++++++++ Mobile/lib/reviewlist.dart | 5 ++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Mobile/lib/createreview.dart b/Mobile/lib/createreview.dart index b944fd2..c784de2 100644 --- a/Mobile/lib/createreview.dart +++ b/Mobile/lib/createreview.dart @@ -1,3 +1,5 @@ +import 'dart:convert'; + import 'package:flutter/material.dart'; import 'package:mobile/base/sidemenu.dart'; import 'models.dart'; @@ -91,5 +93,13 @@ class _CreateReviewState extends State { 'lat': place!.point.latitude, 'lng': place!.point.longitude, }); + + if (response == null || !mounted) return; + + final review = Review.fromJson(jsonDecode(response)); + + ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('Review submitted'))); + + Navigator.pop(context, review); } } \ No newline at end of file diff --git a/Mobile/lib/reviewlist.dart b/Mobile/lib/reviewlist.dart index 29f791f..bd0313b 100644 --- a/Mobile/lib/reviewlist.dart +++ b/Mobile/lib/reviewlist.dart @@ -61,7 +61,10 @@ class _ReviewListState extends State { ), )), floatingActionButton: FloatingActionButton( - onPressed: () => Navigator.pushNamed(context, '/create-review', arguments: place), + onPressed: () async { + final review = await Navigator.pushNamed(context, '/create-review', arguments: place) as Review?; + if (review != null) reviews.add(review); + }, backgroundColor: Colors.blue, focusColor: Colors.blueGrey, tooltip: "Write a Review",