|
| 1 | +import 'package:cloud_firestore/cloud_firestore.dart'; |
1 | 2 | import 'package:emart/common_widgets/home_buttons.dart';
|
| 3 | +import 'package:emart/common_widgets/loading_indicator.dart'; |
2 | 4 | import 'package:emart/consts/consts.dart';
|
3 | 5 | import 'package:emart/consts/list.dart';
|
| 6 | +import 'package:emart/services/firestore_service.dart'; |
| 7 | +import 'package:emart/views/category_screen_view/item_details.dart'; |
4 | 8 | import 'package:emart/views/home_screen_view/components/featured_button.dart';
|
| 9 | +import 'package:get/get.dart'; |
5 | 10 |
|
6 | 11 | class HomeScreen extends StatelessWidget {
|
7 | 12 | const HomeScreen({super.key});
|
@@ -190,7 +195,8 @@ class HomeScreen extends StatelessWidget {
|
190 | 195 | .box
|
191 | 196 | .white
|
192 | 197 | .roundedSM
|
193 |
| - .margin(const EdgeInsets.symmetric(horizontal: 4)) |
| 198 | + .margin(const EdgeInsets.symmetric( |
| 199 | + horizontal: 4)) |
194 | 200 | .padding(const EdgeInsets.all(8))
|
195 | 201 | .make(),
|
196 | 202 | ),
|
@@ -221,45 +227,77 @@ class HomeScreen extends StatelessWidget {
|
221 | 227 |
|
222 | 228 | // All product section
|
223 | 229 | 20.heightBox,
|
224 |
| - GridView.builder( |
225 |
| - shrinkWrap: true, |
226 |
| - physics: const NeverScrollableScrollPhysics(), |
227 |
| - itemCount: 6, |
228 |
| - gridDelegate: |
229 |
| - const SliverGridDelegateWithFixedCrossAxisCount( |
230 |
| - crossAxisCount: 2, |
231 |
| - mainAxisSpacing: 8, |
232 |
| - crossAxisSpacing: 8, |
233 |
| - mainAxisExtent: 300, |
234 |
| - ), |
235 |
| - itemBuilder: (context, index) { |
236 |
| - return Column( |
237 |
| - crossAxisAlignment: CrossAxisAlignment.start, |
238 |
| - children: [ |
239 |
| - Image.asset(imgP5, |
240 |
| - width: 200, height: 200, fit: BoxFit.cover), |
241 |
| - const Spacer(), |
242 |
| - "Laptop 8GB/64GB" |
243 |
| - .text |
244 |
| - .fontFamily(semibold) |
245 |
| - .color(darkFontGrey) |
246 |
| - .make(), |
247 |
| - 10.heightBox, |
248 |
| - "\$600" |
249 |
| - .text |
250 |
| - .color(redColor) |
251 |
| - .fontFamily(bold) |
252 |
| - .size(16) |
253 |
| - .make(), |
254 |
| - ], |
255 |
| - ) |
256 |
| - .box |
257 |
| - .white |
258 |
| - .roundedSM |
259 |
| - .margin(const EdgeInsets.all(4)) |
260 |
| - .padding(const EdgeInsets.all(12)) |
261 |
| - .make(); |
262 |
| - }) |
| 230 | + Align( |
| 231 | + alignment: Alignment.centerLeft, |
| 232 | + child: allProducts.text |
| 233 | + .fontFamily(bold) |
| 234 | + .color(darkFontGrey) |
| 235 | + .size(18) |
| 236 | + .make(), |
| 237 | + ), |
| 238 | + 20.heightBox, |
| 239 | + StreamBuilder( |
| 240 | + stream: FirestoreService.getAllProducts(), |
| 241 | + builder: (BuildContext context, |
| 242 | + AsyncSnapshot<QuerySnapshot> snapshot) { |
| 243 | + if (!snapshot.hasData) return loadingIndicator(); |
| 244 | + var allProductData = snapshot.data!.docs; |
| 245 | + return GridView.builder( |
| 246 | + shrinkWrap: true, |
| 247 | + physics: const NeverScrollableScrollPhysics(), |
| 248 | + itemCount: allProductData.length, |
| 249 | + gridDelegate: |
| 250 | + const SliverGridDelegateWithFixedCrossAxisCount( |
| 251 | + crossAxisCount: 2, |
| 252 | + mainAxisSpacing: 8, |
| 253 | + crossAxisSpacing: 8, |
| 254 | + mainAxisExtent: 300, |
| 255 | + ), |
| 256 | + itemBuilder: (context, index) { |
| 257 | + return Column( |
| 258 | + crossAxisAlignment: CrossAxisAlignment.start, |
| 259 | + children: [ |
| 260 | + Image.network( |
| 261 | + allProductData[index]['p_images'][0], |
| 262 | + width: 200, |
| 263 | + height: 200, |
| 264 | + fit: BoxFit.cover, |
| 265 | + ), |
| 266 | + const Spacer(), |
| 267 | + "${allProductData[index]['p_name']}" |
| 268 | + .text |
| 269 | + .fontFamily(semibold) |
| 270 | + .color(darkFontGrey) |
| 271 | + .make(), |
| 272 | + 10.heightBox, |
| 273 | + "${allProductData[index]['p_price']}" |
| 274 | + .numCurrency |
| 275 | + .text |
| 276 | + .color(redColor) |
| 277 | + .fontFamily(bold) |
| 278 | + .size(16) |
| 279 | + .make(), |
| 280 | + ], |
| 281 | + ) |
| 282 | + .box |
| 283 | + .white |
| 284 | + .roundedSM |
| 285 | + .margin(const EdgeInsets.all(4)) |
| 286 | + .padding(const EdgeInsets.all(12)) |
| 287 | + .make() |
| 288 | + .onTap( |
| 289 | + () { |
| 290 | + Get.to( |
| 291 | + () => ItemDetails( |
| 292 | + title: allProductData[index]['p_name'], |
| 293 | + data: allProductData[index]), |
| 294 | + ); |
| 295 | + }, |
| 296 | + ); |
| 297 | + }, |
| 298 | + ); |
| 299 | + }, |
| 300 | + ), |
263 | 301 | ],
|
264 | 302 | ),
|
265 | 303 | ),
|
|
0 commit comments