Phase 4 Stage 10 client_app: Chat tab UI (3 sub-tabs + retire bestie_history)

Flutter half of Stage 10 — the new Chat tab landing in the bottom nav.
The CTA target swaps from /chat/history to /chat, which redirects into
/chat/aktif. Three sibling routes under a single ShellRoute share a
header + sub-tab pills + the existing HaloTabBar footer:

  /chat/aktif        — the current active session (0 or 1 row)
  /chat/pembayaran   — pending initial + extension payments
  /chat/selesai      — past sessions, cursor-paginated infinite scroll

URL is the source of truth for the active sub-tab so deep links, back
stack, and Maestro all agree on state.

New feature dir `lib/features/chat_tab/`:
- providers/pending_payments_provider.dart — FutureProvider against the
  Stage-10 backend endpoint, plus pendingPaymentsCountProvider for the
  red-dot derivative
- providers/selesai_history_provider.dart — AsyncNotifier over
  GET /api/client/chat/history; tracks accumulated items + next_cursor +
  hasMore; loadMore() and refresh()
- widgets/chat_row.dart — generic row used by all 3 sub-tabs, with
  optional PaymentAmountChip / DurationChip / 📞 Call indicator
- widgets/sub_tab_pill.dart — pill with active underline + optional
  numeric badge (null hides; matches Selesai's no-badge rule)
- screens/chat_tab_shell.dart — ShellRoute scaffold + ChatSubTab enum
- screens/{aktif,pembayaran,selesai}_view.dart — the three sub-tab bodies

Router (`router.dart`):
- /chat → redirect → /chat/aktif
- ShellRoute hosts /chat/aktif, /chat/pembayaran, /chat/selesai
- /chat/history retired; /chat/history/:sessionId → /chat/transcript/:sessionId
- ChatHistoryScreen import + file deleted

HaloTabBar (`features/home/widgets/halo_tab_bar.dart` — new in the
working tree from Stage 9 sweep): now a ConsumerWidget. Chat tab goes
to /chat. Red dot renders when pendingPaymentsCountProvider > 0.

Inbound call-site updates:
- bestie_choice_sheet.dart: /chat/history → /chat
- home_screen.dart history-row tap: /chat/history/:id → /chat/transcript/:id

This commit also carries the larger Stage 9 sweep + ESP-removal + USP
gate edits that were already staged in the working tree on
`home_screen.dart` and `router.dart` from the prior session.

flutter analyze: clean except for the pre-existing scaffold
test/widget_test.dart MyApp reference (unrelated, present on master).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-12 20:14:22 +08:00
parent 350b92f1f3
commit e3ea1d793e
13 changed files with 1943 additions and 478 deletions

View File

@@ -2,25 +2,27 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import 'core/auth/auth_notifier.dart';
import 'features/auth/screens/welcome_screen.dart';
import 'features/auth/screens/display_name_screen.dart';
import 'features/auth/screens/register_screen.dart';
import 'features/auth/screens/otp_screen.dart';
import 'features/auth/screens/force_register_screen.dart';
import 'features/auth/screens/set_display_name_screen.dart';
import 'features/onboarding/onboarding_screen.dart';
import 'features/onboarding/screens/esp_screen.dart';
import 'features/onboarding/screens/notif_gate_screen.dart';
import 'features/onboarding/screens/usp_screen.dart';
import 'features/splash/splash_screen.dart';
import 'features/home/home_screen.dart';
import 'features/profile/profile_screen.dart';
import 'core/constants.dart';
import 'features/chat/screens/searching_screen.dart';
import 'features/chat/screens/bestie_found_screen.dart';
import 'features/chat/screens/no_bestie_screen.dart';
import 'features/chat/screens/chat_screen.dart';
import 'features/chat/screens/chat_history_screen.dart';
import 'features/chat/screens/chat_transcript_screen.dart';
import 'features/chat_tab/screens/chat_tab_shell.dart';
import 'features/chat_tab/screens/aktif_view.dart';
import 'features/chat_tab/screens/pembayaran_view.dart';
import 'features/chat_tab/screens/selesai_view.dart';
import 'features/chat/screens/targeted_waiting_screen.dart';
import 'features/chat/screens/thank_you_screen.dart';
import 'features/payment/screens/payment_screen.dart';
@@ -69,8 +71,7 @@ GoRouter buildRouter(Ref ref) {
final authState = ref.read(authProvider);
final isSplash = state.matchedLocation == '/splash';
final isOnboarding = state.matchedLocation == '/onboarding';
final isAuthRoute = state.matchedLocation.startsWith('/auth') ||
state.matchedLocation == '/welcome';
final isAuthRoute = state.matchedLocation.startsWith('/auth');
// Phase 4 onboarding flow (Verif Choice → ESP → USP) — must transit
// freely while authState is AuthAnonymousData so the router doesn't
// boot the user back to /home before they finish onboarding.
@@ -89,14 +90,15 @@ GoRouter buildRouter(Ref ref) {
return isOnboarding ? null : '/onboarding';
}
if (isOnboarding) {
return '/welcome';
return '/home';
}
final data = authState.valueOrNull;
if (data == null) {
// Error state — show login
if (!isAuthRoute && !isSplash) return '/welcome';
if (isSplash) return '/welcome';
// Error state — drop onto Home; SHome1st variant handles the
// unauthenticated render (login banner overlay).
if (!isAuthRoute && !isSplash) return '/home';
if (isSplash) return '/home';
return null;
}
@@ -106,19 +108,22 @@ GoRouter buildRouter(Ref ref) {
// intentionally pushes into /onboarding/* after loginAnonymous.
if (isOnboardingFlow) return null;
// While AuthAnonymousData, the user may legitimately be mid-flow on
// /welcome (initial entry) → /auth/display-name (push) → about to
// open the Verif Choice Sheet. When refreshListenable fires after
// loginAnonymous resolves, GoRouter re-evaluates the *bottom* of the
// navigation stack (/welcome) which would otherwise redirect to
// /home and tear the stack down before the sheet can open. Allow
// any auth route to stay put under AuthAnonymousData.
// /home → /auth/display-name (push) → about to open the Verif Choice
// Sheet. When refreshListenable fires after loginAnonymous resolves,
// GoRouter re-evaluates the bottom of the navigation stack — without
// this carve-out an /auth/* push would be torn down before the sheet
// can open. Allow any auth route to stay put under AuthAnonymousData.
if (data is AuthAnonymousData && isAuthRoute) return null;
return (isSplash || isAuthRoute) ? '/home' : null;
}
if (data is AuthNeedsDisplayNameData) return '/auth/set-name';
if (data is AuthForceRegisterData) return '/auth/force-register';
if (!isAuthRoute && !isSplash) return '/welcome';
if (isSplash) return '/welcome';
// Phase 4: per flow_customer.mermaid §1, fresh / unauthenticated users
// land on Home directly — the login panel is an overlay on Home, not a
// separate /welcome screen. The Home1st login-panel overlay itself is
// still a follow-up (audit: Home1st 🟡).
if (!isAuthRoute && !isSplash) return '/home';
if (isSplash) return '/home';
return null;
},
routes: [
@@ -126,26 +131,19 @@ GoRouter buildRouter(Ref ref) {
GoRoute(path: '/_theme_preview', builder: (_, __) => const ThemePreviewScreen()),
GoRoute(path: '/splash', builder: (_, __) => const SplashScreen()),
GoRoute(path: '/onboarding', builder: (_, __) => const OnboardingScreen()),
GoRoute(path: '/welcome', builder: (_, __) => const WelcomeScreen()),
GoRoute(path: '/auth/display-name', builder: (_, __) => const DisplayNameScreen()),
GoRoute(path: '/auth/register', builder: (_, __) => const RegisterScreen()),
GoRoute(path: '/auth/otp', builder: (context, state) => OtpScreen(phone: state.extra as String)),
GoRoute(path: '/auth/set-name', builder: (_, __) => const SetDisplayNameScreen()),
GoRoute(path: '/auth/force-register', builder: (_, __) => const ForceRegisterScreen()),
// Phase 4 onboarding sub-flow (Stage 2). Verified vs anonymous branch
// share ESP + USP screens; the parent path drives the post-USP fork.
GoRoute(
path: '/onboarding/verif/esp',
builder: (_, __) => const EspScreen(verified: true),
),
// Phase 4 onboarding sub-flow (Stage 2; updated 2026-05-12 — ESP retired,
// USP is now a one-time gate, see `usp_seen_provider.dart`). Verified vs
// anonymous branches share the USP screen; the parent path drives the
// post-USP fork.
GoRoute(
path: '/onboarding/verif/usp',
builder: (_, __) => const UspScreen(verified: true),
),
GoRoute(
path: '/onboarding/anon/esp',
builder: (_, __) => const EspScreen(verified: false),
),
GoRoute(
path: '/onboarding/anon/usp',
builder: (_, __) => const UspScreen(verified: false),
@@ -166,6 +164,7 @@ GoRouter buildRouter(Ref ref) {
redirect: (_, __) => '/payment/method-pick',
),
GoRoute(path: '/home', builder: (_, __) => const HomeScreen()),
GoRoute(path: '/profile', builder: (_, __) => const ProfileScreen()),
GoRoute(path: '/payment', builder: (context, state) {
// Legacy Phase 3.7 single-screen payment. Still reachable from
// - Home "Mulai Curhat" CTA → no extras (general blast follows confirm)
@@ -232,8 +231,29 @@ GoRouter buildRouter(Ref ref) {
);
}),
GoRoute(path: '/chat/thank-you', builder: (_, __) => const ThankYouScreen()),
GoRoute(path: '/chat/history', builder: (_, __) => const ChatHistoryScreen()),
GoRoute(path: '/chat/history/:sessionId', builder: (context, state) {
// Phase 4 Stage 10 — Chat tab with 3 sub-tabs. The bare `/chat` entry
// redirects into the default `aktif` sub-tab so tap-on-bottom-nav lands
// on a deterministic URL.
GoRoute(path: '/chat', redirect: (_, __) => '/chat/aktif'),
ShellRoute(
builder: (context, state, child) {
final active = switch (state.uri.path) {
'/chat/pembayaran' => ChatSubTab.pembayaran,
'/chat/selesai' => ChatSubTab.selesai,
_ => ChatSubTab.aktif,
};
return ChatTabShell(active: active, child: child);
},
routes: [
GoRoute(path: '/chat/aktif', builder: (_, __) => const AktifView()),
GoRoute(
path: '/chat/pembayaran',
builder: (_, __) => const PembayaranView()),
GoRoute(
path: '/chat/selesai', builder: (_, __) => const SelesaiView()),
],
),
GoRoute(path: '/chat/transcript/:sessionId', builder: (context, state) {
return ChatTranscriptScreen(sessionId: state.pathParameters['sessionId']!);
}),
],