import 'package:flutter/material.dart'; import 'package:bookatanker/common/settings.dart'; class CancelOrderPage extends StatefulWidget { var order; var status; CancelOrderPage({this.order, this.status}); @override State createState() => _CancelOrderPageState(); } class _CancelOrderPageState extends State { String? selectedReason; final TextEditingController reasonController = TextEditingController(); final List reasons = [ "Changed my mind", "Found another price", "Delivery got delayed", "Do not need it anymore", "Supplier asked me to cancel", "Other", ]; @override Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, appBar: AppBar( backgroundColor: Colors.white, elevation: 0, scrolledUnderElevation: 0, title: Text( 'Cancel Order', style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w500), ), iconTheme: IconThemeData(color: Color(0XFF2A2A2A)), leading: GestureDetector( onTap: () { Navigator.pop(context); }, child: Padding( padding: const EdgeInsets.fromLTRB(8, 8, 8, 8), // Add padding if needed child: Image.asset( 'images/backbutton_appbar.png', // Replace with your image path fit: BoxFit.contain, color: Color(0XFF2A2A2A), height: 24, width: 24, ), ), ), ), body: Padding( padding:EdgeInsets.all(24.0), child: SingleChildScrollView( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( "Why are you cancelling?", style: fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w600), ), SizedBox(height:MediaQuery.of(context).size.height * .008,), // Radio buttons ...reasons.map((reason) { return RadioListTile( value: reason, groupValue: selectedReason, activeColor: primaryColor, contentPadding: EdgeInsets.zero, title: Text( reason, style: fontTextStyle(12, Color(0XFF2D2E30), FontWeight.w400), ), onChanged: (value) { setState(() { selectedReason = value; }); }, ); }).toList(), if (selectedReason == "Other") Padding( padding: const EdgeInsets.symmetric(vertical: 10), child: TextFormField( controller: reasonController, maxLines: 5, style: fontTextStyle(14, Color(0XFF101214), FontWeight.w400), cursorColor: Color(0XFF1D7AFC), textCapitalization: TextCapitalization.sentences, decoration: textFormFieldDecorationHintText( Icons.phone, 'Describe your reason..', ), ), ), SizedBox(height:MediaQuery.of(context).size.height * .008,), Text( "Cancellation Policy", style:fontTextStyle(14, Color(0XFF2A2A2A), FontWeight.w600), ), SizedBox(height:MediaQuery.of(context).size.height * .016,), Text( 'Cancel anytime before delivery starts. If it’s already on the way, a ₹100 cancellation fee may apply. Please review our full terms and conditions for more details.', style:fontTextStyle(12, Color(0XFF2A2A2A), FontWeight.w400), ), SizedBox(height:MediaQuery.of(context).size.height * .016,), GestureDetector( onTap: () { // open terms page }, child: Text( "View Terms & Conditions", style: fontTextStylewithUnderline(10, Color(0XFF4692FD), FontWeight.w400,Color(0XFF4692FD)), ), ), ], ), ), ), bottomNavigationBar: Padding( padding: EdgeInsets.all(24.0), child: SizedBox( width: double.infinity, child: ElevatedButton( onPressed: () async { if (selectedReason == null) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text("Please select a reason")), ); return; } String finalReason = selectedReason == "Other" ? reasonController.text.trim() : selectedReason!; if (finalReason.isEmpty) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text("Please enter cancellation reason")), ); return; } bool success = await AppSettings.cancelTankerBooking( widget.order.dbId, "cancel", finalReason, ); if (success) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text("Order cancelled successfully")), ); Navigator.pop(context, true); } else { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text("Failed to cancel order")), ); } }, style: ElevatedButton.styleFrom( backgroundColor: const Color(0XFFE76960), padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(24), ), ), child: Text( "CANCEL ORDER", style: fontTextStyle(14, Color(0XFFFFFFFF), FontWeight.w600), ), ), ), ), ); } }