|
|
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|
|
|
|
import '../common/settings.dart';
|
|
|
|
|
|
|
|
|
|
class PlanDetails extends StatefulWidget {
|
|
|
|
|
final Map<String, dynamic> plan; // 🔥 pass full plan object
|
|
|
|
|
final Map<String, dynamic> plan;
|
|
|
|
|
|
|
|
|
|
const PlanDetails({super.key, required this.plan});
|
|
|
|
|
|
|
|
|
|
@ -11,14 +11,19 @@ class PlanDetails extends StatefulWidget {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
late List<DateTime> deliveryDates;
|
|
|
|
|
late List<Map<String, dynamic>> deliveryDates;
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
deliveryDates = (widget.plan["dates"] as List)
|
|
|
|
|
.map((d) => DateTime.parse(d))
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
// 🔥 Now expecting:
|
|
|
|
|
// "dates": [
|
|
|
|
|
// { "date": "2026-02-10", "status": "scheduled" }
|
|
|
|
|
// ]
|
|
|
|
|
|
|
|
|
|
deliveryDates =
|
|
|
|
|
List<Map<String, dynamic>>.from(widget.plan["dates"] ?? []);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================= INFO CARD =================
|
|
|
|
|
@ -36,8 +41,7 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
style: fontTextStyle(18, Colors.black, FontWeight.w600)),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Text(label,
|
|
|
|
|
style:
|
|
|
|
|
fontTextStyle(13, Colors.black54, FontWeight.w400)),
|
|
|
|
|
style: fontTextStyle(13, Colors.black54, FontWeight.w400)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -45,22 +49,12 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ================= DELIVERY CARD =================
|
|
|
|
|
Widget _buildDeliveryCard(DateTime date) {
|
|
|
|
|
final now = DateTime.now();
|
|
|
|
|
String status;
|
|
|
|
|
Widget _buildDeliveryCard(Map<String, dynamic> delivery) {
|
|
|
|
|
DateTime date = DateTime.parse(delivery["date"]);
|
|
|
|
|
String status = delivery["status"] ?? "scheduled";
|
|
|
|
|
|
|
|
|
|
String buttonText = "";
|
|
|
|
|
bool showButton = true;
|
|
|
|
|
|
|
|
|
|
if (date.isBefore(now)) {
|
|
|
|
|
status = "completed";
|
|
|
|
|
showButton = false;
|
|
|
|
|
} else if (date.difference(now).inHours < 24) {
|
|
|
|
|
status = "in-progress";
|
|
|
|
|
buttonText = "Track Order";
|
|
|
|
|
} else {
|
|
|
|
|
status = "pending";
|
|
|
|
|
buttonText = "Assign Tanker";
|
|
|
|
|
}
|
|
|
|
|
bool showButton = false;
|
|
|
|
|
|
|
|
|
|
Color statusBg;
|
|
|
|
|
Color statusText;
|
|
|
|
|
@ -70,13 +64,26 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
statusBg = Colors.green.withOpacity(0.15);
|
|
|
|
|
statusText = Colors.green;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "rescheduled":
|
|
|
|
|
statusBg = Colors.purple.withOpacity(0.15);
|
|
|
|
|
statusText = Colors.purple;
|
|
|
|
|
buttonText = "View Details";
|
|
|
|
|
showButton = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "in-progress":
|
|
|
|
|
statusBg = Colors.blue.withOpacity(0.15);
|
|
|
|
|
statusText = Colors.blue;
|
|
|
|
|
buttonText = "Track Order";
|
|
|
|
|
showButton = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
default: // scheduled
|
|
|
|
|
statusBg = Colors.orange.withOpacity(0.15);
|
|
|
|
|
statusText = Colors.orange;
|
|
|
|
|
buttonText = "Assign Tanker";
|
|
|
|
|
showButton = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
|
@ -100,15 +107,16 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
status,
|
|
|
|
|
style: fontTextStyle(12, statusText, FontWeight.w600),
|
|
|
|
|
status.toUpperCase(),
|
|
|
|
|
style:
|
|
|
|
|
fontTextStyle(12, statusText, FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const Spacer(),
|
|
|
|
|
Text(
|
|
|
|
|
"${date.day}-${date.month}-${date.year}",
|
|
|
|
|
style:
|
|
|
|
|
fontTextStyle(12, Colors.black54, FontWeight.w400),
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
12, Colors.black54, FontWeight.w400),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -118,7 +126,7 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
style: fontTextStyle(14, Colors.black, FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
|
/* if (showButton)
|
|
|
|
|
if (showButton)
|
|
|
|
|
Align(
|
|
|
|
|
alignment: Alignment.centerRight,
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
@ -135,7 +143,7 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
fontTextStyle(13, Colors.white, FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
)*/
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
@ -147,8 +155,14 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
final plan = widget.plan;
|
|
|
|
|
|
|
|
|
|
final int totalDeliveries = deliveryDates.length;
|
|
|
|
|
final int pendingCount =
|
|
|
|
|
deliveryDates.where((d) => d.isAfter(DateTime.now())).length;
|
|
|
|
|
|
|
|
|
|
final int pendingCount = deliveryDates
|
|
|
|
|
.where((d) => d["status"] == "scheduled")
|
|
|
|
|
.length;
|
|
|
|
|
|
|
|
|
|
final int rescheduledCount = deliveryDates
|
|
|
|
|
.where((d) => d["status"] == "rescheduled")
|
|
|
|
|
.length;
|
|
|
|
|
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
@ -156,7 +170,8 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
backgroundColor: Colors.white,
|
|
|
|
|
elevation: 0,
|
|
|
|
|
leading: IconButton(
|
|
|
|
|
icon: const Icon(Icons.arrow_back_ios_new, color: Colors.black),
|
|
|
|
|
icon:
|
|
|
|
|
const Icon(Icons.arrow_back_ios_new, color: Colors.black),
|
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
|
),
|
|
|
|
|
title: Text(
|
|
|
|
|
@ -202,8 +217,8 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
Column(
|
|
|
|
|
children: [
|
|
|
|
|
Text(plan["customerId"],
|
|
|
|
|
style:
|
|
|
|
|
fontTextStyle(18, Colors.black, FontWeight.w600)),
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
18, Colors.black, FontWeight.w600)),
|
|
|
|
|
const SizedBox(height: 4),
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
|
@ -213,7 +228,8 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Text(plan["type_of_water"],
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
14, const Color(0xFF8270DB),
|
|
|
|
|
14,
|
|
|
|
|
const Color(0xFF8270DB),
|
|
|
|
|
FontWeight.w500)),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
@ -230,7 +246,8 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
|
|
|
|
|
// INFO ROWS
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
_buildInfoCard(plan["capacity"], "Quantity"),
|
|
|
|
|
@ -247,14 +264,17 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
|
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
_buildInfoCard("${plan["weekly_count"]}/week", "Schedule"),
|
|
|
|
|
_buildInfoCard(
|
|
|
|
|
"${plan["weekly_count"]}/week", "Schedule"),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
_buildInfoCard("$pendingCount", "Pending"),
|
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
|
_buildInfoCard("0", "Rescheduled"),
|
|
|
|
|
_buildInfoCard(
|
|
|
|
|
"$rescheduledCount", "Rescheduled"),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
@ -268,7 +288,8 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
|
|
|
|
|
// BOTTOM BUTTONS
|
|
|
|
|
Padding(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
@ -278,14 +299,17 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
side: const BorderSide(
|
|
|
|
|
color: Color(0xFF8270DB)),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(24),
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(24),
|
|
|
|
|
),
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 14),
|
|
|
|
|
const EdgeInsets.symmetric(
|
|
|
|
|
vertical: 14),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
"Edit Plan",
|
|
|
|
|
style: fontTextStyle(14,
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
14,
|
|
|
|
|
const Color(0xFF8270DB),
|
|
|
|
|
FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
@ -296,17 +320,22 @@ class _PlanDetailsState extends State<PlanDetails> {
|
|
|
|
|
child: ElevatedButton(
|
|
|
|
|
onPressed: () {},
|
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
|
backgroundColor: const Color(0xFFE2483D),
|
|
|
|
|
backgroundColor:
|
|
|
|
|
const Color(0xFFE2483D),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(24),
|
|
|
|
|
borderRadius:
|
|
|
|
|
BorderRadius.circular(24),
|
|
|
|
|
),
|
|
|
|
|
padding:
|
|
|
|
|
const EdgeInsets.symmetric(vertical: 14),
|
|
|
|
|
const EdgeInsets.symmetric(
|
|
|
|
|
vertical: 14),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
"Discontinue",
|
|
|
|
|
style: fontTextStyle(
|
|
|
|
|
14, Colors.white, FontWeight.w600),
|
|
|
|
|
14,
|
|
|
|
|
Colors.white,
|
|
|
|
|
FontWeight.w600),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|