Skip to content

Commit 51a9191

Browse files
committed
Crop registration Added to flutter
1 parent e4fbdcb commit 51a9191

20 files changed

+950
-118
lines changed

kisan/lib/models/register_crop.dart

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import 'package:cloud_firestore/cloud_firestore.dart';
2+
3+
class RegisteredCrop {
4+
String cropName;
5+
String minBid;
6+
String totalWeight;
7+
String state;
8+
String phoneNumber;
9+
DateTime timestamp;
10+
11+
// Constructor
12+
RegisteredCrop({
13+
required this.cropName,
14+
required this.minBid,
15+
required this.totalWeight,
16+
required this.state,
17+
required this.phoneNumber,
18+
required this.timestamp,
19+
});
20+
21+
// Factory constructor to create an instance from Firestore Document
22+
factory RegisteredCrop.fromFirestore(Map<String, dynamic> firestoreData) {
23+
return RegisteredCrop(
24+
cropName: firestoreData['cropName'] ?? '',
25+
minBid: firestoreData['minBid'] ?? '',
26+
totalWeight: firestoreData['totalWeight'] ?? '',
27+
state: firestoreData['state'] ?? '',
28+
phoneNumber: firestoreData['phoneNumber'] ?? '',
29+
timestamp: (firestoreData['timestamp'] as Timestamp).toDate(),
30+
);
31+
}
32+
33+
// Method to convert the RegisteredCrop object to a Map (for saving to Firestore)
34+
Map<String, dynamic> toMap() {
35+
return {
36+
'cropName': cropName,
37+
'minBid': minBid,
38+
'totalWeight': totalWeight,
39+
'state': state,
40+
'phoneNumber': phoneNumber,
41+
'timestamp': Timestamp.fromDate(timestamp),
42+
};
43+
}
44+
45+
// Method to save the RegisteredCrop object to Firestore
46+
Future<void> saveToFirestore() async {
47+
try {
48+
// Get a reference to the 'registered_crops' collection
49+
CollectionReference cropsCollection =
50+
FirebaseFirestore.instance.collection('registered_crops');
51+
52+
// Add the RegisteredCrop data to Firestore
53+
await cropsCollection.add(toMap());
54+
55+
print('Crop registered successfully!');
56+
} catch (e) {
57+
print('Failed to register crop: $e');
58+
}
59+
}
60+
}
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import 'package:flutter/material.dart';
2+
//import 'internet_banking_page.dart';
3+
4+
class GooglePayDetailsPage extends StatefulWidget {
5+
const GooglePayDetailsPage({super.key});
6+
7+
@override
8+
_GooglePayDetailsPageState createState() => _GooglePayDetailsPageState();
9+
}
10+
11+
class _GooglePayDetailsPageState extends State<GooglePayDetailsPage> {
12+
final TextEditingController _upiController = TextEditingController();
13+
bool _isPayButtonEnabled = false;
14+
15+
@override
16+
void dispose() {
17+
_upiController.dispose();
18+
super.dispose();
19+
}
20+
21+
void _validateUPI() {
22+
setState(() {
23+
_isPayButtonEnabled = _upiController.text.isNotEmpty;
24+
});
25+
}
26+
27+
void _processPayment() {
28+
// Placeholder for payment processing logic
29+
ScaffoldMessenger.of(context).showSnackBar(
30+
SnackBar(
31+
content: Text('Payment initiated via UPI ID: ${_upiController.text}'),
32+
duration: const Duration(seconds: 2),
33+
),
34+
);
35+
36+
// Navigate back or to a success page
37+
Navigator.pop(context);
38+
}
39+
40+
@override
41+
Widget build(BuildContext context) {
42+
return Scaffold(
43+
appBar: AppBar(
44+
elevation: 0,
45+
backgroundColor: Colors.white,
46+
leading: IconButton(
47+
icon: const Icon(Icons.arrow_back, color: Colors.black),
48+
onPressed: () {
49+
Navigator.pop(context);
50+
},
51+
),
52+
title: const Text(
53+
'Google Pay UPI Details',
54+
style: TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
55+
),
56+
),
57+
body: Padding(
58+
padding: const EdgeInsets.all(16.0),
59+
child: Column(
60+
crossAxisAlignment: CrossAxisAlignment.start,
61+
children: [
62+
const Text(
63+
'Enter your UPI ID for Google Pay:',
64+
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w500),
65+
),
66+
const SizedBox(height: 20),
67+
TextField(
68+
controller: _upiController,
69+
decoration: const InputDecoration(
70+
labelText: 'UPI ID',
71+
border: OutlineInputBorder(),
72+
),
73+
onChanged: (value) => _validateUPI(),
74+
),
75+
const SizedBox(height: 40),
76+
Center(
77+
child: ElevatedButton(
78+
onPressed: _isPayButtonEnabled ? _processPayment : null,
79+
style: ElevatedButton.styleFrom(
80+
backgroundColor: Colors.green[700],
81+
padding:
82+
const EdgeInsets.symmetric(horizontal: 50, vertical: 15),
83+
shape: RoundedRectangleBorder(
84+
borderRadius: BorderRadius.circular(30),
85+
),
86+
),
87+
child: const Text('Pay'),
88+
),
89+
),
90+
],
91+
),
92+
),
93+
);
94+
}
95+
}

kisan/lib/pages/ProductDetailPage.dart

+76-16
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,72 @@
11
import 'package:flutter/material.dart';
2+
import 'cart_items.dart'; // Import the global cart list
23

3-
class ProductDetailPage extends StatelessWidget {
4+
class ProductDetailPage extends StatefulWidget {
45
final String productName;
56
final int productPrice;
67
final String productImagePath;
78
final String productDescription;
89

910
const ProductDetailPage({
10-
Key? key,
11+
super.key,
1112
required this.productName,
1213
required this.productPrice,
1314
required this.productImagePath,
1415
required this.productDescription,
15-
}) : super(key: key);
16+
});
17+
18+
@override
19+
_ProductDetailPageState createState() => _ProductDetailPageState();
20+
}
21+
22+
class _ProductDetailPageState extends State<ProductDetailPage> {
23+
int _quantity = 1;
24+
25+
void _incrementQuantity() {
26+
setState(() {
27+
_quantity++;
28+
});
29+
}
30+
31+
void _decrementQuantity() {
32+
if (_quantity > 1) {
33+
setState(() {
34+
_quantity--;
35+
});
36+
}
37+
}
38+
39+
// Function to calculate the total price for the selected product and quantity
40+
int _calculateTotalPrice() {
41+
return widget.productPrice * _quantity;
42+
}
1643

1744
@override
1845
Widget build(BuildContext context) {
1946
return Scaffold(
2047
appBar: AppBar(
21-
titleTextStyle: const TextStyle(
22-
color: Color(0xFF313423),
23-
fontFamily: 'Serif',
24-
fontSize: 25.0, // Increase the text size
25-
),
26-
title: Text(productName),
27-
backgroundColor: const Color(0xFF626F47),
48+
title: Text(widget.productName),
49+
backgroundColor: const Color(0xFF798645),
2850
),
2951
body: Padding(
3052
padding: const EdgeInsets.all(16.0),
3153
child: Column(
3254
crossAxisAlignment: CrossAxisAlignment.start,
3355
children: [
3456
Image.asset(
35-
productImagePath,
57+
widget.productImagePath,
3658
height: 250,
3759
width: double.infinity,
3860
fit: BoxFit.cover,
3961
),
4062
const SizedBox(height: 16),
4163
Text(
42-
productName,
64+
widget.productName,
4365
style: const TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
4466
),
4567
const SizedBox(height: 8),
4668
Text(
47-
'Rs. $productPrice/-',
69+
'Rs. ${widget.productPrice}/-',
4870
style: const TextStyle(fontSize: 20, color: Colors.red),
4971
),
5072
const SizedBox(height: 16),
@@ -54,18 +76,56 @@ class ProductDetailPage extends StatelessWidget {
5476
),
5577
const SizedBox(height: 4),
5678
Text(
57-
productDescription,
79+
widget.productDescription,
5880
style: const TextStyle(fontSize: 16),
5981
),
82+
const SizedBox(height: 16),
83+
Row(
84+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
85+
children: [
86+
const Text('Quantity', style: TextStyle(fontSize: 18)),
87+
Row(
88+
children: [
89+
IconButton(
90+
icon: const Icon(Icons.remove),
91+
onPressed: _decrementQuantity,
92+
),
93+
Text('$_quantity', style: const TextStyle(fontSize: 18)),
94+
IconButton(
95+
icon: const Icon(Icons.add),
96+
onPressed: _incrementQuantity,
97+
),
98+
],
99+
),
100+
],
101+
),
102+
const SizedBox(height: 16),
103+
Text(
104+
'Total Price: Rs. ${_calculateTotalPrice()}/-', // Display total price based on quantity
105+
style: const TextStyle(fontSize: 20, fontWeight: FontWeight.bold),
106+
),
60107
const Spacer(),
61108
Center(
62109
child: ElevatedButton(
63110
onPressed: () {
64-
// Add to cart logic
111+
// Add the product to the cart with quantity and total price
112+
cartItems.add({
113+
'name': widget.productName,
114+
'price': widget.productPrice,
115+
'image': widget.productImagePath,
116+
'quantity': _quantity, // Include the quantity
117+
'totalPrice': _calculateTotalPrice(), // Include the total price
118+
});
119+
120+
ScaffoldMessenger.of(context).showSnackBar(
121+
SnackBar(
122+
content: Text('${widget.productName} added to cart!'),
123+
duration: const Duration(seconds: 2),
124+
),
125+
);
65126
},
66127
style: ElevatedButton.styleFrom(
67128
backgroundColor: const Color(0xFF798645),
68-
textStyle: const TextStyle(color: Color(0xFFF2EED7)),
69129
),
70130
child: const Text('Add to Cart'),
71131
),

kisan/lib/pages/cart_items.dart

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
List<Map<String, dynamic>> cartItems = [];

0 commit comments

Comments
 (0)