first commit
This commit is contained in:
2178
lib/app/modules/warga/views/order_sewa_aset_view.dart
Normal file
2178
lib/app/modules/warga/views/order_sewa_aset_view.dart
Normal file
File diff suppressed because it is too large
Load Diff
981
lib/app/modules/warga/views/order_sewa_paket_view.dart
Normal file
981
lib/app/modules/warga/views/order_sewa_paket_view.dart
Normal file
@ -0,0 +1,981 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import '../controllers/order_sewa_paket_controller.dart';
|
||||
import '../../../data/models/paket_model.dart';
|
||||
import '../../../routes/app_routes.dart';
|
||||
import '../../../services/navigation_service.dart';
|
||||
import 'package:photo_view/photo_view.dart';
|
||||
import 'package:photo_view/photo_view_gallery.dart';
|
||||
import 'package:flutter_logs/flutter_logs.dart';
|
||||
import '../../../theme/app_colors.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class OrderSewaPaketView extends GetView<OrderSewaPaketController> {
|
||||
const OrderSewaPaketView({super.key});
|
||||
|
||||
// Function to show confirmation dialog
|
||||
void showOrderConfirmationDialog() {
|
||||
final paket = controller.paket.value!;
|
||||
final PaketModel? paketModel = paket is PaketModel ? paket : null;
|
||||
final totalPrice = controller.totalPrice.value;
|
||||
|
||||
Get.dialog(
|
||||
Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.all(24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Header with success icon
|
||||
Container(
|
||||
width: 72,
|
||||
height: 72,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primarySoft,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(
|
||||
Icons.check_circle_outline_rounded,
|
||||
color: AppColors.primary,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 20),
|
||||
|
||||
// Title
|
||||
Text(
|
||||
'Konfirmasi Pesanan',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 6),
|
||||
|
||||
// Subtitle
|
||||
Text(
|
||||
'Periksa detail pesanan Anda',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
|
||||
// Order details
|
||||
Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLight,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: AppColors.borderLight),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// Paket name
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Paket',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
paketModel?.nama ?? controller.getPaketNama(paket) ?? 'Paket tanpa nama',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Divider(height: 24, color: AppColors.divider),
|
||||
|
||||
// Duration info
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Durasi',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => Text(
|
||||
controller.isDailyRental()
|
||||
? controller.formattedDateRange.value
|
||||
: '${controller.selectedDate.value}, ${controller.formattedTimeRange.value}',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Divider(height: 24, color: AppColors.divider),
|
||||
|
||||
// Total price info
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'Total',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
Obx(
|
||||
() => Text(
|
||||
controller.formatPrice(controller.totalPrice.value),
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
|
||||
// Action buttons
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: OutlinedButton(
|
||||
onPressed: () => Get.back(),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
side: BorderSide(color: AppColors.primary),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
'Batal',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Obx(
|
||||
() => ElevatedButton(
|
||||
onPressed: controller.isSubmitting.value
|
||||
? null
|
||||
: () {
|
||||
Get.back();
|
||||
controller.submitOrder();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
padding: EdgeInsets.symmetric(vertical: 16),
|
||||
backgroundColor: AppColors.primary,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: controller.isSubmitting.value
|
||||
? SizedBox(
|
||||
height: 20,
|
||||
width: 20,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
Colors.white,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Text(
|
||||
'Pesan',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Handle hot reload by checking if controller needs to be reset
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
// This will be called after the widget tree is built
|
||||
controller.handleHotReload();
|
||||
|
||||
// Ensure navigation service is registered for back button functionality
|
||||
if (!Get.isRegistered<NavigationService>()) {
|
||||
Get.put(NavigationService());
|
||||
debugPrint('✅ Created new NavigationService instance in view');
|
||||
}
|
||||
});
|
||||
|
||||
// Function to handle back button press
|
||||
void handleBackButtonPress() {
|
||||
debugPrint('🔙 Back button pressed - navigating to SewaAsetView');
|
||||
try {
|
||||
// First try to use the controller's method
|
||||
controller.onBackPressed();
|
||||
} catch (e) {
|
||||
debugPrint('⚠️ Error handling back via controller: $e');
|
||||
// Fallback to direct navigation
|
||||
Get.back();
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.background,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
leading: IconButton(
|
||||
icon: Icon(Icons.arrow_back, color: AppColors.textPrimary),
|
||||
onPressed: handleBackButtonPress,
|
||||
),
|
||||
title: Text(
|
||||
'Pesan Paket',
|
||||
style: TextStyle(
|
||||
color: AppColors.textPrimary,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
centerTitle: true,
|
||||
),
|
||||
body: Obx(
|
||||
() => controller.isLoading.value
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: controller.paket.value == null
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline_rounded,
|
||||
size: 64,
|
||||
color: AppColors.error,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Paket tidak ditemukan',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
'Silakan kembali dan pilih paket lain',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24),
|
||||
ElevatedButton(
|
||||
onPressed: handleBackButtonPress,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 24,
|
||||
vertical: 12,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
child: Text('Kembali'),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTopSection(),
|
||||
_buildPaketDetails(),
|
||||
_buildPriceOptions(),
|
||||
_buildDateSelection(context),
|
||||
SizedBox(height: 100), // Space for bottom bar
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
bottomSheet: Obx(
|
||||
() => controller.isLoading.value || controller.paket.value == null
|
||||
? SizedBox.shrink()
|
||||
: _buildBottomBar(onTapPesan: showOrderConfirmationDialog),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Build top section with paket images
|
||||
Widget _buildTopSection() {
|
||||
return Container(
|
||||
height: 280,
|
||||
width: double.infinity,
|
||||
child: Stack(
|
||||
children: [
|
||||
// Photo gallery
|
||||
Obx(
|
||||
() => controller.isPhotosLoading.value
|
||||
? Center(child: CircularProgressIndicator())
|
||||
: controller.paketImages.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(
|
||||
Icons.image_not_supported_outlined,
|
||||
size: 64,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'Tidak ada foto',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: AppColors.textSecondary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
: PhotoViewGallery.builder(
|
||||
scrollPhysics: BouncingScrollPhysics(),
|
||||
builder: (BuildContext context, int index) {
|
||||
return PhotoViewGalleryPageOptions(
|
||||
imageProvider: CachedNetworkImageProvider(
|
||||
controller.paketImages[index],
|
||||
),
|
||||
initialScale: PhotoViewComputedScale.contained,
|
||||
minScale: PhotoViewComputedScale.contained,
|
||||
maxScale: PhotoViewComputedScale.covered * 2,
|
||||
heroAttributes: PhotoViewHeroAttributes(
|
||||
tag: 'paket_image_$index',
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: controller.paketImages.length,
|
||||
loadingBuilder: (context, event) => Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
backgroundDecoration: BoxDecoration(
|
||||
color: Colors.black,
|
||||
),
|
||||
pageController: PageController(),
|
||||
),
|
||||
),
|
||||
|
||||
// Gradient overlay at the top for back button
|
||||
Positioned(
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 80,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topCenter,
|
||||
end: Alignment.bottomCenter,
|
||||
colors: [
|
||||
Colors.black.withOpacity(0.5),
|
||||
Colors.transparent,
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Build paket details section
|
||||
Widget _buildPaketDetails() {
|
||||
final paket = controller.paket.value!;
|
||||
final PaketModel? paketModel = paket is PaketModel ? paket : null;
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
color: Colors.white,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Paket name and availability badge
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
paketModel?.nama ?? controller.getPaketNama(paket) ?? 'Paket tanpa nama',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.success.withOpacity(0.1),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Text(
|
||||
'Tersedia',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w500,
|
||||
color: AppColors.success,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
|
||||
// Description
|
||||
Text(
|
||||
'Deskripsi',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: AppColors.textPrimary,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
paketModel?.deskripsi ?? controller.getPaketDeskripsi(paket) ?? 'Tidak ada deskripsi untuk paket ini.',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.textSecondary,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|