Skip to content

Commit 967b3d3

Browse files
committed
2 parents 0fddc9d + 6b06058 commit 967b3d3

2 files changed

Lines changed: 457 additions & 2 deletions

File tree

Lines changed: 284 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
import 'package:farmerapp/pages/subpages/articles.dart';
2+
import 'package:farmerapp/pages/subpages/marketplace/buypage.dart';
3+
import 'package:flutter/cupertino.dart';
14
import 'package:flutter/material.dart';
5+
import 'package:flutter/widgets.dart';
6+
import 'package:get/get.dart';
27

38
class MarketplacePage extends StatefulWidget {
49
const MarketplacePage({super.key});
@@ -8,10 +13,287 @@ class MarketplacePage extends StatefulWidget {
813
}
914

1015
class _MarketplacePageState extends State<MarketplacePage> {
16+
int currentPage = 0;
17+
18+
List<ArticleItem> listTiles = [
19+
ArticleItem(
20+
"https://images.pexels.com/photos/2647053/pexels-photo-2647053.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
21+
"Cow Fodder",
22+
"High quality Cow Fodder imported from abroad sold by Raju from XYZ place.",
23+
"Raju",
24+
"\u20B9 200",
25+
),
26+
ArticleItem(
27+
"https://images.pexels.com/photos/2647053/pexels-photo-2647053.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
28+
"Haybale",
29+
"High quality Haybale imported from abroad sold by Ramesh from XYZ place.",
30+
"Ramesh",
31+
"\u20B9 200",
32+
),
33+
ArticleItem(
34+
"https://images.pexels.com/photos/2647053/pexels-photo-2647053.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
35+
"Buffalo Fodder",
36+
"High quality Buffalo Fodder imported from abroad sold by Shankar from XYZ place.",
37+
"Shankar",
38+
"\u20B9 200 ",
39+
),
40+
ArticleItem(
41+
"https://images.pexels.com/photos/2647053/pexels-photo-2647053.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
42+
"Equipment",
43+
"High quality Cow and Buffalo Equipment imported from abroad sold by Govind from XYZ place.",
44+
"Govind",
45+
"\u20B9 200 ",
46+
),
47+
ArticleItem(
48+
"https://images.pexels.com/photos/2647053/pexels-photo-2647053.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500",
49+
"Bells",
50+
"High quality Bells imported from abroad sold by Rammu from XYZ place.",
51+
"Rammu",
52+
"\u20B9 200 ",
53+
),
54+
];
55+
56+
TextEditingController productNameController = TextEditingController();
57+
TextEditingController productDescriptionController = TextEditingController();
58+
TextEditingController sellingPriceController = TextEditingController();
59+
60+
@override
61+
void initState() {
62+
super.initState();
63+
productNameController.text = "milk";
64+
}
65+
66+
@override
67+
void dispose() {
68+
productNameController.dispose();
69+
productDescriptionController.dispose();
70+
sellingPriceController.dispose();
71+
super.dispose();
72+
}
73+
1174
@override
1275
Widget build(BuildContext context) {
13-
return const Center(
14-
child: Text('Tasks'),
76+
return Column(
77+
children: [
78+
ButtonBar(
79+
alignment: MainAxisAlignment.spaceAround,
80+
children: [
81+
ElevatedButton(
82+
onPressed: () {
83+
setState(() {
84+
currentPage = 0;
85+
});
86+
},
87+
style: ButtonStyle(
88+
// backgroundColor: MaterialStateProperty.all(Colors.green),
89+
minimumSize:
90+
MaterialStateProperty.all(Size(context.width * 0.4, 50)),
91+
),
92+
child: const Text('Buy'),
93+
),
94+
ElevatedButton(
95+
onPressed: () {
96+
setState(() {
97+
currentPage = 1;
98+
});
99+
},
100+
style: ButtonStyle(
101+
// backgroundColor: MaterialStateProperty.all(Colors.green),
102+
minimumSize:
103+
MaterialStateProperty.all(Size(context.width * 0.4, 50)),
104+
),
105+
child: const Text('Sell'),
106+
),
107+
],
108+
),
109+
Expanded(
110+
// height: 200,
111+
child: currentPage == 0 ? drawBuyPage() : drawSellPage(),
112+
),
113+
],
114+
);
115+
}
116+
117+
Widget drawBuyPage() {
118+
return Padding(
119+
padding: const EdgeInsets.only(left: 10.0, right: 10.0),
120+
child: Container(
121+
child: ListView.builder(
122+
itemCount: listTiles.length,
123+
itemBuilder: (context, index) {
124+
// return listWidget(listTiles[index]);
125+
return InkWell(
126+
onTap: () {
127+
Navigator.push(
128+
context,
129+
MaterialPageRoute(
130+
builder: (context) => BuyPage(
131+
article: listTiles[index],
132+
tag: 'shop-$index',
133+
)));
134+
},
135+
child: listWidget(listTiles[index], index),
136+
);
137+
},
138+
),
139+
),
140+
);
141+
}
142+
143+
Widget drawSellPage() {
144+
return SingleChildScrollView(
145+
child: Padding(
146+
padding: EdgeInsets.only(left: 20, right: 20, top: 10),
147+
child: Column(
148+
children: [
149+
const Text(
150+
"Sell Page",
151+
style: TextStyle(fontSize: 20),
152+
),
153+
DropdownButtonFormField<String>(
154+
value: productNameController.text,
155+
onChanged: (value) {
156+
setState(() {
157+
productNameController.text = value!;
158+
});
159+
},
160+
decoration: const InputDecoration(
161+
labelText: "Product Name",
162+
),
163+
items: [
164+
DropdownMenuItem(
165+
value: "milk",
166+
child: Text("Milk"),
167+
),
168+
DropdownMenuItem(
169+
value: "curd",
170+
child: Text("Curd"),
171+
),
172+
DropdownMenuItem(
173+
value: "paneer",
174+
child: Text("Paneer"),
175+
),
176+
DropdownMenuItem(
177+
value: "butter",
178+
child: Text("Butter"),
179+
),
180+
DropdownMenuItem(
181+
value: "ghee",
182+
child: Text("Ghee"),
183+
),
184+
],
185+
),
186+
TextFormField(
187+
controller: productDescriptionController,
188+
decoration: const InputDecoration(
189+
labelText: "Product Description",
190+
),
191+
),
192+
TextFormField(
193+
controller: sellingPriceController,
194+
keyboardType: TextInputType.number,
195+
decoration: const InputDecoration(
196+
prefixIcon: Icon(Icons.currency_rupee),
197+
labelText: "Desired Selling Price",
198+
),
199+
),
200+
SizedBox(
201+
height: 20,
202+
),
203+
ElevatedButton(
204+
onPressed: () {
205+
print('''{
206+
item_name: "${productNameController.text}",
207+
item_desc: "${productDescriptionController.text}",
208+
item_price: ${sellingPriceController.text},
209+
}''');
210+
productNameController.clear();
211+
productDescriptionController.clear();
212+
sellingPriceController.clear();
213+
},
214+
child: Text("Sell"),
215+
),
216+
],
217+
),
218+
),
219+
);
220+
}
221+
222+
Widget listWidget(ArticleItem item, int index) {
223+
return Hero(
224+
tag: 'shop-$index',
225+
child: Card(
226+
semanticContainer: false,
227+
elevation: 2.0,
228+
margin: EdgeInsets.only(bottom: 20.0),
229+
child: Padding(
230+
padding: EdgeInsets.all(8.0),
231+
child: Row(
232+
crossAxisAlignment: CrossAxisAlignment.start,
233+
children: [
234+
Container(
235+
height: 100,
236+
width: 100,
237+
decoration: BoxDecoration(
238+
image: DecorationImage(
239+
image: NetworkImage(item.imgUrl),
240+
fit: BoxFit.cover,
241+
),
242+
borderRadius: BorderRadius.circular(8),
243+
),
244+
),
245+
const SizedBox(
246+
width: 10,
247+
),
248+
Expanded(
249+
child: Column(
250+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
251+
crossAxisAlignment: CrossAxisAlignment.start,
252+
children: [
253+
Text(
254+
item.articleTitle,
255+
style: const TextStyle(
256+
fontSize: 16,
257+
fontWeight: FontWeight.bold,
258+
),
259+
),
260+
const SizedBox(height: 5),
261+
Text(
262+
item.articleDescription,
263+
maxLines: 2,
264+
overflow: TextOverflow.ellipsis,
265+
style: const TextStyle(
266+
fontSize: 14,
267+
color: Colors.grey,
268+
),
269+
),
270+
const SizedBox(height: 10),
271+
Row(
272+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
273+
children: [
274+
Text(
275+
item.date,
276+
style: const TextStyle(
277+
fontSize: 14,
278+
color: Colors.black,
279+
),
280+
),
281+
Text(
282+
"~${item.author}",
283+
style: const TextStyle(
284+
fontSize: 14,
285+
color: Colors.black,
286+
),
287+
),
288+
],
289+
),
290+
],
291+
),
292+
),
293+
],
294+
),
295+
),
296+
),
15297
);
16298
}
17299
}

0 commit comments

Comments
 (0)