Feature Request: Per-User Rating System #5

Open
opened 2026-04-11 12:50:30 +02:00 by ben · 1 comment
Owner

User should be able to choose between 1 to 5 stars for each dish.
We could introduce a long-press context menu for the rating alongside a rating system on the dish page itself. There, if available, the partners Ranking would also be visible.

We need to introduce changes to the PocketBase Backend for this

User should be able to choose between 1 to 5 stars for each dish. We could introduce a long-press context menu for the rating alongside a rating system on the dish page itself. There, if available, the partners Ranking would also be visible. We need to introduce changes to the PocketBase Backend for this
ben added this to the LovePlate project 2026-04-17 08:01:20 +02:00
Author
Owner

Implementation Plan: Issue #5 (Per-User Rating System)

Overview

Introduce a 1 to 5 star rating system for dishes, allowing each user to rate a dish independently. The rating will be accessible via the DishDetailPage and via a long-press context menu on dish cards. If the user has linked a partner, the partner's rating will also be displayed on the dish page.

Phase 1: Backend (PocketBase) Updates

  1. Modify users Collection: Add a new json field named ratings.
    • This will store a map of dish.remoteId to the integer rating (1-5).
    • Example: {"dzv2a...": 5, "xj89...": 3}

Phase 2: Data Service Layer (UserSettingsService)

  1. Local Persistence:
    • Introduce _keyUserRatings and _keyPartnerRatings string keys for SharedPreferences.
    • Since ratings are a map, we will store them locally as a JSON-encoded string.
  2. Sync Push (push):
    • Include the local ratings map in the update(userId, body: {...}) call to PocketBase.
  3. Sync Pull (pull):
    • Extract the ratings json field from the user record.
    • Save it locally and return it via the returned record so Riverpod can update the state.
  4. Partner Data (pullPartnerFavorites -> pullPartnerData):
    • Update this method to fetch the ratings field from the partner's user record in addition to favorites.
    • Cache the partner's ratings locally.

Phase 3: State Management (Riverpod)

  1. DishRatings Notifier:
    • Create a Notifier<Map<String, int>> in providers.dart.
    • Methods to setRating(String remoteId, int rating).
    • Similar to ShoppingCart, persisting changes to SharedPreferences and calling userSettingsService.push() in a fire-and-forget manner.
  2. PartnerRatings Notifier:
    • Create a Notifier<Map<String, int>> to hold the partner's ratings in memory.
  3. performFullSync:
    • Update the sync routine to distribute the pulled ratings to these new notifiers.

Phase 4: UI Implementation

  1. DishDetailPage:
    • Add an interactive 5-star RatingBar (e.g., using flutter_rating_bar or row of IconButtons).
    • Below the user's rating, add a smaller, read-only 5-star display showing the partner's rating (if partner_id exists and they rated it). E.g., "Jane rated this 4 stars".
  2. DishCard (Long-press Context Menu):
    • Wrap DishCard in a GestureDetector (using onLongPress) or use a PopupMenuButton / showModalBottomSheet.
    • On long press, show a quick action menu or an overlay with 5 selectable stars to rate the dish.
    • Update the UI of DishCard to show a small star badge if the current user has rated the dish.

Effort / Dependencies

  • Requires Admin access to PocketBase to add the ratings field.
  • Once backend is updated, the code generation (build_runner) does NOT need to run since we manage this entirely in Riverpod state & users collection, keeping Isar Dish model untouched.
# Implementation Plan: Issue #5 (Per-User Rating System) ## Overview Introduce a 1 to 5 star rating system for dishes, allowing each user to rate a dish independently. The rating will be accessible via the `DishDetailPage` and via a long-press context menu on dish cards. If the user has linked a partner, the partner's rating will also be displayed on the dish page. ## Phase 1: Backend (PocketBase) Updates 1. **Modify `users` Collection:** Add a new `json` field named `ratings`. * This will store a map of `dish.remoteId` to the integer rating (1-5). * Example: `{"dzv2a...": 5, "xj89...": 3}` ## Phase 2: Data Service Layer (`UserSettingsService`) 1. **Local Persistence:** * Introduce `_keyUserRatings` and `_keyPartnerRatings` string keys for SharedPreferences. * Since ratings are a map, we will store them locally as a JSON-encoded string. 2. **Sync Push (`push`):** * Include the local `ratings` map in the `update(userId, body: {...})` call to PocketBase. 3. **Sync Pull (`pull`):** * Extract the `ratings` json field from the user record. * Save it locally and return it via the returned record so Riverpod can update the state. 4. **Partner Data (`pullPartnerFavorites` -> `pullPartnerData`):** * Update this method to fetch the `ratings` field from the partner's user record in addition to `favorites`. * Cache the partner's ratings locally. ## Phase 3: State Management (Riverpod) 1. **`DishRatings` Notifier:** * Create a `Notifier<Map<String, int>>` in `providers.dart`. * Methods to `setRating(String remoteId, int rating)`. * Similar to `ShoppingCart`, persisting changes to SharedPreferences and calling `userSettingsService.push()` in a fire-and-forget manner. 2. **`PartnerRatings` Notifier:** * Create a `Notifier<Map<String, int>>` to hold the partner's ratings in memory. 3. **`performFullSync`:** * Update the sync routine to distribute the pulled ratings to these new notifiers. ## Phase 4: UI Implementation 1. **`DishDetailPage`:** * Add an interactive 5-star `RatingBar` (e.g., using `flutter_rating_bar` or row of `IconButton`s). * Below the user's rating, add a smaller, read-only 5-star display showing the partner's rating (if `partner_id` exists and they rated it). E.g., *"Jane rated this 4 stars"*. 2. **`DishCard` (Long-press Context Menu):** * Wrap `DishCard` in a `GestureDetector` (using `onLongPress`) or use a `PopupMenuButton` / `showModalBottomSheet`. * On long press, show a quick action menu or an overlay with 5 selectable stars to rate the dish. * Update the UI of `DishCard` to show a small star badge if the current user has rated the dish. ## Effort / Dependencies * Requires Admin access to PocketBase to add the `ratings` field. * Once backend is updated, the code generation (`build_runner`) does NOT need to run since we manage this entirely in Riverpod state & `users` collection, keeping Isar `Dish` model untouched.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ben/LovePlate#5
No description provided.