import 'package:wanisclient/config/custom_text.dart'; import 'package:wanisclient/utils/colors.dart'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:provider/provider.dart'; import '../config/enum/ride_enum.dart'; import '../providers/ride_providers.dart'; import '../providers/utils_singleton.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 = [ "Driver did not move", "Long pickup time", "Driver asked me to cancel", "Accidental request", "Other" ]; @override Widget build(BuildContext context) { return Container( height: showReasonSelection ? MediaQuery.of(context).size.height * 0.6 : MediaQuery.of(context).size.height * 0.35, padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 20), decoration: const BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(20), topRight: Radius.circular(20), ), ), child: showReasonSelection ? _buildReasonSelection() : _buildConfirmation(), ); } Widget _buildConfirmation() { return Column( //mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ Txt( text: "Are you sure!", style: GoogleFonts.poppins(fontSize: 18, fontWeight: FontWeight.bold), ), const SizedBox(height: 8), Txt( text: "Do you really want to cancel the ride?", style: GoogleFonts.poppins(fontSize: 14, color: Colors.grey.shade600), ), const SizedBox(height: 20), _buildActionButton( "Cancel Ride", AppColors.secondaryColor, Colors.white, () { setState(() { showReasonSelection = true; }); }, ), const SizedBox(height: 12), _buildActionButton( "Wait for Driver", AppColors.primaryColor, Colors.white, () { Navigator.pop(context); if (widget.onCancelDismissed != null) { widget.onCancelDismissed!(); } }, ), ], ); } Widget _buildReasonSelection() { final rideProvider = context.watch(); return Column( mainAxisSize: MainAxisSize.min, children: [ Txt( text: "Share the reason for cancelling the ride", style: GoogleFonts.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 ? AppColors.primaryColor : Colors.grey.shade300, width: 1.5, ), borderRadius: BorderRadius.circular(12), color: selectedReason == reason ? AppColors.primaryColor.withOpacity(0.1) : Colors.white, ), child: Txt( text: reason, textAlign: TextAlign.center, style: GoogleFonts.poppins(fontSize: 14), ), ), ); }).toList(), ), ), const SizedBox(height: 12), GestureDetector( onTap: selectedReason != null ? () { Navigator.pop(context); if (widget.onCancelConfirmed != null) { widget.onCancelConfirmed!(selectedReason!); } rideProvider.updateCurrentstate(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: Txt( text: "Done", style: GoogleFonts.poppins( fontSize: 16, fontWeight: FontWeight.bold, color: Colors.white), ), ), ), const SizedBox(height: 36), ], ); } 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: GoogleFonts.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), ), ); } }