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>
267 lines
7.2 KiB
Dart
267 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../../../core/theme/halo_tokens.dart';
|
|
import '../../../core/theme/widgets/widgets.dart';
|
|
|
|
/// Generic row used by all three Chat-Tab sub-tabs (aktif / pembayaran /
|
|
/// selesai). The owning sub-tab supplies the right-side trailing widget and
|
|
/// any chips below the preview so this widget stays presentation-only.
|
|
///
|
|
/// Visual reference: `requirement/Figma/screens/extras.jsx::SChatList` rows.
|
|
class ChatRow extends StatelessWidget {
|
|
final int seed;
|
|
final String name;
|
|
final String preview;
|
|
final bool isLive;
|
|
final String? trailing;
|
|
final List<Widget> chips;
|
|
final bool isCall;
|
|
final VoidCallback? onTap;
|
|
|
|
const ChatRow({
|
|
super.key,
|
|
required this.seed,
|
|
required this.name,
|
|
required this.preview,
|
|
this.isLive = false,
|
|
this.trailing,
|
|
this.chips = const [],
|
|
this.isCall = false,
|
|
this.onTap,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Padding(
|
|
padding: const EdgeInsets.only(bottom: 10),
|
|
child: Material(
|
|
color: HaloTokens.surface,
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: InkWell(
|
|
onTap: onTap,
|
|
borderRadius: BorderRadius.circular(14),
|
|
child: Container(
|
|
padding: const EdgeInsets.all(14),
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(color: HaloTokens.border),
|
|
),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
_Avatar(seed: seed, isLive: isLive),
|
|
const SizedBox(width: 12),
|
|
Expanded(child: _Body(
|
|
name: name,
|
|
preview: preview,
|
|
trailing: trailing,
|
|
isLive: isLive,
|
|
isCall: isCall,
|
|
chips: chips,
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Avatar extends StatelessWidget {
|
|
final int seed;
|
|
final bool isLive;
|
|
const _Avatar({required this.seed, required this.isLive});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
width: 44,
|
|
height: 44,
|
|
child: Stack(
|
|
clipBehavior: Clip.none,
|
|
children: [
|
|
HaloOrb(seed: seed, size: 44),
|
|
if (isLive)
|
|
Positioned(
|
|
right: -2,
|
|
bottom: -2,
|
|
child: Container(
|
|
width: 14,
|
|
height: 14,
|
|
decoration: BoxDecoration(
|
|
color: HaloTokens.success,
|
|
shape: BoxShape.circle,
|
|
border: Border.all(color: HaloTokens.surface, width: 2.5),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
class _Body extends StatelessWidget {
|
|
final String name;
|
|
final String preview;
|
|
final String? trailing;
|
|
final bool isLive;
|
|
final bool isCall;
|
|
final List<Widget> chips;
|
|
|
|
const _Body({
|
|
required this.name,
|
|
required this.preview,
|
|
required this.trailing,
|
|
required this.isLive,
|
|
required this.isCall,
|
|
required this.chips,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
Row(
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
textBaseline: TextBaseline.alphabetic,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
name,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
color: HaloTokens.ink,
|
|
),
|
|
),
|
|
),
|
|
if (trailing != null || isLive)
|
|
Text(
|
|
isLive ? '● live' : (trailing ?? ''),
|
|
style: TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 10.5,
|
|
fontWeight: isLive ? FontWeight.w600 : FontWeight.w400,
|
|
color: isLive ? HaloTokens.success : HaloTokens.inkMuted,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 2),
|
|
Text(
|
|
preview,
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: const TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 12,
|
|
color: HaloTokens.inkSoft,
|
|
height: 1.4,
|
|
),
|
|
),
|
|
if (isCall || chips.isNotEmpty)
|
|
Padding(
|
|
padding: const EdgeInsets.only(top: 6),
|
|
child: Wrap(
|
|
spacing: 6,
|
|
runSpacing: 4,
|
|
children: [
|
|
if (isCall) const _CallChip(),
|
|
...chips,
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
}
|
|
|
|
/// Voice-call indicator. Stage 6.0 introduced the header pill for the in-call
|
|
/// screen; this is its row-level companion in the Chat tab.
|
|
class _CallChip extends StatelessWidget {
|
|
const _CallChip();
|
|
@override
|
|
Widget build(BuildContext context) => const _Chip(
|
|
text: '📞 Call',
|
|
textColor: HaloTokens.brandDark,
|
|
background: HaloTokens.brandSoft,
|
|
);
|
|
}
|
|
|
|
/// Amber chip used on Pembayaran rows: `bayar Rp X.XXX`.
|
|
class PaymentAmountChip extends StatelessWidget {
|
|
final int amount;
|
|
const PaymentAmountChip({super.key, required this.amount});
|
|
|
|
@override
|
|
Widget build(BuildContext context) => _Chip(
|
|
text: 'bayar ${_formatRupiah(amount)}',
|
|
textColor: const Color(0xFFA8410E),
|
|
background: const Color(0xFFFFF0E5),
|
|
);
|
|
}
|
|
|
|
/// Subtle duration suffix on Selesai rows: `X menit`.
|
|
class DurationChip extends StatelessWidget {
|
|
final int minutes;
|
|
const DurationChip({super.key, required this.minutes});
|
|
|
|
@override
|
|
Widget build(BuildContext context) => Text(
|
|
'$minutes menit',
|
|
style: const TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 10.5,
|
|
color: HaloTokens.inkMuted,
|
|
),
|
|
);
|
|
}
|
|
|
|
class _Chip extends StatelessWidget {
|
|
final String text;
|
|
final Color textColor;
|
|
final Color background;
|
|
const _Chip({
|
|
required this.text,
|
|
required this.textColor,
|
|
required this.background,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: background,
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
child: Text(
|
|
text,
|
|
style: TextStyle(
|
|
fontFamily: HaloTokens.fontBody,
|
|
fontSize: 10.5,
|
|
fontWeight: FontWeight.w600,
|
|
color: textColor,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _formatRupiah(int amount) {
|
|
// Locale-agnostic, no intl dep. Render with `.` group separators per id_ID.
|
|
final s = amount.toString();
|
|
final buf = StringBuffer();
|
|
for (int i = 0; i < s.length; i++) {
|
|
if (i != 0 && (s.length - i) % 3 == 0) buf.write('.');
|
|
buf.write(s[i]);
|
|
}
|
|
return 'Rp${buf.toString()}';
|
|
}
|