cancelled product
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import 'package:flutter/gestures.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gap/gap.dart';
|
||||
import 'package:grocery_app/src/common_widget/network_image.dart';
|
||||
import 'package:grocery_app/src/data/myOrder.dart';
|
||||
import 'package:grocery_app/src/logic/provider/order_provider.dart';
|
||||
import 'package:grocery_app/utils/extensions/extensions.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class OrderDetailsScreen extends StatefulWidget {
|
||||
final Datum order;
|
||||
@@ -13,20 +18,16 @@ class OrderDetailsScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
int currentStep = 1;
|
||||
String convertUtcToIst(String utcTime) {
|
||||
// Parse the UTC time string
|
||||
DateTime utcDateTime = DateTime.parse(utcTime).toUtc();
|
||||
|
||||
// Convert to IST (UTC +5:30)
|
||||
DateTime istDateTime =
|
||||
utcDateTime.add(const Duration(hours: 5, minutes: 30));
|
||||
|
||||
// Format the IST datetime with AM/PM
|
||||
String formattedDateTime =
|
||||
DateFormat("dd-MM-yyyy hh:mm a").format(istDateTime);
|
||||
|
||||
return formattedDateTime; // Example: 11-02-2025 10:44 AM
|
||||
return formattedDateTime;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -34,17 +35,39 @@ class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Order Details')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_orderInfo(),
|
||||
SizedBox(height: 20),
|
||||
_animatedShippingTimeline(),
|
||||
SizedBox(height: 20),
|
||||
Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(widget.order.orderNumber,
|
||||
style: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 5),
|
||||
Text(widget.order.deliveryAddress!.addressLine ?? " ",
|
||||
style: TextStyle(
|
||||
fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
SizedBox(height: 5),
|
||||
Text(convertUtcToIst(widget.order.createdAt.toString())),
|
||||
SizedBox(height: 5),
|
||||
// Text(
|
||||
// "Status: ${_getStatusText(widget.order.orderStatus)}",
|
||||
// style: TextStyle(
|
||||
// color: Colors.blue, fontWeight: FontWeight.bold),
|
||||
// ),
|
||||
// _itemsList(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
_itemsList(),
|
||||
SizedBox(height: 20),
|
||||
//_cancelButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -76,6 +99,7 @@ class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
style:
|
||||
TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
|
||||
),
|
||||
// _itemsList(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -83,61 +107,73 @@ class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Animated Shipping Timeline
|
||||
Widget _animatedShippingTimeline() {
|
||||
return Column(
|
||||
final List<String> statuses = [
|
||||
"PENDING",
|
||||
"PROCESSING",
|
||||
"SHIPPED",
|
||||
"DELIVERED"
|
||||
];
|
||||
|
||||
Widget _animatedShippingTimeline(orderItemStatus) {
|
||||
var currentStep = statuses.indexOf(orderItemStatus);
|
||||
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start, // Align items properly
|
||||
children: [
|
||||
for (int i = 0; i < 3; i++) _timelineStep(i),
|
||||
for (int i = 0; i < statuses.length; i++)
|
||||
_timelineStep(i, statuses[i], currentStep),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Each Step in the Timeline
|
||||
Widget _timelineStep(int step) {
|
||||
Widget _timelineStep(int step, String status, currentStep) {
|
||||
bool isCompleted = step <= currentStep;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
AnimatedContainer(
|
||||
duration: Duration(milliseconds: 500),
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: isCompleted ? Colors.green : Colors.grey,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.check, size: 14, color: Colors.white),
|
||||
),
|
||||
if (step < 2)
|
||||
AnimatedContainer(
|
||||
duration: Duration(milliseconds: 500),
|
||||
width: 5,
|
||||
height: 50,
|
||||
color: isCompleted ? Colors.green : Colors.grey,
|
||||
),
|
||||
],
|
||||
AnimatedContainer(
|
||||
duration: Duration(milliseconds: 500),
|
||||
width: 15,
|
||||
height: 15,
|
||||
decoration: BoxDecoration(
|
||||
color: isCompleted ? Colors.green : Colors.grey,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.check, size: 12, color: Colors.white),
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
SizedBox(width: 5),
|
||||
Text(
|
||||
_getStatusTextForStep(widget.order.orderStatus),
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
status,
|
||||
style: TextStyle(fontSize: 10, fontWeight: FontWeight.bold),
|
||||
),
|
||||
if (step < statuses.length - 1) ...[
|
||||
SizedBox(width: 5),
|
||||
AnimatedContainer(
|
||||
duration: Duration(milliseconds: 500),
|
||||
width: 20,
|
||||
height: 3,
|
||||
color: isCompleted ? Colors.green : Colors.grey,
|
||||
),
|
||||
SizedBox(width: 5),
|
||||
],
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Status Texts
|
||||
// PENDING PROCESSING SHIPPED DELIVERED CANCELLED RETURNED)
|
||||
|
||||
String _getStatusTextForStep(orderStatus) {
|
||||
switch (orderStatus) {
|
||||
case 'PENDING':
|
||||
return "PENDING";
|
||||
case 'SHIPPED':
|
||||
return "SHIPPED";
|
||||
case 'DELIVERD':
|
||||
return "DELIVERD";
|
||||
case 'PROCESSING':
|
||||
return "PROCESSING";
|
||||
case 'DELIVERED':
|
||||
return "DELIVERED";
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
@@ -165,22 +201,93 @@ class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
// final item = items[index];
|
||||
var orderitem = widget.order.orderItems![index];
|
||||
return Card(
|
||||
margin: EdgeInsets.symmetric(vertical: 8),
|
||||
child: ListTile(
|
||||
leading: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: AppNetworkImage(
|
||||
height: MediaQuery.of(context).size.height * 0.08,
|
||||
width: 48,
|
||||
imageUrl: orderitem.productImage ?? "",
|
||||
backGroundColor: Colors.transparent,
|
||||
margin: EdgeInsets.symmetric(vertical: 2),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
if (orderitem.orderItemStatus == "PENDING")
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
var status = await Provider.of<OrderProvider>(
|
||||
context,
|
||||
listen: false)
|
||||
.updateStatus(
|
||||
context, "CANCELLED", orderitem.id);
|
||||
},
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 5, vertical: 5),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green.shade100,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Text(" Cancel ",
|
||||
style: TextStyle(color: Colors.black)),
|
||||
),
|
||||
),
|
||||
Gap(5),
|
||||
if (orderitem.orderItemStatus != "PENDING")
|
||||
RichText(
|
||||
text: TextSpan(
|
||||
text: " ",
|
||||
style: context.buttonTestStyle.copyWith(
|
||||
color: context.appColor.blackColor,
|
||||
),
|
||||
children: [
|
||||
TextSpan(
|
||||
text: "GET OTP",
|
||||
style: context.buttonTestStyle.copyWith(
|
||||
color: Colors.blue,
|
||||
decoration: TextDecoration.underline,
|
||||
),
|
||||
recognizer: TapGestureRecognizer()
|
||||
..onTap = () {
|
||||
Provider.of<OrderProvider>(context,
|
||||
listen: false)
|
||||
.getAssignedOtp(context, orderitem.id);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
title: Text(orderitem.productName ?? ""),
|
||||
subtitle: Text("Qty: ${orderitem.quantity.toString()}"),
|
||||
trailing: Text("₹${orderitem.totalOrderItemPrice ?? ""}",
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
ListTile(
|
||||
leading: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: AppNetworkImage(
|
||||
height: MediaQuery.of(context).size.height * 0.08,
|
||||
width: 48,
|
||||
imageUrl: orderitem.productImage ?? "",
|
||||
backGroundColor: Colors.transparent,
|
||||
),
|
||||
),
|
||||
title: Text(orderitem.productName ?? ""),
|
||||
subtitle: Text("Qty: ${orderitem.quantity.toString()}"),
|
||||
trailing: Text("₹${orderitem.totalOrderItemPrice ?? ""}",
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
if (orderitem.orderItemStatus == "CANCELLED") ...{
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: Text("Order Cancelled",
|
||||
style: TextStyle(
|
||||
color: Colors.black, fontWeight: FontWeight.bold)),
|
||||
)
|
||||
} else ...{
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: _animatedShippingTimeline(orderitem.orderItemStatus),
|
||||
),
|
||||
}
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
@@ -188,21 +295,20 @@ class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
/// Cancel Order Button (Only if not delivered)
|
||||
Widget _cancelButton() {
|
||||
return ElevatedButton(
|
||||
onPressed: currentStep < 2
|
||||
? () {
|
||||
setState(() {
|
||||
currentStep = 2; // Simulate cancellation
|
||||
});
|
||||
}
|
||||
: null, // Disable if already delivered
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.red,
|
||||
disabledBackgroundColor: Colors.grey,
|
||||
),
|
||||
child: Text("Cancel Order", style: TextStyle(color: Colors.white)),
|
||||
);
|
||||
}
|
||||
// Widget _cancelButton() {
|
||||
// return ElevatedButton(
|
||||
// onPressed: currentStep < 2
|
||||
// ? () {
|
||||
// setState(() {
|
||||
// currentStep = 2;
|
||||
// });
|
||||
// }
|
||||
// : null,
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// backgroundColor: Colors.red,
|
||||
// disabledBackgroundColor: Colors.grey,
|
||||
// ),
|
||||
// child: Text("Cancel Order", style: TextStyle(color: Colors.white)),
|
||||
// );
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user