-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
e-Commerce Admin - Order Screen UI Added
- Loading branch information
1 parent
37df68b
commit 4e7cd37
Showing
9 changed files
with
362 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export 'product_model.dart'; | ||
export 'order_model.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:cloud_firestore/cloud_firestore.dart'; | ||
import 'package:equatable/equatable.dart'; | ||
|
||
class Order extends Equatable { | ||
final int id; | ||
final int customerId; | ||
final List<String> productIds; | ||
final double deliveryFee; | ||
final double subtotal; | ||
final double total; | ||
final bool isAccepted; | ||
final bool isDelivered; | ||
final bool isCancelled; | ||
final DateTime createdAt; | ||
|
||
const Order({ | ||
required this.id, | ||
required this.customerId, | ||
required this.productIds, | ||
required this.deliveryFee, | ||
required this.subtotal, | ||
required this.total, | ||
required this.isAccepted, | ||
required this.isDelivered, | ||
required this.isCancelled, | ||
required this.createdAt, | ||
}); | ||
|
||
Order copyWith({ | ||
int? id, | ||
int? customerId, | ||
List<String>? productIds, | ||
double? deliveryFee, | ||
double? subtotal, | ||
double? total, | ||
bool? isAccepted, | ||
bool? isDelivered, | ||
bool? isCancelled, | ||
DateTime? createdAt, | ||
}) { | ||
return Order( | ||
id: id ?? this.id, | ||
customerId: customerId ?? this.customerId, | ||
productIds: productIds ?? this.productIds, | ||
deliveryFee: deliveryFee ?? this.deliveryFee, | ||
subtotal: subtotal ?? this.subtotal, | ||
total: total ?? this.total, | ||
isAccepted: isAccepted ?? this.isAccepted, | ||
isDelivered: isDelivered ?? this.isDelivered, | ||
isCancelled: isCancelled ?? this.isCancelled, | ||
createdAt: createdAt ?? this.createdAt, | ||
); | ||
} | ||
|
||
Map<String, dynamic> toMap() { | ||
return { | ||
'id': id, | ||
'customerId': customerId, | ||
'productIds': productIds, | ||
'deliveryFee': deliveryFee, | ||
'subtotal': subtotal, | ||
'total': total, | ||
'isAccepted': isAccepted, | ||
'isDelivered': isDelivered, | ||
'isCancelled': isCancelled, | ||
'createdAt': createdAt.millisecondsSinceEpoch, | ||
}; | ||
} | ||
|
||
factory Order.fromSnapshot(DocumentSnapshot snap) { | ||
return Order( | ||
id: snap['id'], | ||
customerId: snap['customerId'], | ||
productIds: List<String>.from(snap['productIds']), | ||
deliveryFee: snap['deliveryFee'], | ||
subtotal: snap['subtotal'], | ||
total: snap['total'], | ||
isAccepted: snap['isAccepted'], | ||
isDelivered: snap['isDelivered'], | ||
isCancelled: snap['isCancelled'], | ||
createdAt: snap['createdAt'].toDate(), | ||
); | ||
} | ||
|
||
String toJson() => json.encode(toMap()); | ||
|
||
@override | ||
bool get stringify => true; | ||
|
||
@override | ||
List<Object> get props { | ||
return [ | ||
id, | ||
customerId, | ||
productIds, | ||
deliveryFee, | ||
subtotal, | ||
total, | ||
isAccepted, | ||
isDelivered, | ||
isCancelled, | ||
createdAt, | ||
]; | ||
} | ||
|
||
static List<Order> orders = [ | ||
Order( | ||
id: 1, | ||
customerId: 2345, | ||
productIds: const ['1', '2'], | ||
deliveryFee: 10, | ||
subtotal: 20, | ||
total: 30, | ||
isAccepted: false, | ||
isDelivered: false, | ||
isCancelled: false, | ||
createdAt: DateTime.now(), | ||
), | ||
Order( | ||
id: 2, | ||
customerId: 23, | ||
productIds: const ['1', '3', '2'], | ||
deliveryFee: 10, | ||
subtotal: 30, | ||
total: 30, | ||
isAccepted: false, | ||
isDelivered: false, | ||
isCancelled: false, | ||
createdAt: DateTime.now(), | ||
), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:intl/intl.dart'; | ||
|
||
import '../model/model.dart'; | ||
|
||
class OrderScreen extends StatelessWidget { | ||
const OrderScreen({Key? key}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: const Text('Orders Screen'), | ||
centerTitle: true, | ||
backgroundColor: Colors.black, | ||
), | ||
body: Column( | ||
children: [ | ||
Expanded( | ||
child: ListView.builder( | ||
itemCount: Order.orders.length, | ||
itemBuilder: (context, index) { | ||
return OrderCard( | ||
order: Order.orders[index], | ||
); | ||
}, | ||
), | ||
), | ||
], | ||
), | ||
); | ||
} | ||
} | ||
|
||
class OrderCard extends StatelessWidget { | ||
final Order order; | ||
const OrderCard({Key? key, required this.order}) : super(key: key); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
var products = Product.products.where((product) { | ||
return order.productIds.contains(product.id); | ||
}).toList(); | ||
|
||
return Padding( | ||
padding: const EdgeInsets.only( | ||
left: 10, | ||
right: 10, | ||
top: 10, | ||
), | ||
child: Card( | ||
margin: EdgeInsets.zero, | ||
child: Padding( | ||
padding: const EdgeInsets.all(10.0), | ||
child: Column( | ||
children: [ | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
children: [ | ||
Text( | ||
'Order ID: ${order.id}', | ||
style: const TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
Text( | ||
DateFormat('MMM dd, yyyy').format(order.createdAt), | ||
style: const TextStyle( | ||
fontSize: 14, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
], | ||
), | ||
const SizedBox(height: 10), | ||
const SizedBox(height: 10), | ||
ListView.builder( | ||
shrinkWrap: true, | ||
physics: const NeverScrollableScrollPhysics(), | ||
itemCount: products.length, | ||
itemBuilder: (context, index) { | ||
return Padding( | ||
padding: const EdgeInsets.only(bottom: 10), | ||
child: Row( | ||
children: [ | ||
SizedBox( | ||
height: 50, | ||
width: 50, | ||
child: Image.network( | ||
products[index].imageUrl, | ||
fit: BoxFit.cover, | ||
), | ||
), | ||
const SizedBox(width: 10), | ||
Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Text( | ||
products[index].name, | ||
style: const TextStyle( | ||
fontSize: 14, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 5), | ||
SizedBox( | ||
width: 285, | ||
child: Text( | ||
products[index].description, | ||
style: const TextStyle( | ||
fontSize: 12, | ||
), | ||
maxLines: 2, | ||
overflow: TextOverflow.clip, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
); | ||
}), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
children: [ | ||
Column( | ||
children: [ | ||
const Text( | ||
'Delivery Fee', | ||
style: TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 10), | ||
Text( | ||
'\$${order.deliveryFee}', | ||
style: const TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
], | ||
), | ||
Column( | ||
children: [ | ||
const Text( | ||
'Total Fee', | ||
style: TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
const SizedBox(height: 10), | ||
Text( | ||
'\$${order.total}', | ||
style: const TextStyle( | ||
fontSize: 16, | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
], | ||
), | ||
], | ||
), | ||
const SizedBox(height: 10), | ||
Row( | ||
mainAxisAlignment: MainAxisAlignment.spaceAround, | ||
children: [ | ||
ElevatedButton( | ||
onPressed: () {}, | ||
style: ElevatedButton.styleFrom( | ||
primary: Colors.black, | ||
minimumSize: const Size(150, 40), | ||
), | ||
child: const Text( | ||
'Accept', | ||
style: TextStyle( | ||
fontSize: 12, | ||
), | ||
), | ||
), | ||
ElevatedButton( | ||
onPressed: () {}, | ||
style: ElevatedButton.styleFrom( | ||
primary: Colors.black, | ||
minimumSize: const Size(150, 40), | ||
), | ||
child: const Text( | ||
'Cancel', | ||
style: TextStyle( | ||
fontSize: 12, | ||
), | ||
), | ||
), | ||
], | ||
) | ||
], | ||
), | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export 'add_new_product_screen.dart'; | ||
export 'home_screen.dart'; | ||
export 'product_screen.dart'; | ||
export 'order_screen.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export 'database_service.dart'; | ||
export 'storage_service.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.