Skip to content

Commit 61dfbaf

Browse files
committedJun 2, 2021
bids and orders, without payment
1 parent 16ebe95 commit 61dfbaf

20 files changed

+710
-43
lines changed
 

‎lib/models/bids.dart

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import 'package:cloud_firestore/cloud_firestore.dart';
2+
3+
class Bids {
4+
final String? id;
5+
final String user;
6+
final String value;
7+
final DateTime publishedAt;
8+
9+
Bids({
10+
this.id,
11+
required this.user,
12+
required this.value,
13+
required this.publishedAt,
14+
});
15+
16+
factory Bids.fromDocument(DocumentSnapshot doc) {
17+
return Bids(
18+
id: doc.id,
19+
user: doc.data()?['user'].toString() ?? "",
20+
value: doc.data()?['value'] ?? "",
21+
publishedAt: DateTime.parse(
22+
(doc.data()!['publishedAt'] as Timestamp).toDate().toString()),
23+
);
24+
}
25+
26+
Map<String, dynamic> toMap() => {
27+
'user': user,
28+
'value': value,
29+
'publishedAt': publishedAt,
30+
};
31+
}

‎lib/models/order.dart

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import 'package:cloud_firestore/cloud_firestore.dart';
2+
3+
class Order {
4+
final String? id;
5+
final String userID;
6+
final String title;
7+
final String description;
8+
final String? category;
9+
final String? subcategory;
10+
final String condition;
11+
final double price;
12+
final List<String> images;
13+
final DateTime publishedAt;
14+
15+
Order({
16+
this.id,
17+
required this.userID,
18+
required this.title,
19+
required this.description,
20+
required this.category,
21+
this.subcategory,
22+
required this.condition,
23+
required this.price,
24+
required this.images,
25+
required this.publishedAt,
26+
});
27+
28+
factory Order.fromDocument(DocumentSnapshot doc) {
29+
return Order(
30+
id: doc.id,
31+
userID: doc.data()?['userID'].toString() ?? "",
32+
title: doc.data()?['title'] ?? "",
33+
description: doc.data()?['description'] ?? "",
34+
condition: doc.data()?['condition'] ?? "",
35+
price: doc.data()?['price'] ?? 0,
36+
category: doc.data()?['category'],
37+
subcategory: doc.data()?['subcategory'],
38+
images: List<String>.from(doc.data()?['images'] ?? []),
39+
publishedAt: DateTime.tryParse(
40+
(doc.data()?['publishedAt'] as Timestamp).toDate().toString()) ??
41+
DateTime.now(),
42+
);
43+
}
44+
45+
Map<String, dynamic> toMap() => {
46+
'userID': userID,
47+
'title': title,
48+
'description': description,
49+
'condition': condition,
50+
'category': category,
51+
'subcategory': subcategory,
52+
'price': price,
53+
'images': images,
54+
'publishedAt': publishedAt,
55+
};
56+
}

‎lib/screens/account/addNewProduct.dart

+16-8
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,15 @@ class _AddNewProductState extends State<AddNewProduct> {
3838

3939
Map<String, List<String>> categoryList = {
4040
'Fashion': ["Clothing", "Accessories", "Shoes"],
41-
'Electronics': ["Mobiles","Mobile Accessories", "Headphones", "Speakers", "Cameras", "Gaming Consoles", "Household Appliances"],
41+
'Electronics': [
42+
"Mobiles",
43+
"Mobile Accessories",
44+
"Headphones",
45+
"Speakers",
46+
"Cameras",
47+
"Gaming Consoles",
48+
"Household Appliances"
49+
],
4250
'Collectibles': ["Stamps", "Antiques", "Comics", "Coins", "Toys"],
4351
'Handbags': ["Leather Bag", "Satchel Bag", "Shoulder Bag", "Saddle Bag"],
4452
'Watches': ["Analog", "Digital"],
@@ -59,9 +67,9 @@ class _AddNewProductState extends State<AddNewProduct> {
5967
compressQuality: 80,
6068
androidUiSettings: AndroidUiSettings(
6169
hideBottomControls: true,
62-
toolbarColor: Color(0xFFFFA53E),
63-
cropGridColor: Color(0xFFFFA53E),
64-
cropFrameColor: Color(0xFFFFA53E),
70+
toolbarColor: kAccentColor,
71+
cropGridColor: kAccentColor,
72+
cropFrameColor: kAccentColor,
6573
toolbarWidgetColor: Colors.white,
6674
dimmedLayerColor: Colors.white,
6775
),
@@ -75,8 +83,8 @@ class _AddNewProductState extends State<AddNewProduct> {
7583
SnackBar(content: Text("This image can not be used")));
7684
}
7785
} catch (error) {
78-
ScaffoldMessenger.of(context).showSnackBar(
79-
SnackBar(content: Text("Something went wrong")));
86+
ScaffoldMessenger.of(context)
87+
.showSnackBar(SnackBar(content: Text("Something went wrong")));
8088
}
8189
}
8290

@@ -91,8 +99,8 @@ class _AddNewProductState extends State<AddNewProduct> {
9199
condition: condition,
92100
quickSellPrice: double.parse(quickSellController.text),
93101
isUpForBidding: isUpForBidding,
94-
minimumBid: double.parse(minimumBidController.text),
95-
biddingTime: biddingTime,
102+
minimumBid: double.tryParse(minimumBidController.text) ?? null,
103+
biddingTime: isUpForBidding ? biddingTime : null,
96104
images: images,
97105
isActive: true,
98106
);

‎lib/screens/account/orderHistory.dart

+17-16
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import 'package:bidding_app/models/product.dart';
1+
import 'package:bidding_app/models/order.dart';
22
import 'package:bidding_app/models/user.dart';
3-
import 'package:bidding_app/services/userDbService.dart';
3+
import 'package:bidding_app/services/orderDbService.dart';
44
import 'package:bidding_app/widgets/commonUI/AppStreamBuilder.dart';
5-
import 'package:bidding_app/widgets/productCard.dart';
5+
import 'package:bidding_app/widgets/orderCard.dart';
66
import 'package:flutter/material.dart';
77
import 'package:provider/provider.dart';
88

@@ -16,19 +16,20 @@ class MyOrders extends StatelessWidget {
1616
body: Container(
1717
child: Column(
1818
children: [
19-
// Expanded(
20-
// child: StrmBldr<List<Order>>(
21-
// stream: UserDBServices().fetchMyOrders(),
22-
// noDataWidget: Center(
23-
// child: Text("You haven't ordered anything yet")),
24-
// builder: (context, value) {
25-
// return ListView.builder(
26-
// children:
27-
// value!.map((e) => OrederCard(order: e)).toList(),
28-
// );
29-
// },
30-
// ),
31-
// ),
19+
Expanded(
20+
child: StrmBldr<List<Order>>(
21+
stream: OrderDBServices(uid: context.watch<AppUser>().id)
22+
.fetchMyOrders(),
23+
noDataWidget:
24+
Center(child: Text("You haven't ordered anything yet")),
25+
builder: (context, value) {
26+
return ListView(
27+
children:
28+
value?.map((e) => OrderCard(order: e)).toList() ?? [],
29+
);
30+
},
31+
),
32+
),
3233
],
3334
),
3435
),

‎lib/screens/home/components/popular_product.dart

+8-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,14 @@ class PopularProducts extends StatelessWidget {
4242
builder: (context, value) {
4343
return SizedBox(
4444
height: 170,
45-
child: ListView.builder(
46-
scrollDirection: Axis.horizontal,
47-
itemCount: value!.length > 4 ? 4 : value.length,
48-
itemBuilder: (context, index) =>
49-
ProductCard(product: value[index]),
50-
),
45+
child: value != null
46+
? ListView.builder(
47+
scrollDirection: Axis.horizontal,
48+
itemCount: value.length > 4 ? 4 : value.length,
49+
itemBuilder: (context, index) =>
50+
ProductCard(product: value[index]),
51+
)
52+
: Center(child: Text("No Popular Products")),
5153
);
5254
},
5355
),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import 'package:bidding_app/models/bids.dart';
2+
import 'package:bidding_app/models/user.dart';
3+
import 'package:bidding_app/services/orderDbService.dart';
4+
import 'package:bidding_app/widgets/bidTile.dart';
5+
import 'package:bidding_app/widgets/commonUI/AppStreamBuilder.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:provider/provider.dart';
8+
9+
class AllBids extends StatelessWidget {
10+
final String productId;
11+
final ScrollController scrollController;
12+
const AllBids({required this.productId, required this.scrollController});
13+
14+
@override
15+
Widget build(BuildContext context) {
16+
return StrmBldr<List<Bids>>(
17+
noDataWidget: const Center(
18+
child: Text("No bids yet"),
19+
),
20+
stream: OrderDBServices().fetchAllBids(productId),
21+
builder: (context, value) {
22+
return Scrollbar(
23+
child: ListView(
24+
controller: scrollController,
25+
reverse: true,
26+
shrinkWrap: true,
27+
children: value
28+
?.map(
29+
(bid) => BidTile(
30+
bid: bid.value,
31+
byMe: bid.user == context.watch<AppUser>().id,
32+
time: bid.publishedAt,
33+
),
34+
)
35+
.toList() ??
36+
[],
37+
),
38+
);
39+
},
40+
);
41+
}
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import 'package:bidding_app/models/product.dart';
2+
import 'package:bidding_app/models/user.dart';
3+
import 'package:bidding_app/services/orderDbService.dart';
4+
import 'package:flutter/material.dart';
5+
import 'package:intl/intl.dart';
6+
import 'package:provider/provider.dart';
7+
8+
class BidBottom extends StatefulWidget {
9+
final Product product;
10+
final ScrollController scrollController;
11+
12+
const BidBottom(
13+
{Key? key, required this.product, required this.scrollController})
14+
: super(key: key);
15+
16+
@override
17+
_BidBottomState createState() => _BidBottomState();
18+
}
19+
20+
class _BidBottomState extends State<BidBottom> {
21+
final textController = TextEditingController();
22+
bool timer = false;
23+
Future<void> addBid(AppUser user) async {
24+
final String bid = textController.text;
25+
textController.clear();
26+
27+
await OrderDBServices(uid: user.id).addNewBid(
28+
pId: widget.product.id,
29+
value: bid,
30+
);
31+
}
32+
33+
@override
34+
void initState() {
35+
DateTime? time = widget.product.biddingTime;
36+
if (time != null) {
37+
setState(() {
38+
timer = DateTime.now().isAfter(time) &&
39+
DateTime.now().isBefore(time.add(const Duration(days: 1)));
40+
});
41+
}
42+
super.initState();
43+
}
44+
45+
@override
46+
Widget build(BuildContext context) {
47+
return Container(
48+
color: Colors.white,
49+
padding: const EdgeInsets.all(8.0),
50+
child: Container(
51+
decoration: BoxDecoration(
52+
borderRadius: BorderRadius.circular(15),
53+
boxShadow: [BoxShadow(blurRadius: 10, color: Colors.grey[300]!)],
54+
color: Colors.white,
55+
),
56+
// height: 60.0,
57+
child: timer
58+
? Padding(
59+
padding: const EdgeInsets.all(8.0),
60+
child: Row(
61+
children: [
62+
Expanded(
63+
child: TextField(
64+
minLines: 1,
65+
maxLines: 1,
66+
onSubmitted: (value) => addBid(context.read<AppUser>()),
67+
keyboardType: TextInputType.number,
68+
controller: textController,
69+
decoration: const InputDecoration(
70+
hintText: "Your Bid",
71+
hintStyle: TextStyle(
72+
fontSize: 16,
73+
),
74+
border: InputBorder.none),
75+
),
76+
),
77+
IconButton(
78+
icon: const Icon(Icons.send),
79+
iconSize: 25.0,
80+
color: Theme.of(context).accentColor,
81+
onPressed: () => addBid(context.read<AppUser>()),
82+
),
83+
],
84+
),
85+
)
86+
: ListTile(
87+
leading: Text("Auction Starts on"),
88+
title: Text(DateFormat.yMMMMd('en_US')
89+
.format(widget.product.biddingTime!)),
90+
subtitle:
91+
Text(DateFormat.jm().format(widget.product.biddingTime!)),
92+
),
93+
),
94+
);
95+
}
96+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import 'dart:async';
2+
import 'package:bidding_app/models/product.dart';
3+
import 'package:bidding_app/services/productDbService.dart';
4+
import 'package:cloud_firestore/cloud_firestore.dart';
5+
import 'package:flutter/material.dart';
6+
import 'package:provider/provider.dart';
7+
8+
class BidTimer extends StatefulWidget {
9+
final Product? product;
10+
const BidTimer({this.product}) : super();
11+
@override
12+
_BidTimerState createState() => _BidTimerState();
13+
}
14+
15+
class _BidTimerState extends State<BidTimer> {
16+
bool timerWorks = false;
17+
late Duration timeLeft;
18+
Timer? timer;
19+
Future<void> init() async {
20+
debugPrint("TIMER STARTED${DateTime.now()}");
21+
final time = widget.product?.biddingTime;
22+
if (time == null) {
23+
return;
24+
} else {
25+
timeLeft = time.add(const Duration(days: 1)).difference(DateTime.now());
26+
if (timeLeft.isNegative) {
27+
timerWorks = false;
28+
}
29+
if (!timeLeft.isNegative) {
30+
timerWorks = true;
31+
timeLeft = timeLeft.abs();
32+
timer = Timer.periodic(const Duration(seconds: 1), (t) {
33+
timeLeft = timeLeft - const Duration(seconds: 1);
34+
if (timeLeft.isNegative) {
35+
timerWorks = false;
36+
try {
37+
if (mounted) {
38+
showDialog(
39+
context: context,
40+
builder: (BuildContext context) {
41+
return AlertDialog(
42+
title: Text('Bidding Ended',
43+
style:
44+
const TextStyle(fontWeight: FontWeight.bold)),
45+
content: Text(
46+
"The bidding period for this product has ended!"),
47+
actions: <Widget>[
48+
TextButton(
49+
onPressed: () {
50+
Navigator.of(context).pop();
51+
},
52+
child: const Text("Dismiss"),
53+
)
54+
]);
55+
},
56+
);
57+
setState(() {});
58+
}
59+
} catch (e) {
60+
debugPrint(e.toString());
61+
}
62+
t.cancel();
63+
}
64+
if (mounted) {
65+
setState(() {});
66+
}
67+
});
68+
setState(() {});
69+
}
70+
}
71+
}
72+
73+
String getDurationShort(Duration duration) {
74+
String twoDigits(int n) => n.toString().padLeft(2, "0");
75+
final twoDigitHours = twoDigits(duration.inHours.remainder(60));
76+
final twoDigitMinutes = twoDigits(duration.inMinutes.remainder(60));
77+
final twoDigitSeconds = twoDigits(duration.inSeconds.remainder(60));
78+
return "$twoDigitHours:$twoDigitMinutes:$twoDigitSeconds";
79+
}
80+
81+
@override
82+
void dispose() {
83+
timer?.cancel();
84+
super.dispose();
85+
}
86+
87+
@override
88+
void initState() {
89+
super.initState();
90+
init();
91+
}
92+
93+
@override
94+
Widget build(BuildContext context) {
95+
return Text(timerWorks ? getDurationShort(timeLeft) : '--:--');
96+
}
97+
}

‎lib/screens/product/bids.dart

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import 'package:bidding_app/models/product.dart';
2+
import 'package:bidding_app/screens/product/bidingComponents/allBids.dart';
3+
import 'package:bidding_app/screens/product/bidingComponents/bidBottom.dart';
4+
import 'package:bidding_app/screens/product/bidingComponents/bidTimer.dart';
5+
import 'package:bidding_app/utils/constants.dart';
6+
import 'package:flutter/material.dart';
7+
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
8+
9+
class ProductBids extends StatefulWidget {
10+
final Product product;
11+
ProductBids({required this.product});
12+
@override
13+
_ProductBidsState createState() => _ProductBidsState();
14+
}
15+
16+
class _ProductBidsState extends State<ProductBids> {
17+
final ScrollController _scrollController = ScrollController();
18+
bool timer = false;
19+
20+
@override
21+
void initState() {
22+
DateTime? time = widget.product.biddingTime;
23+
if (time != null) {
24+
setState(() {
25+
timer = DateTime.now().isAfter(time) &&
26+
DateTime.now().isBefore(time.add(const Duration(days: 1)));
27+
});
28+
}
29+
super.initState();
30+
}
31+
32+
@override
33+
Widget build(BuildContext context) {
34+
return Scaffold(
35+
resizeToAvoidBottomInset: true,
36+
appBar: AppBar(
37+
title: Text(widget.product.title),
38+
centerTitle: false,
39+
actions: timer
40+
? <Widget>[
41+
Padding(
42+
padding: const EdgeInsets.only(right: 5),
43+
child: Container(
44+
margin: const EdgeInsets.symmetric(vertical: 12),
45+
padding: const EdgeInsets.symmetric(horizontal: 10),
46+
alignment: Alignment.center,
47+
decoration: BoxDecoration(
48+
color: const Color(0xFFFF7643).withOpacity(0.2),
49+
borderRadius: BorderRadius.circular(20),
50+
),
51+
child: Row(
52+
textBaseline: TextBaseline.ideographic,
53+
crossAxisAlignment: CrossAxisAlignment.baseline,
54+
children: [
55+
const Icon(FontAwesomeIcons.stopwatch,
56+
size: 15, color: kPrimaryColor),
57+
const SizedBox(
58+
width: 5,
59+
),
60+
BidTimer(
61+
product: widget.product,
62+
),
63+
],
64+
),
65+
),
66+
),
67+
]
68+
: [],
69+
),
70+
body: Column(
71+
children: [
72+
Expanded(
73+
child: Container(
74+
color: Colors.white,
75+
child: AllBids(
76+
productId: widget.product.id ?? "",
77+
scrollController: _scrollController,
78+
),
79+
),
80+
),
81+
BidBottom(
82+
product: widget.product,
83+
scrollController: _scrollController,
84+
),
85+
],
86+
),
87+
);
88+
}
89+
}

‎lib/screens/product/productDetails.dart

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import 'package:bidding_app/models/product.dart';
22
import 'package:bidding_app/models/user.dart';
3+
import 'package:bidding_app/services/orderDbService.dart';
34
import 'package:bidding_app/services/productDbService.dart';
45
import 'package:bidding_app/utils/constants.dart';
6+
import 'package:bidding_app/utils/routing/RoutingUtils.dart';
57
import 'package:bidding_app/utils/size_config.dart';
68
import 'package:bidding_app/widgets/commonUI/defaultButton.dart';
79
import 'package:flutter/material.dart';
@@ -127,7 +129,7 @@ class _ProductDetailsState extends State<ProductDetails> {
127129
padding: EdgeInsets.symmetric(
128130
horizontal: getProportionateScreenWidth(20)),
129131
child: Text(
130-
product!.category!,
132+
product?.category ?? "",
131133
style: TextStyle(
132134
fontWeight: FontWeight.bold,
133135
color: kPrimaryColor),
@@ -214,14 +216,17 @@ class _ProductDetailsState extends State<ProductDetails> {
214216
DefaultButton(
215217
width: SizeConfig.screenWidth / 3,
216218
text: "Quick Buy",
217-
press: () {},
219+
press: () async {
220+
await OrderDBServices(uid: context.read<AppUser>().id)
221+
.makeOrder(
222+
product: product!, price: product!.quickSellPrice);
223+
},
218224
),
219-
product!.isUpForBidding
225+
product?.isUpForBidding ?? false
220226
? DefaultButton(
221227
width: SizeConfig.screenWidth / 3,
222228
text: "Bidding",
223-
press: () {},
224-
)
229+
press: () => Navigator.pushNamed(context, Routes.bidding, arguments: product))
225230
: Container(),
226231
],
227232
),

‎lib/services/orderDbService.dart

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import 'package:bidding_app/models/bids.dart';
2+
import 'package:bidding_app/models/order.dart';
3+
import 'package:bidding_app/models/product.dart';
4+
import 'package:cloud_firestore/cloud_firestore.dart';
5+
6+
class OrderDBServices {
7+
String? uid;
8+
late CollectionReference productsRef;
9+
late CollectionReference userRef;
10+
11+
OrderDBServices({String? uid}) {
12+
this.uid = uid;
13+
productsRef = FirebaseFirestore.instance.collection('products');
14+
userRef = FirebaseFirestore.instance.collection('users');
15+
}
16+
17+
Future makeOrder({
18+
required Product product,
19+
required double price,
20+
}) async {
21+
Order order = Order(
22+
userID: uid!,
23+
title: product.title,
24+
description: product.description,
25+
category: product.category,
26+
subcategory: product.subcategory,
27+
condition: product.condition,
28+
price: price,
29+
images: product.images,
30+
publishedAt: DateTime.now());
31+
await userRef.doc(uid).collection('orders').add(order.toMap());
32+
await productsRef.doc(product.id).delete();
33+
}
34+
35+
Stream<List<Order>> fetchMyOrders() {
36+
return userRef
37+
.doc(uid)
38+
.collection('orders')
39+
.orderBy('publishedAt', descending: true)
40+
.snapshots()
41+
.asyncMap<List<Order>>((event) =>
42+
event.docs.map<Order>((d) => Order.fromDocument(d)).toList());
43+
}
44+
45+
Future addNewBid({required pId, required String value}) async {
46+
Bids bid = Bids(
47+
user: uid!,
48+
value: value,
49+
publishedAt: DateTime.now(),
50+
);
51+
await productsRef.doc(pId).collection('bids').add(bid.toMap());
52+
}
53+
54+
Stream<List<Bids>> fetchAllBids(String pId) => productsRef
55+
.doc(pId)
56+
.collection('bids')
57+
.orderBy('publishedAt', descending: true)
58+
.snapshots()
59+
.map<List<Bids>>(
60+
(event) => event.docs.map((e) => Bids.fromDocument(e)).toList());
61+
}

‎lib/services/productDbService.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class ProductDBServices {
124124
event.docs.map<Product>((d) => Product.fromDocument(d)).toList());
125125
}
126126

127-
Future removePost(String id) async {
127+
Future removeProduct(String id) async {
128128
return productsRef.doc(id).delete();
129129
}
130130
}

‎lib/utils/constants.dart

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
22
import 'package:bidding_app/utils/size_config.dart';
33

44
const kPrimaryColor = Color(0xFFFF7643);
5+
const kAccentColor = Color(0xFFFFA53E);
56
const kPrimaryLightColor = Color(0xFFFFECDF);
67
const kPrimaryGradientColor = LinearGradient(
78
begin: Alignment.topLeft,

‎lib/utils/routing/RoutingUtils.dart

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ class Routes {
3131
static const String productDetails = 'productDetails';
3232
static const String popularProducts = 'popularProduct';
3333

34+
//order
35+
static const String bidding = 'bidding';
36+
static const String orderDetails = 'orderDetails';
37+
3438
//account
3539
static const String myProducts = 'myProducts';
3640
static const String orderHistory = 'orderHistory';

‎lib/utils/routing/router.dart

+20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:bidding_app/models/product.dart';
12
import 'package:bidding_app/screens/account/addNewProduct.dart';
23
import 'package:bidding_app/screens/account/editUserProfile.dart';
34
import 'package:bidding_app/screens/account/helpCenter.dart';
@@ -13,6 +14,7 @@ import 'package:bidding_app/screens/auth/signUp.dart';
1314
import 'package:bidding_app/screens/favorites.dart';
1415
import 'package:bidding_app/screens/product/allPopularProducts.dart';
1516
import 'package:bidding_app/screens/home/homepage.dart';
17+
import 'package:bidding_app/screens/product/bids.dart';
1618
import 'package:bidding_app/screens/product/productDetails.dart';
1719
import 'package:bidding_app/screens/account.dart';
1820
import 'package:bidding_app/services/auth.dart';
@@ -114,6 +116,24 @@ class Router {
114116
case Routes.popularProducts:
115117
return routify(AllPopularProducts());
116118

119+
// order
120+
case Routes.bidding:
121+
if (settings.arguments is Product) {
122+
return routify(ProductBids(
123+
product: settings.arguments as Product,
124+
));
125+
} else {
126+
return routify(wrong);
127+
}
128+
case Routes.orderDetails:
129+
// if (settings.arguments is String) {
130+
// return routify(OrderDetails(
131+
// oId: settings.arguments as String,
132+
// ));
133+
// } else {
134+
return routify(wrong);
135+
// }
136+
117137
// Paste new routes above this
118138
default:
119139
return routify(

‎lib/widgets/bidTile.dart

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import 'package:bidding_app/utils/constants.dart';
2+
import 'package:flutter/material.dart';
3+
import 'package:intl/intl.dart';
4+
5+
class BidTile extends StatelessWidget {
6+
final String bid;
7+
final bool byMe;
8+
final DateTime time;
9+
10+
const BidTile(
11+
{required this.bid, required this.byMe, required this.time});
12+
@override
13+
Widget build(BuildContext context) {
14+
final bg = byMe ? Colors.grey[200] : kAccentColor;
15+
final dynamic radius = BorderRadius.only(
16+
topLeft: const Radius.circular(8),
17+
topRight: const Radius.circular(8),
18+
bottomRight:
19+
byMe ? const Radius.circular(0) : const Radius.circular(8),
20+
bottomLeft:
21+
byMe ? const Radius.circular(8) : const Radius.circular(0),
22+
);
23+
const dynamic margin = EdgeInsets.only(bottom: 1.5);
24+
return Container(
25+
padding: const EdgeInsets.all(8.0),
26+
margin:
27+
EdgeInsets.only(left: byMe ? 80 : 0, right: byMe ? 0 : 80),
28+
alignment: byMe ? Alignment.centerRight : Alignment.centerLeft,
29+
child: Container(
30+
margin: margin as EdgeInsetsGeometry,
31+
constraints: const BoxConstraints(minWidth: 80),
32+
padding:
33+
const EdgeInsets.only(top: 10, bottom: 10, left: 15, right: 15),
34+
decoration: BoxDecoration(
35+
borderRadius: radius as BorderRadiusGeometry,
36+
color: bg,
37+
),
38+
child: Stack(
39+
children: <Widget>[
40+
Padding(
41+
padding: const EdgeInsets.only(bottom: 15.0),
42+
child: Text(
43+
bid,
44+
textAlign: byMe ? TextAlign.right : TextAlign.left,
45+
style: TextStyle(
46+
color: byMe ? Colors.black : Colors.white,
47+
),
48+
),
49+
),
50+
Positioned(
51+
right: 0,
52+
bottom: 0,
53+
child: Row(
54+
children: [
55+
Text(
56+
DateFormat.jm().format(time).toString(),
57+
style: TextStyle(
58+
fontSize: 9.0,
59+
color: byMe ? Colors.black : Colors.white),
60+
),
61+
],
62+
),
63+
),
64+
],
65+
),
66+
),
67+
);
68+
}
69+
}

‎lib/widgets/orderCard.dart

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import 'package:bidding_app/models/order.dart';
2+
import 'package:bidding_app/utils/constants.dart';
3+
import 'package:bidding_app/utils/routing/RoutingUtils.dart';
4+
import 'package:bidding_app/utils/size_config.dart';
5+
import 'package:flutter/material.dart';
6+
7+
class OrderCard extends StatelessWidget {
8+
final Order order;
9+
const OrderCard({required this.order});
10+
11+
@override
12+
Widget build(BuildContext context) {
13+
return Card(
14+
elevation: 3.0,
15+
child: ListTile(
16+
shape: RoundedRectangleBorder(
17+
borderRadius: BorderRadius.circular(10.0),
18+
),
19+
onTap: () => Navigator.pushNamed(
20+
context,
21+
Routes.orderDetails,
22+
arguments: order.id!,
23+
),
24+
leading: Container(
25+
decoration: BoxDecoration(
26+
color: kSecondaryColor.withOpacity(0.1),
27+
borderRadius: BorderRadius.circular(15),
28+
),
29+
child: Hero(
30+
tag: order.id.toString(),
31+
child: Image.network(order.images[0]),
32+
),
33+
),
34+
title: Text(
35+
order.title,
36+
style: TextStyle(color: Colors.black),
37+
maxLines: 2,
38+
),
39+
subtitle: Text(
40+
"₹${order.price}",
41+
style: TextStyle(
42+
fontSize: getProportionateScreenWidth(18),
43+
fontWeight: FontWeight.w600,
44+
color: kPrimaryColor,
45+
),
46+
),
47+
),
48+
);
49+
}
50+
}

‎lib/widgets/productCard.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class _ProductCardState extends State<ProductCard> {
3333
super.didUpdateWidget(oldWidget);
3434
}
3535

36-
bool isLiked() => (product!.likes).contains(context.watch<AppUser>().id);
37-
bool isLiked2() => (product!.likes).contains(context.read<AppUser>().id);
36+
bool isLiked() =>
37+
(product?.likes ?? []).contains(context.watch<AppUser>().id);
38+
bool isLiked2() =>
39+
(product?.likes ?? []).contains(context.read<AppUser>().id);
3840
likeUnlike() async {
3941
if (isLiked2()) {
4042
await ProductDBServices(uid: context.read<AppUser>().id)
@@ -87,7 +89,7 @@ class _ProductCardState extends State<ProductCard> {
8789
Flexible(
8890
flex: 3,
8991
child: Text(
90-
product!.title,
92+
product?.title ?? "",
9193
style: TextStyle(color: Colors.black),
9294
maxLines: 2,
9395
),
@@ -101,7 +103,7 @@ class _ProductCardState extends State<ProductCard> {
101103
mainAxisAlignment: MainAxisAlignment.spaceBetween,
102104
children: [
103105
Text(
104-
"₹${product!.quickSellPrice.toInt()}",
106+
"₹${product!.quickSellPrice}",
105107
style: TextStyle(
106108
fontSize: getProportionateScreenWidth(18),
107109
fontWeight: FontWeight.w600,

‎pubspec.lock

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ packages:
1414
name: async
1515
url: "https://pub.dartlang.org"
1616
source: hosted
17-
version: "2.5.0"
17+
version: "2.6.1"
1818
boolean_selector:
1919
dependency: transitive
2020
description:
@@ -552,7 +552,7 @@ packages:
552552
name: source_span
553553
url: "https://pub.dartlang.org"
554554
source: hosted
555-
version: "1.8.0"
555+
version: "1.8.1"
556556
sqflite:
557557
dependency: transitive
558558
description:
@@ -608,7 +608,7 @@ packages:
608608
name: test_api
609609
url: "https://pub.dartlang.org"
610610
source: hosted
611-
version: "0.2.19"
611+
version: "0.3.0"
612612
timeago:
613613
dependency: "direct dev"
614614
description:

‎web/index.html

+33
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,39 @@
4040
});
4141
}
4242
</script>
43+
<!-- The core Firebase JS SDK is always required and must be listed first -->
44+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-app.js"></script>
45+
46+
<!-- TODO: Add SDKs for Firebase products that you want to use
47+
https://firebase.google.com/docs/web/setup#available-libraries -->
48+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-analytics.js"></script>
49+
50+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-auth.js"></script>
51+
52+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-firestore.js"></script>
53+
54+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-core.js"></script>
55+
56+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-messaging.js"></script>
57+
58+
<script src="https://www.gstatic.com/firebasejs/8.4.2/firebase-storage.js"></script>
59+
60+
<script>
61+
// Your web app's Firebase configuration
62+
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
63+
var firebaseConfig = {
64+
apiKey: "AIzaSyDDN5hmmVac9LMYwFP8CfguyHNePFeE_2c",
65+
authDomain: "bidding-app-34d90.firebaseapp.com",
66+
projectId: "bidding-app-34d90",
67+
storageBucket: "bidding-app-34d90.appspot.com",
68+
messagingSenderId: "124556225740",
69+
appId: "1:124556225740:web:3232b01f76589aa7ac2669",
70+
measurementId: "G-ZZNDLNDTHT"
71+
};
72+
// Initialize Firebase
73+
firebase.initializeApp(firebaseConfig);
74+
firebase.analytics();
75+
</script>
4376
<script src="main.dart.js" type="application/javascript"></script>
4477
</body>
4578
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.