- Migrate SessionClosureBloc → SessionClosureNotifier (@riverpod) - Migrate PairingBloc → PairingNotifier (@riverpod, WebSocket + timer) - Migrate ChatBloc → ChatNotifier (@riverpod, WebSocket + message state) - Remove all flutter_bloc usage from client_app screens and main.dart - MultiBlocProvider fully removed from client_app - All screens now use ConsumerWidget/ConsumerStatefulWidget + ref Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
138 lines
4.8 KiB
Dart
138 lines
4.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../../core/chat/chat_opening_provider.dart';
|
|
import '../../../core/chat/session_closure_notifier.dart';
|
|
import '../../../core/pairing/pairing_notifier.dart';
|
|
|
|
class PricingBottomSheet extends ConsumerWidget {
|
|
/// If set, the bottom sheet is in "extension" mode — selecting a tier extends the session.
|
|
final String? extensionSessionId;
|
|
|
|
const PricingBottomSheet({super.key, this.extensionSessionId});
|
|
|
|
/// Show for new pairing (from home screen)
|
|
static Future<void> show(BuildContext context) {
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
builder: (_) => const PricingBottomSheet(),
|
|
);
|
|
}
|
|
|
|
/// Show for session extension (from chat screen)
|
|
static Future<void> showForExtension(BuildContext context, {required String sessionId}) {
|
|
return showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
builder: (_) => PricingBottomSheet(extensionSessionId: sessionId),
|
|
);
|
|
}
|
|
|
|
String _formatPrice(int price) {
|
|
final str = price.toString();
|
|
final buffer = StringBuffer();
|
|
for (var i = 0; i < str.length; i++) {
|
|
if (i > 0 && (str.length - i) % 3 == 0) buffer.write('.');
|
|
buffer.write(str[i]);
|
|
}
|
|
return 'Rp $buffer';
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final isExtension = extensionSessionId != null;
|
|
final pricingAsync = ref.watch(chatPricingProvider);
|
|
|
|
return pricingAsync.when(
|
|
loading: () => const SizedBox(
|
|
height: 200,
|
|
child: Center(child: CircularProgressIndicator()),
|
|
),
|
|
error: (error, _) => SizedBox(
|
|
height: 200,
|
|
child: Center(child: Text('Gagal memuat harga. Coba lagi.')),
|
|
),
|
|
data: (pricing) => DraggableScrollableSheet(
|
|
initialChildSize: 0.6,
|
|
minChildSize: 0.4,
|
|
maxChildSize: 0.8,
|
|
expand: false,
|
|
builder: (_, scrollController) {
|
|
return Padding(
|
|
padding: const EdgeInsets.all(24),
|
|
child: ListView(
|
|
controller: scrollController,
|
|
children: [
|
|
Text(
|
|
isExtension ? 'Perpanjang Durasi' : 'Pilih Durasi Curhat',
|
|
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
const SizedBox(height: 16),
|
|
if (!isExtension && pricing.freeTrialEligible) ...[
|
|
Card(
|
|
color: Colors.green.shade50,
|
|
child: ListTile(
|
|
leading: const Icon(Icons.card_giftcard, color: Colors.green),
|
|
title: Text('Free Trial (${pricing.freeTrialDurationMinutes} Menit)'),
|
|
subtitle: const Text('Gratis untuk pertama kali!'),
|
|
trailing: const Icon(Icons.arrow_forward_ios, size: 16),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
_startPairing(ref, isFreeTrial: true);
|
|
},
|
|
),
|
|
),
|
|
const Divider(height: 24),
|
|
],
|
|
...pricing.tiers.map((tier) => Card(
|
|
child: ListTile(
|
|
title: Text(tier.label),
|
|
trailing: Text(
|
|
_formatPrice(tier.price),
|
|
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
|
),
|
|
onTap: () {
|
|
Navigator.of(context).pop();
|
|
if (isExtension) {
|
|
_requestExtension(
|
|
ref,
|
|
sessionId: extensionSessionId!,
|
|
durationMinutes: tier.durationMinutes,
|
|
price: tier.price,
|
|
);
|
|
} else {
|
|
_startPairing(
|
|
ref,
|
|
durationMinutes: tier.durationMinutes,
|
|
price: tier.price,
|
|
);
|
|
}
|
|
},
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
void _startPairing(WidgetRef ref, {bool isFreeTrial = false, int? durationMinutes, int? price}) {
|
|
ref.read(pairingProvider.notifier).requestPairingWithTier(
|
|
durationMinutes: durationMinutes,
|
|
price: price,
|
|
isFreeTrial: isFreeTrial,
|
|
);
|
|
}
|
|
|
|
void _requestExtension(WidgetRef ref, {required String sessionId, required int durationMinutes, required int price}) {
|
|
ref.read(sessionClosureProvider.notifier).requestExtension(
|
|
sessionId,
|
|
durationMinutes: durationMinutes,
|
|
price: price,
|
|
);
|
|
}
|
|
}
|