orderlistcomplete
This commit is contained in:
205
lib/src/ui/myOrder/OrderDetailsScreen.dart
Normal file
205
lib/src/ui/myOrder/OrderDetailsScreen.dart
Normal file
@@ -0,0 +1,205 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:grocery_app/src/common_widget/network_image.dart';
|
||||
import 'package:grocery_app/src/data/myOrder.dart';
|
||||
|
||||
class OrderDetailsScreen extends StatefulWidget {
|
||||
final Datum order;
|
||||
|
||||
const OrderDetailsScreen({Key? key, required this.order}) : super(key: key);
|
||||
|
||||
@override
|
||||
_OrderDetailsScreenState createState() => _OrderDetailsScreenState();
|
||||
}
|
||||
|
||||
class _OrderDetailsScreenState extends State<OrderDetailsScreen> {
|
||||
int currentStep = 1;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: Text('Order Details')),
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_orderInfo(),
|
||||
SizedBox(height: 20),
|
||||
_animatedShippingTimeline(),
|
||||
SizedBox(height: 20),
|
||||
_itemsList(),
|
||||
SizedBox(height: 20),
|
||||
_cancelButton(),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Order Information
|
||||
Widget _orderInfo() {
|
||||
return Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
child: 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.createdAt.toString()),
|
||||
SizedBox(height: 5),
|
||||
Text(
|
||||
"Status: ${_getStatusText(widget.order.orderStatus)}",
|
||||
style:
|
||||
TextStyle(color: Colors.blue, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Animated Shipping Timeline
|
||||
Widget _animatedShippingTimeline() {
|
||||
return Column(
|
||||
children: [
|
||||
for (int i = 0; i < 3; i++) _timelineStep(i),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Each Step in the Timeline
|
||||
Widget _timelineStep(int step) {
|
||||
bool isCompleted = step <= currentStep;
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
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,
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(width: 10),
|
||||
Text(
|
||||
_getStatusTextForStep(widget.order.orderStatus),
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// Status Texts
|
||||
String _getStatusTextForStep(orderStatus) {
|
||||
switch (orderStatus) {
|
||||
case 'PENDING':
|
||||
return "PENDING";
|
||||
case 'SHIPPED':
|
||||
return "SHIPPED";
|
||||
case 'DELIVERD':
|
||||
return "DELIVERD";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
String _getStatusText(orderStatus) {
|
||||
switch (orderStatus) {
|
||||
case 'PENDING':
|
||||
return "PENDING";
|
||||
case 'SHIPPED':
|
||||
return "SHIPPED";
|
||||
case 'DELIVERD':
|
||||
return "DELIVERD";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// List of Ordered Items
|
||||
Widget _itemsList() {
|
||||
// final List<Map<String, dynamic>> items = [
|
||||
// {
|
||||
// "name": "Coffee",
|
||||
// "quantity": 2,
|
||||
// "price": 10.00,
|
||||
// "image": "https://via.placeholder.com/50"
|
||||
// },
|
||||
// {
|
||||
// "name": "Rice",
|
||||
// "quantity": 1,
|
||||
// "price": 10.50,
|
||||
// "image": "https://via.placeholder.com/50"
|
||||
// }
|
||||
// ];
|
||||
|
||||
return Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: widget.order.orderItems!.length,
|
||||
itemBuilder: (context, index) {
|
||||
// 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,
|
||||
),
|
||||
),
|
||||
title: Text(orderitem.productName ?? ""),
|
||||
subtitle: Text("Qty: ${orderitem.quantity.toString()}"),
|
||||
trailing: Text("\$${orderitem.price ?? ""}",
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user