Files
halobestie-clone/client_app/lib/features/chat/screens/chat_transcript_screen.dart
ramadhan sjamsani fa8c963d92 Phase 3.1: Remove flutter_bloc + equatable, delete old bloc files
- Remove flutter_bloc and equatable dependencies from both apps
- Delete all 10 old bloc files (5 per app)
- Fix 6 remaining screens that used context.read<ApiClient>() from
  flutter_bloc → converted to ConsumerStatefulWidget/ConsumerWidget
  with ref.read(apiClientProvider)
- Both apps now use Riverpod exclusively for state management

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 14:12:28 +08:00

93 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../core/api/api_client_provider.dart';
import '../../../core/constants.dart';
class ChatTranscriptScreen extends ConsumerStatefulWidget {
final String sessionId;
const ChatTranscriptScreen({super.key, required this.sessionId});
@override
ConsumerState<ChatTranscriptScreen> createState() => _ChatTranscriptScreenState();
}
class _ChatTranscriptScreenState extends ConsumerState<ChatTranscriptScreen> {
List<Map<String, dynamic>> _messages = [];
List<Map<String, dynamic>> _closures = [];
bool _loading = true;
@override
void initState() {
super.initState();
_loadTranscript();
}
Future<void> _loadTranscript() async {
try {
final api = ref.read(apiClientProvider);
final response = await api.get('/api/shared/chat/${widget.sessionId}/transcript');
final data = response['data'] as Map<String, dynamic>;
setState(() {
_messages = (data['messages'] as List<dynamic>).cast<Map<String, dynamic>>();
_closures = (data['closures'] as List<dynamic>).cast<Map<String, dynamic>>();
_loading = false;
});
} catch (_) {
setState(() => _loading = false);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Transkrip Chat')),
body: _loading
? const Center(child: CircularProgressIndicator())
: ListView(
padding: const EdgeInsets.all(16),
children: [
..._messages.map((m) {
final isMe = m['sender_type'] == UserType.customer;
final time = DateTime.parse(m['created_at'] as String).toLocal();
return Align(
alignment: isMe ? Alignment.centerRight : Alignment.centerLeft,
child: Container(
margin: const EdgeInsets.symmetric(vertical: 4),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
constraints: BoxConstraints(maxWidth: MediaQuery.of(context).size.width * 0.75),
decoration: BoxDecoration(
color: isMe ? Colors.blue.shade100 : Colors.grey.shade200,
borderRadius: BorderRadius.circular(16),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(m['content'] as String, style: const TextStyle(fontSize: 15)),
const SizedBox(height: 4),
Text(
'${time.hour.toString().padLeft(2, '0')}:${time.minute.toString().padLeft(2, '0')}',
style: const TextStyle(fontSize: 10, color: Colors.grey),
),
],
),
),
);
}),
if (_closures.isNotEmpty) ...[
const Divider(height: 32),
const Text('Pesan Penutup', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16)),
const SizedBox(height: 8),
..._closures.map((c) => Card(
child: ListTile(
title: Text(c['user_type'] == UserType.customer ? 'Kamu' : 'Bestie'),
subtitle: Text(c['message'] as String),
),
)),
],
],
),
);
}
}