import 'package:flutter/material.dart'; class EditPlanRequests extends StatefulWidget { final dynamic order; // Pass order data here const EditPlanRequests({super.key, this.order}); @override State createState() => _EditPlanRequestsState(); } class _EditPlanRequestsState extends State { final TextEditingController tankerPriceController = TextEditingController(text: "2000"); final TextEditingController waterTypeController = TextEditingController(text: "Drinking Water"); final TextEditingController frequencyController = TextEditingController(text: "4/week"); final TextEditingController capacityController = TextEditingController(text: "10000L"); final TextEditingController timeController = TextEditingController(text: "10:00 AM - 5:00 PM"); final TextEditingController quantityController = TextEditingController(text: "1/day"); final TextEditingController advanceController = TextEditingController(text: "40%"); final TextEditingController startDateController = TextEditingController(text: "12 July 2025"); final TextEditingController endDateController = TextEditingController(text: "21 July 2025"); @override void initState() { super.initState(); // Update summary in real-time as user types tankerPriceController.addListener(() => setState(() {})); advanceController.addListener(() => setState(() {})); } @override Widget build(BuildContext context) { int tankerPrice = int.tryParse(tankerPriceController.text) ?? 0; int totalWeeks = 12; // static for now int weeklyPrice = tankerPrice * 4; // assuming 4 tankers/week int totalPrice = weeklyPrice * totalWeeks; double advancePercent = double.tryParse(advanceController.text.replaceAll('%', '')) ?? 0; int advancePayable = (totalPrice * (advancePercent / 100)).round(); return Scaffold( backgroundColor: Colors.white, appBar: AppBar( backgroundColor: Colors.white, elevation: 0, leading: IconButton( icon: const Icon(Icons.close, color: Colors.black), onPressed: () => Navigator.pop(context), ), title: const Text( "Edit Order", style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600), ), centerTitle: true, ), body: SingleChildScrollView( padding: const EdgeInsets.all(16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // 🔹 Club Info Card Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( border: Border.all(color: Colors.grey.shade300), borderRadius: BorderRadius.circular(12), ), child: Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: const [ Chip( label: Text("New", style: TextStyle( color: Colors.blue, fontSize: 12, fontWeight: FontWeight.w600)), backgroundColor: Color(0xFFEAF3FF), padding: EdgeInsets.symmetric(horizontal: 4), ), Text("Club Kohinoor", style: TextStyle( fontSize: 18, fontWeight: FontWeight.w600)), SizedBox(height: 4), Text("Banjara Hills, Hyderabad", style: TextStyle(color: Colors.grey, fontSize: 13)), ], ), ), const Text("5.5 Km", style: TextStyle(color: Colors.black54)), ], ), ), const SizedBox(height: 20), const Text("ORDER DETAILS", style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14)), const SizedBox(height: 12), // 🔹 Two in a row _twoFields(tankerPriceController, "Tanker Price", waterTypeController, "Water Type"), _twoFields(frequencyController, "Frequency", capacityController, "Capacity"), _twoFields(timeController, "Time of Delivery", quantityController, "Quantity"), _twoFields(advanceController, "Advance", startDateController, "Start Date"), _twoFields(endDateController, "End Date", null, null), const SizedBox(height: 20), const Text("UPDATED PAYMENT SUMMARY", style: TextStyle(fontWeight: FontWeight.w600, fontSize: 14)), const SizedBox(height: 12), _summaryRow("Tanker Price", "₹ $tankerPrice"), _summaryRow("Tankers per week", "04"), _summaryRow("Weekly Price", "₹ $weeklyPrice"), _summaryRow("Total weeks", "$totalWeeks"), _summaryRow("Total Price", "₹ $totalPrice"), const Divider(), _summaryRow("Advance", advanceController.text), _summaryRow("Advance Payable", "₹ $advancePayable"), ], ), ), bottomNavigationBar: Container( padding: const EdgeInsets.all(12), decoration: BoxDecoration( color: Colors.white, border: Border(top: BorderSide(color: Colors.grey.shade300)), ), child: Row( children: [ Expanded( child: OutlinedButton( onPressed: () => Navigator.pop(context), child: const Text("Cancel"), ), ), const SizedBox(width: 8), Expanded( child: ElevatedButton( style: ElevatedButton.styleFrom( backgroundColor: Colors.deepPurple, foregroundColor: Colors.white, ), onPressed: () { // 🔹 Collect updated values print("Tanker Price: ${tankerPriceController.text}"); print("Water Type: ${waterTypeController.text}"); print("Frequency: ${frequencyController.text}"); // Save logic here }, child: const Text("Send ➤"), ), ), ], ), ), ); } /// 🔹 Two fields side by side Widget _twoFields(TextEditingController? controller1, String? label1, TextEditingController? controller2, String? label2) { return Row( children: [ Expanded( child: _textField(controller1, label1), ), const SizedBox(width: 10), if (controller2 != null) Expanded( child: _textField(controller2, label2), ), ], ); } /// 🔹 Custom text field Widget _textField(TextEditingController? controller, String? label) { return Container( margin: const EdgeInsets.only(bottom: 12), child: TextField( controller: controller, decoration: InputDecoration( labelText: label, border: OutlineInputBorder( borderRadius: BorderRadius.circular(10), ), contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), ), ), ); } /// 🔹 Summary row Widget _summaryRow(String title, String value) { return Padding( padding: const EdgeInsets.symmetric(vertical: 6), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(title, style: const TextStyle(color: Colors.black54)), Text(value, style: const TextStyle( fontWeight: FontWeight.w600, color: Colors.black)), ], ), ); } }