master
Sneha 4 days ago
parent e49f859358
commit aa1d86d17e

@ -30,7 +30,6 @@ class _AllOrdersState extends State<AllOrders> {
@override @override
void initState() { void initState() {
// TODO: implement initState
super.initState(); super.initState();
_fetchOrders(); _fetchOrders();
} }
@ -59,25 +58,25 @@ class _AllOrdersState extends State<AllOrders> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// Group orders by date // Group orders by date
final Map<String, List<OrdersModel>> groupedOrders = {}; final Map<String, List<OrdersModel>> groupedOrders = {};
String formatOrderDate(String? dateStr) { String formatOrderDate(String? dateStr) {
if (dateStr == null || dateStr.trim().isEmpty) { if (dateStr == null || dateStr.trim().isEmpty) {
return ""; // or return a fallback like "N/A" return "";
} }
try { try {
final inputFormat = DateFormat("dd-MMM-yyyy"); // matches 10-Sep-2025 final inputFormat = DateFormat("dd-MMM-yyyy");
final outputFormat = DateFormat("dd MMM yyyy"); // output 10 Sep 2025 final outputFormat = DateFormat("dd MMM yyyy");
final parsedDate = inputFormat.parse(dateStr); final parsedDate = inputFormat.parse(dateStr);
return outputFormat.format(parsedDate); return outputFormat.format(parsedDate);
} catch (e) { } catch (e) {
print("Date parse error: $e"); print("Date parse error: $e");
return dateStr; // fallback to original string return dateStr;
} }
} }
for (var order in ordersList) { for (var order in ordersList) {
final formattedDate = formatOrderDate(order.date); // "10 Sep 2025" final formattedDate = formatOrderDate(order.date);
groupedOrders.putIfAbsent(formattedDate, () => []).add(order); groupedOrders.putIfAbsent(formattedDate, () => []).add(order);
} }
return Scaffold( return Scaffold(
@ -86,10 +85,7 @@ class _AllOrdersState extends State<AllOrders> {
SearchOrderAppBar( SearchOrderAppBar(
controller: searchController, controller: searchController,
onBack: () => Navigator.pop(context), onBack: () => Navigator.pop(context),
onHelp: () { onHelp: () {},
// Show help dialog or navigate
print("Help tapped");
},
):null, ):null,
body: isLoading body: isLoading
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
@ -99,143 +95,140 @@ class _AllOrdersState extends State<AllOrders> {
style: fontTextStyle(16,Color(0XFF000000),FontWeight.w700), style: fontTextStyle(16,Color(0XFF000000),FontWeight.w700),
), ),
):SingleChildScrollView( ):SingleChildScrollView(
child: child:
Padding( Padding(
padding: EdgeInsets.all(16), padding: EdgeInsets.all(16),
child: Column( child: Column(
children: [ children: [
SizedBox(height: MediaQuery.of(context).size.height * .042), SizedBox(height: MediaQuery.of(context).size.height * .042),
/// Total Orders /// Total Orders
Column( Column(
children: [ children: [
Text( Text(
"12", "12",
style:fontTextStyle(64, Color(0XFFFF2D2E30), FontWeight.w700), style:fontTextStyle(64, Color(0XFFFF2D2E30), FontWeight.w700),
), ),
Text( Text(
"Today's Total Orders", "Today's Total Orders",
style: fontTextStyle(24, Color(0XFFFF2D2E30), FontWeight.w600), style: fontTextStyle(24, Color(0XFFFF2D2E30), FontWeight.w600),
), ),
SizedBox(height: MediaQuery.of(context).size.height * .042), SizedBox(height: MediaQuery.of(context).size.height * .042),
/// Bore Water + Drinking Water /// Bore Water + Drinking Water
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
OrderCategoryCard( OrderCategoryCard(
image: Image.asset( image: Image.asset(
'images/bore-water.png', 'images/bore-water.png',
fit: BoxFit.contain, fit: BoxFit.contain,
height: 40, height: 40,
width: 40, width: 40,
),
value: "16",
label: "Bore Water",
), ),
value: "16", OrderCategoryCard(
label: "Bore Water", image: Image.asset(
), 'images/drinking-water.png',
OrderCategoryCard( height: 40,
image: Image.asset( width: 40,
'images/drinking-water.png', fit: BoxFit.contain,
height: 40, ),
width: 40, value: "08",
fit: BoxFit.contain, label: "Drinking Water",
), ),
value: "08", ],
label: "Drinking Water", ),
),
],
),
SizedBox(height: MediaQuery.of(context).size.height * .024), SizedBox(height: MediaQuery.of(context).size.height * .024),
/// Button /// Button
Container( Container(
width: double.infinity, width: double.infinity,
child: ElevatedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
backgroundColor:Color(0XFF8270DB), backgroundColor:Color(0XFF8270DB),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(32), borderRadius: BorderRadius.circular(32),
),
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 16),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrderRequestsPage()),
);
},
child: Text(
"View Order Requests",
style: fontTextStyle(16, Color(0XFFFFFFFFFF), FontWeight.w500),
), ),
padding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 16),
),
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => OrderRequestsPage()),
);
},
child: Text(
"View Order Requests",
style: fontTextStyle(16, Color(0XFFFFFFFFFF), FontWeight.w500),
), ),
), )
)
],
),
const SizedBox(height: 20),
/// Filters Row
SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
FilterChipWidget(label: "Building"),
const SizedBox(width: 8),
FilterChipWidget(label: "Status"),
const SizedBox(width: 8),
FilterChipWidget(label: "Date"),
const SizedBox(width: 8),
FilterChipWidget(label: "Amount"),
], ],
), ),
),
const SizedBox(height: 20), const SizedBox(height: 20),
/// Order Card Example /// Filters Row
/// Order List SingleChildScrollView(
ListView( scrollDirection: Axis.horizontal,
padding: const EdgeInsets.all(12), padding: const EdgeInsets.symmetric(horizontal: 12),
shrinkWrap: true, // Important child: Row(
physics: NeverScrollableScrollPhysics(), // Prevent nested scrolling
children: groupedOrders.entries.map((entry) {
final date = entry.key;
final ordersForDate = entry.value;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Date heading FilterChipWidget(label: "Building"),
Padding( const SizedBox(width: 8),
padding: const EdgeInsets.all(0), FilterChipWidget(label: "Status"),
child: Text( const SizedBox(width: 8),
date, FilterChipWidget(label: "Date"),
style:fontTextStyle(14, Color(0XFF343637), FontWeight.w600), const SizedBox(width: 8),
FilterChipWidget(label: "Amount"),
],
),
),
const SizedBox(height: 20),
/// Order List
ListView(
padding: const EdgeInsets.all(12),
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: groupedOrders.entries.map((entry) {
final date = entry.key;
final ordersForDate = entry.value;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(0),
child: Text(
date,
style:fontTextStyle(14, Color(0XFF343637), FontWeight.w600),
),
), ),
),
// Orders list for this date ...ordersForDate.map((order) => OrderCard(
...ordersForDate.map((order) => OrderCard( order: order,
order: order, onRefresh: _fetchOrders,
onRefresh: _fetchOrders, // 👈 pass parent function here )),
)), const SizedBox(height: 12),
const SizedBox(height: 12), ],
], );
); }).toList(),
}).toList(), ),
),
], ],
), ),
) )
), ),
); );
} }
} }
/// Category Card (Bore Water, Drinking Water) /// Category Card
class OrderCategoryCard extends StatelessWidget { class OrderCategoryCard extends StatelessWidget {
final Image image; final Image image;
final String value; final String value;
@ -255,7 +248,7 @@ class OrderCategoryCard extends StatelessWidget {
SizedBox( SizedBox(
width: 40, width: 40,
height: 40, height: 40,
child: image, // Replaced Icon with Image child: image,
), ),
SizedBox(height: MediaQuery.of(context).size.height * .008), SizedBox(height: MediaQuery.of(context).size.height * .008),
Text( Text(
@ -297,20 +290,26 @@ class OrderCard extends StatelessWidget {
Color _getStatusColor() { Color _getStatusColor() {
String st=''; String st='';
if(order.status.toLowerCase()=='advance_paid'){ if(order.status.toLowerCase()=='advance_paid'){
st='pending'; st='pending';
} }
else if(order.status.toLowerCase()=='accepted'){ // ADDED
st='pending';
}
else if(order.status.toLowerCase()=='deliveryboy_assigned'){ else if(order.status.toLowerCase()=='deliveryboy_assigned'){
st='assigned'; st='assigned';
} }
else if(order.status.toLowerCase()=='tanker_assigned'){ else if(order.status.toLowerCase()=='tanker_assigned'){
st='assigned'; st='assigned';
} }
else if(order.status.toLowerCase()=='delivered'){
st='completed';
}
else{ else{
st=order.status.toLowerCase(); st=order.status.toLowerCase();
} }
switch (st.toLowerCase()) { switch (st.toLowerCase()) {
case "completed": case "completed":
return Color(0XFFC4E8C3); return Color(0XFFC4E8C3);
@ -329,12 +328,19 @@ class OrderCard extends StatelessWidget {
Color _getTextStatusColor() { Color _getTextStatusColor() {
String st=''; String st='';
if(order.status.toLowerCase()=='advance_paid'){ if(order.status.toLowerCase()=='advance_paid'){
st='pending'; st='pending';
} }
else if(order.status.toLowerCase()=='accepted'){ // ADDED
st='pending';
}
else if(order.status.toLowerCase()=='deliveryboy_assigned'){ else if(order.status.toLowerCase()=='deliveryboy_assigned'){
st='assigned'; st='assigned';
} }
else if(order.status.toLowerCase()=='delivered'){
st='completed';
}
else if(order.status.toLowerCase()=='tanker_assigned'){ else if(order.status.toLowerCase()=='tanker_assigned'){
st='assigned'; st='assigned';
} }
@ -365,6 +371,10 @@ class OrderCard extends StatelessWidget {
String st = (order.status == 'advance_paid') String st = (order.status == 'advance_paid')
? 'pending' ? 'pending'
: (order.status.toLowerCase() == 'accepted') // ADDED
? 'pending'
: (order.status.toLowerCase() == 'delivered') // ADDED
? 'completed'
: (order.status.toString().toLowerCase() == 'deliveryboy_assigned') : (order.status.toString().toLowerCase() == 'deliveryboy_assigned')
? 'assigned' ? 'assigned'
: (order.status.toString().toLowerCase() == 'tanker_assigned') : (order.status.toString().toLowerCase() == 'tanker_assigned')
@ -387,23 +397,21 @@ class OrderCard extends StatelessWidget {
], ],
), ),
/// 👇 IntrinsicHeight allows both sides of the row to match height dynamically
child: IntrinsicHeight( child: IntrinsicHeight(
child: Row( child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch, // 👈 image stretches crossAxisAlignment: CrossAxisAlignment.stretch,
children: [ children: [
/// 🖼 Left Image
ClipRRect( ClipRRect(
borderRadius: const BorderRadius.only( borderRadius: const BorderRadius.only(
topLeft: Radius.circular(12), topLeft: Radius.circular(12),
bottomLeft: Radius.circular(12), bottomLeft: Radius.circular(12),
), ),
child: SizedBox( child: SizedBox(
width: 145, // fixed width width: 145,
child: order.imageAsset.isNotEmpty child: order.imageAsset.isNotEmpty
? Image.asset( ? Image.asset(
order.imageAsset, order.imageAsset,
fit: BoxFit.cover, // 👈 fills height fit: BoxFit.cover,
) )
: Image.network( : Image.network(
order.imageAsset, order.imageAsset,
@ -412,14 +420,12 @@ class OrderCard extends StatelessWidget {
), ),
), ),
/// 📄 Right Content
Expanded( Expanded(
child: Padding( child: Padding(
padding: const EdgeInsets.all(10.0), padding: const EdgeInsets.all(10.0),
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
// Status chip
Container( Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 8, horizontal: 8,
@ -456,11 +462,9 @@ class OrderCard extends StatelessWidget {
), ),
const SizedBox(height: 12), const SizedBox(height: 12),
/// ===================
/// 🟡 ASSIGN & CANCEL BUTTONS
/// ===================
Visibility( Visibility(
visible: order.status.toLowerCase() == 'advance_paid', visible: order.status.toLowerCase() == 'advance_paid'
|| order.status.toLowerCase() == 'accepted', // ADDED
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
@ -527,9 +531,6 @@ class OrderCard extends StatelessWidget {
), ),
), ),
/// ===================
/// 🟣 TRACK DELIVERY BUTTON
/// ===================
Visibility( Visibility(
visible: order.status.toLowerCase() == 'in_progress', visible: order.status.toLowerCase() == 'in_progress',
child: GestureDetector( child: GestureDetector(
@ -565,79 +566,80 @@ class OrderCard extends StatelessWidget {
), ),
Visibility( Visibility(
visible: st.toLowerCase() == 'assigned', visible: st.toLowerCase() == 'assigned',
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Image.asset( Image.asset(
'images/avatar.png', 'images/avatar.png',
fit: BoxFit.cover, fit: BoxFit.cover,
width: 12, width: 12,
height: 12, height: 12,
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
// Title + Chips Expanded(
Expanded( child: Column(
child: Column( crossAxisAlignment: CrossAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start, children: [
children: [ Row(
Row( children: [
children: [ Expanded(
Expanded( child: Text(
child: Text( order.delivery_agent_name!=''?
order.delivery_agent_name!=''?"Assigned to ${order.delivery_agent_name}":"Assigned to ${order.tanker_name}", "Assigned to ${order.delivery_agent_name}"
maxLines: 1, :"Assigned to ${order.tanker_name}",
overflow: TextOverflow.ellipsis, maxLines: 1,
style: fontTextStyle( overflow: TextOverflow.ellipsis,
8, const Color(0xFF646566), FontWeight.w400), style: fontTextStyle(
8, const Color(0xFF646566), FontWeight.w400),
),
), ),
), ],
], ),
),
], ],
),
), ),
),
], ],
), ),
SizedBox(height: MediaQuery.of(context).size.height * .004), SizedBox(height: MediaQuery.of(context).size.height * .004),
GestureDetector( GestureDetector(
onTap: () async { onTap: () async {
final result = await Navigator.push( final result = await Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ChangeDriverScreen(order: order), builder: (context) => ChangeDriverScreen(order: order),
),
);
if (result == true) {
onRefresh?.call();
}
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22),
color: const Color(0XFF8270DB),
border: Border.all(color: const Color(0XFF8270DB)),
), ),
); child: const Padding(
if (result == true) { padding: EdgeInsets.fromLTRB(8, 4, 8, 4),
onRefresh?.call(); child: Text(
} "Change",
}, style: TextStyle(
child: Container( fontSize: 14,
decoration: BoxDecoration( color: Colors.white,
borderRadius: BorderRadius.circular(22), fontWeight: FontWeight.w400),
color: const Color(0XFF8270DB), ),
border: Border.all(color: const Color(0XFF8270DB)),
),
child: const Padding(
padding: EdgeInsets.fromLTRB(8, 4, 8, 4),
child: Text(
"Change",
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w400),
), ),
), ),
), ),
), ],
], )
)
), ),
@ -657,7 +659,6 @@ class OrderCard extends StatelessWidget {
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
// Title + Chips
Expanded( Expanded(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
@ -666,7 +667,9 @@ class OrderCard extends StatelessWidget {
children: [ children: [
Expanded( Expanded(
child: Text( child: Text(
order.delivery_agent_name!=''?"Delivered by ${order.delivery_agent_name}":"Assigned to ${order.tanker_name}", order.delivery_agent_name!=''?
"Delivered by ${order.delivery_agent_name}"
:"Assigned to ${order.tanker_name}",
maxLines: 1, maxLines: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: fontTextStyle( style: fontTextStyle(

Loading…
Cancel
Save