import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../Provider/RideStatusProvider.dart'; import '../config/enum/ride_enum.dart'; import '../utils/colors.dart'; import '../widgets/custom_text.dart'; class CancelRideDialog extends StatefulWidget { final void Function(String reason)? onCancelConfirmed; final VoidCallback? onCancelDismissed; const CancelRideDialog({ Key? key, this.onCancelConfirmed, this.onCancelDismissed, }) : super(key: key); @override _CancelRideDialogState createState() => _CancelRideDialogState(); } class _CancelRideDialogState extends State { bool showReasonSelection = false; String? selectedReason; List reasons = [ "Rider did not show up", "Cannot reach pickup location", "Rider asked to cancel", "Too many passengers or luggage", "Vehicle issue", "Other" ]; @override Widget build(BuildContext context) { return Container( height: showReasonSelection ? MediaQuery.of(context).size.height * 0.7 : MediaQuery.of(context).size.height * 0.35, padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 20), decoration: BoxDecoration( color: Theme.of(context).brightness == Brightness.dark? AppColors.blackBackgroundColor: AppColors.whiteBackgroundColor, borderRadius: const BorderRadius.only( topLeft: Radius.circular(20), topRight: Radius.circular(20), ), ), child: showReasonSelection ? _buildReasonSelection() : _buildConfirmation(), ); } Widget _buildConfirmation() { return SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ _buildCloseButton(), const Txt( text: "Are you sure!", style: TextStyle( fontFamily: 'Poppins',fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 8), Txt( text: "Do you really want to cancel the ride?", style: TextStyle( fontFamily: 'Poppins',fontSize: 14, color: Colors.grey.shade600), ), const SizedBox(height: 20), _buildActionButton( "Cancel Ride", AppColors.secondaryColor, Theme.of(context).brightness == Brightness.dark? AppColors.blackBackgroundColor: AppColors.whiteBackgroundColor, () { setState(() { showReasonSelection = true; }); }, ), const SizedBox(height: 12), _buildActionButton( "Wait for Client", Theme.of(context).brightness == Brightness.dark ? AppColors.secondBtnColor:AppColors.primaryColor, Theme.of(context).brightness == Brightness.dark? AppColors.blackBackgroundColor: AppColors.whiteBackgroundColor, () { Navigator.pop(context); if (widget.onCancelDismissed != null) { widget.onCancelDismissed!(); } }, ), ], ), ); } Widget _buildReasonSelection() { final rideStatusProvider = context.watch(); return Column( mainAxisSize: MainAxisSize.min, children: [ _buildCloseButton(), const Txt( text: "Share the reason for cancelling the ride", style: TextStyle( fontFamily: 'Poppins',fontSize: 16, fontWeight: FontWeight.bold), ), const SizedBox(height: 12), Expanded( child: ListView( children: reasons.map((reason) { return GestureDetector( onTap: () { setState(() { selectedReason = reason; }); }, child: Container( margin: const EdgeInsets.symmetric(vertical: 6), padding: const EdgeInsets.all(14), decoration: BoxDecoration( border: Border.all( color: selectedReason == reason ? Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor:AppColors.primaryColor : Colors.grey.shade300, width: 1.5, ), borderRadius: BorderRadius.circular(12), color: selectedReason == reason ? Theme.of(context).brightness == Brightness.dark ?AppColors.darkPrimaryColor:AppColors.primaryColor.withOpacity(0.1) :Theme.of(context).brightness == Brightness.dark ?AppColors.darkCardColor: Colors.white, ), child: Txt( text: reason, textAlign: TextAlign.center, style: const TextStyle( fontFamily: 'Poppins',fontSize: 14), ), ), ); }).toList(), ), ), const SizedBox(height: 12), GestureDetector( onTap: selectedReason != null ? () { Navigator.pop(context); if (widget.onCancelConfirmed != null) { widget.onCancelConfirmed!(selectedReason!); } rideStatusProvider.updatestates(RideEnum.idle); } : null, child: Container( width: double.infinity, padding: const EdgeInsets.symmetric(vertical: 12), decoration: BoxDecoration( color: selectedReason != null ? Colors.grey.shade800 : Colors.grey.shade400, borderRadius: BorderRadius.circular(30), ), alignment: Alignment.center, child: const Txt( text: "Done", style: TextStyle( fontFamily: 'Poppins', fontSize: 16, fontWeight: FontWeight.bold), ), ), ), ], ); } Widget _buildActionButton( String text, Color borderColor, Color bgColor, VoidCallback onTap) { return GestureDetector( onTap: onTap, child: Container( width: double.infinity, padding: const EdgeInsets.symmetric(vertical: 12), decoration: BoxDecoration( border: Border.all(color: borderColor, width: 2), borderRadius: BorderRadius.circular(30), color: bgColor, ), alignment: Alignment.center, child: Txt( text: text, style: TextStyle( fontFamily: 'Poppins', fontSize: 16, fontWeight: FontWeight.bold, color: borderColor), ), ), ); } Widget _buildCloseButton() { return Align( alignment: Alignment.topRight, child: IconButton( icon: Icon(Icons.close, color: Colors.grey.shade600), onPressed: () => Navigator.pop(context), ), ); } }