What you'll build

In this part you'll build the Orders tab — a live list of the signed-in user's past orders from Firestore, each showing the status, date, total, and an expandable list of items.

By the end of this part:

Build the orders provider

BlocWeave prompt

Create lib/features/orders/orders_provider.dart. Create a Riverpod StreamProvider<List> called userOrdersProvider that: - Reads the currentUserProvider to get the signed-in user's UID - Returns an empty list if the user is null (not signed in) - Calls orderService.getUserOrders(uid) and streams the result Also create a Riverpod Provider for dependency injection.

Build the orders screen

BlocWeave prompt

Build the orders screen at lib/features/orders/orders_screen.dart. The screen watches userOrdersProvider and shows: - A signed-out state with "Sign in to see your orders" and a sign-in button, if the user is null - An empty state with "No orders yet" and a "Start shopping" button if the list is empty - A ListView of order cards when orders exist Each order card shows: - Order date formatted as "12 Jun 2026" - A status chip (Pending = amber, Paid = blue, Shipped = indigo, Delivered = green) - Total amount: "GHS 360.00" - Number of items: "2 items" - A chevron to expand/collapse When expanded, the card shows a list of the items in that order: product name, size, quantity × unit price. Use ExpansionTile or AnimatedContainer for the expand/collapse. Keep the animation smooth.

Add a status badge widget

The status chip is reused across the orders screen and will be useful in the admin screen (Part 7). Extract it as a shared widget:

BlocWeave prompt

Create lib/shared/widgets/order_status_badge.dart — a small chip widget that takes an OrderStatus string and renders: - "Pending" with amber background - "Paid" with blue background - "Shipped" with indigo background - "Delivered" with green background Use white text on all variants. Make it compact — small font, tight padding.

Real-time status updates

Because userOrdersProvider uses a Firestore stream, order status updates in real-time. Test this by going to the Firestore console while the Orders screen is open, and changing an order's status field from paid to shipped. The badge in the app should update within a second.

Handle the signed-out case gracefully

If a user signs out while on the Orders tab, the screen should react:

BlocWeave prompt

Update lib/features/orders/orders_screen.dart so that when currentUserProvider changes to null (user signs out), the screen immediately shows the signed-out state rather than the previous user's orders. The userOrdersProvider should return an empty stream for null users, so this should happen automatically — verify the behaviour by signing out from the AppBar menu while on the Orders tab.

Test the orders screen

  1. Sign in and place an order (from Part 5)
  2. Navigate to the Orders tab — the order should appear with "Paid" status
  3. Tap the order row — it expands to show the items
  4. In the Firestore console, change status to shipped — the badge updates in the app without a refresh
  5. Sign out — the signed-out state appears immediately
  6. Sign in again — the orders reappear

Project structure after Part 6

lib/
  features/
    orders/
      orders_screen.dart
      orders_provider.dart
  shared/
    widgets/
      order_status_badge.dart

What's next

In Part 7 — the final part — we build the admin screen for the shop owner. The owner can add new products with photos, edit prices and stock status, and update order statuses, all from within the app.