You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

217 lines
8.0 KiB

import 'package:flutter/material.dart';
class EditOrderRequests extends StatefulWidget {
var order;
String? advance;
EditOrderRequests({this.order,this.advance});
@override
State<EditOrderRequests> createState() => _EditOrderRequestsState();
}
class _EditOrderRequestsState extends State<EditOrderRequests> {
final TextEditingController tankerPriceController = TextEditingController();
final TextEditingController waterTypeController = TextEditingController();
final TextEditingController capacityController = TextEditingController();
final TextEditingController timeController = TextEditingController();
final TextEditingController quantityController = TextEditingController();
final TextEditingController advanceController = TextEditingController();
final TextEditingController dateController = TextEditingController();
@override
void initState() {
super.initState();
tankerPriceController.text='${widget.order.quoted_amount}';
waterTypeController.text='${widget.order.type_of_water}';
quantityController.text='${widget.order.quantity}';
capacityController.text='${widget.order.capacity}';
timeController.text='${widget.order.averageTime}';
dateController.text='${widget.order.time}';
advanceController.text='${widget.advance}';
// Update summary in real-time as user types
tankerPriceController.addListener(() => setState(() {}));
capacityController.addListener(() => setState(() {}));
quantityController.addListener(() => setState(() {}));
dateController.addListener(() => setState(() {}));
timeController.addListener(() => setState(() {}));
waterTypeController.addListener(() => setState(() {}));
advanceController.addListener(() => setState(() {}));
}
@override
Widget build(BuildContext context) {
int tankerPrice = int.tryParse(tankerPriceController.text) ?? 0;
int updatedQuantity=int.tryParse(quantityController.text) ?? 0;
String updatedCapacity=capacityController.text ?? '';
int totalPrice = tankerPrice * updatedQuantity;
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", null, null),
_twoFields(capacityController, "Capacity", quantityController, "Quantity"),
_twoFields(waterTypeController, "Water Type",advanceController, "Advance"),
_twoFields(dateController, "Date",timeController, "Time Of Delivery"),
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("Quantity", " $updatedQuantity"),
_summaryRow("Capacity", "$updatedCapacity"),
_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}");
// 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)),
],
),
);
}
}