srs/lib/features/orders/orders_screen.dart
Aswin Biju 45fcdcebfb Initial commit
Add SRS app: results, shops, orders and users, wired to srs-api
Flutter web/PWA for the lottery agency, built on Riverpod and go_router,
talking to srs-api over HTTP (HttpApi, token kept in SharedPreferences).

- Results, Shops, Orders and Users tabs (Users for admins only), with
  phone, tablet and desktop layouts and shared widgets and theme tokens
- Users: list with search and Active/Inactive filters; user detail with
  shops, sign-in details, and an Access card
- WhatsApp results switch on each user (sendResults on
  PATCH /api/users/:id). Shows the WhatsApp logo (Simple Icons, CC0,
  drawn with flutter_svg), green only when results will really go out.
  Can't be turned on without a phone number ("Add a phone number first"
  opens the phone sheet), and is paused while the user is inactive. The
  users list marks people who get results with the logo.
- Each Access switch has a one-line description; the explanation
  paragraphs are gone
- Remove demo mode: the app always uses the real AP
  test/support and is used only by tests.
2026-11-04 23:21:50 +05:30

136 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../core/format.dart';
import '../../core/providers.dart';
import '../../core/theme.dart';
import '../../widgets/ui.dart';
import 'order_card.dart';
class OrdersScreen extends ConsumerStatefulWidget {
const OrdersScreen({super.key});
@override
ConsumerState<OrdersScreen> createState() => _OrdersScreenState();
}
class _OrdersScreenState extends ConsumerState<OrdersScreen> {
String? _code;
@override
Widget build(BuildContext context) {
final date = ref.watch(selectedDateProvider);
final orders = ref.watch(ordersProvider(date));
return Column(
children: [
const ScreenHeader(title: 'Orders'),
const PagePad(
top: S.s4,
child: Align(
alignment: Alignment.centerLeft,
child: SizedBox(width: 420, child: DateStrip()),
),
),
Expanded(
child: asyncView(orders, (all) {
final codes = <String>{for (final o in all) o.shop.code}.toList()
..sort();
final active = codes.contains(_code) ? _code : null;
final list = active == null
? all
: all.where((o) => o.shop.code == active).toList();
final tickets = list.fold(0, (a, o) => a + o.tickets);
return PageList(
top: S.s14,
children: [
if (codes.length > 1)
SizedBox(
height: 38,
child: ListView(
scrollDirection: Axis.horizontal,
children: [
_chip(
'All',
active == null,
() => setState(() => _code = null),
),
for (final c in codes)
_chip(
c,
active == c,
() => setState(() => _code = c),
),
],
),
),
if (list.isEmpty)
const EmptyState(
icon: Icons.receipt_long_outlined,
title: 'No orders for this date',
body:
'Orders received via WhatsApp will appear here. Select another date to view earlier orders.',
)
else ...[
Padding(
padding: const EdgeInsets.fromLTRB(
S.s2,
S.s18,
S.s2,
S.s10,
),
child: Row(
children: [
Expanded(
child: Text(dateLong(date), style: ts(15, w: w7)),
),
Text(
'${plural(list.length, 'order')} · ${plural(tickets, 'ticket')}',
style: ts(12, c: C.muted),
),
],
),
),
CardGrid(
children: [
for (final o in list)
OrderCard(
order: o,
onTap: () => context.push('/orders/${o.id}'),
),
],
),
],
],
);
}, retry: () => ref.invalidate(ordersProvider(date))),
),
],
);
}
Widget _chip(String t, bool on, VoidCallback tap) => Padding(
padding: const EdgeInsets.only(right: S.s8),
child: Pressable(
onTap: tap,
radius: R.pill,
builder: (_, hover) => AnimatedContainer(
duration: const Duration(milliseconds: 140),
padding: const EdgeInsets.symmetric(horizontal: S.s16),
alignment: Alignment.center,
decoration: BoxDecoration(
color: on ? C.navy : (hover ? C.hover : Colors.white),
borderRadius: BorderRadius.circular(R.pill),
border: Border.all(
color: on ? C.navy : (hover ? C.border2 : C.border),
),
),
child: Text(
t,
style: ts(13, w: w6, c: on ? Colors.white : C.ink),
),
),
),
);
}