1
+ // ignore_for_file: curly_braces_in_flow_control_structures
2
+
3
+ import 'package:cloud_firestore/cloud_firestore.dart' ;
1
4
import 'package:emart/common_widgets/bg_widget.dart' ;
5
+ import 'package:emart/common_widgets/loading_indicator.dart' ;
2
6
import 'package:emart/consts/consts.dart' ;
3
7
import 'package:emart/controllers/product_controller.dart' ;
8
+ import 'package:emart/services/firestore_service.dart' ;
4
9
import 'package:emart/views/category_screen_view/item_details.dart' ;
5
10
import 'package:get/get.dart' ;
6
11
@@ -18,86 +23,105 @@ class CategoryDetails extends StatelessWidget {
18
23
return bgWidget (
19
24
child: Scaffold (
20
25
appBar: AppBar (title: title! .text.white.fontFamily (bold).make ()),
21
- body: Container (
22
- padding: const EdgeInsets .all (12 ),
23
- child: Column (
24
- crossAxisAlignment: CrossAxisAlignment .start,
25
- children: [
26
- SingleChildScrollView (
27
- physics: const BouncingScrollPhysics (),
28
- scrollDirection: Axis .horizontal,
29
- child: Row (
30
- children: List .generate (
31
- controller.subCat.length,
32
- (index) => "${controller .subCat [index ]}"
33
- .text
34
- .color (darkFontGrey)
35
- .size (12 )
36
- .fontFamily (semibold)
37
- .makeCentered ()
38
- .box
39
- .white
40
- .padding (const EdgeInsets .symmetric (horizontal: 4 ))
41
- .margin (const EdgeInsets .all (4 ))
42
- .roundedSM
43
- .size (120 , 60 )
44
- .make (),
45
- ),
46
- ),
47
- ),
26
+ body: StreamBuilder (
27
+ stream: FirestoreService .getProducts (title),
28
+ builder:
29
+ (BuildContext context, AsyncSnapshot <QuerySnapshot > snapshot) {
30
+ if (! snapshot.hasData)
31
+ return loadingIndicator ();
32
+ else if (snapshot.data! .docs.isEmpty)
33
+ return Center (
34
+ child: "No Products found" .text.color (darkFontGrey).make (),
35
+ );
48
36
49
- // products
50
- 20. heightBox,
51
- Expanded (
52
- child: GridView .builder (
53
- physics: const BouncingScrollPhysics (),
54
- shrinkWrap: true ,
55
- itemCount: 6 ,
56
- gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount (
57
- crossAxisCount: 2 ,
58
- mainAxisExtent: 250 ,
59
- mainAxisSpacing: 8 ,
60
- crossAxisSpacing: 8 ,
61
- ),
62
- itemBuilder: (context, index) {
63
- return Column (
64
- crossAxisAlignment: CrossAxisAlignment .start,
65
- children: [
66
- Image .asset (
67
- imgP5,
68
- width: 200 ,
69
- height: 150 ,
70
- fit: BoxFit .cover,
71
- ),
72
- "Laptop 8GB/64GB"
37
+ var data = snapshot.data! .docs;
38
+
39
+ return Container (
40
+ padding: const EdgeInsets .all (12 ),
41
+ child: Column (
42
+ crossAxisAlignment: CrossAxisAlignment .start,
43
+ children: [
44
+ SingleChildScrollView (
45
+ physics: const BouncingScrollPhysics (),
46
+ scrollDirection: Axis .horizontal,
47
+ child: Row (
48
+ children: List .generate (
49
+ controller.subCat.length,
50
+ (index) => "${controller .subCat [index ]}"
73
51
.text
74
- .fontFamily (semibold)
75
52
.color (darkFontGrey)
53
+ .size (12 )
54
+ .fontFamily (semibold)
55
+ .makeCentered ()
56
+ .box
57
+ .white
58
+ .padding (const EdgeInsets .symmetric (horizontal: 4 ))
59
+ .margin (const EdgeInsets .all (4 ))
60
+ .roundedSM
61
+ .size (120 , 60 )
76
62
.make (),
77
- 10. heightBox,
78
- "\$ 600"
79
- .text
80
- .color (redColor)
81
- .fontFamily (bold)
82
- .size (16 )
83
- .make (),
84
- ],
85
- )
86
- .box
87
- .white
88
- .roundedSM
89
- .outerShadowSm
90
- .margin (const EdgeInsets .all (4 ))
91
- .padding (const EdgeInsets .all (12 ))
92
- .make ()
93
- .onTap (() {
94
- Get .to (() => const ItemDetails (title: "Dumy Title" ));
95
- });
96
- },
97
- ),
98
- )
99
- ],
100
- ),
63
+ ),
64
+ ),
65
+ ),
66
+
67
+ // products
68
+ 20. heightBox,
69
+ Expanded (
70
+ child: GridView .builder (
71
+ physics: const BouncingScrollPhysics (),
72
+ shrinkWrap: true ,
73
+ itemCount: data.length,
74
+ gridDelegate:
75
+ const SliverGridDelegateWithFixedCrossAxisCount (
76
+ crossAxisCount: 2 ,
77
+ mainAxisExtent: 250 ,
78
+ mainAxisSpacing: 8 ,
79
+ crossAxisSpacing: 8 ,
80
+ ),
81
+ itemBuilder: (context, index) {
82
+ return Column (
83
+ crossAxisAlignment: CrossAxisAlignment .start,
84
+ children: [
85
+ Image .network (
86
+ data[index]['p_images' ][0 ],
87
+ width: 200 ,
88
+ height: 150 ,
89
+ fit: BoxFit .cover,
90
+ ),
91
+ "${data [index ]['p_name' ]}"
92
+ .text
93
+ .fontFamily (semibold)
94
+ .color (darkFontGrey)
95
+ .make (),
96
+ 10. heightBox,
97
+ "${data [index ]['p_price' ]}"
98
+ .numCurrency
99
+ .text
100
+ .color (redColor)
101
+ .fontFamily (bold)
102
+ .size (16 )
103
+ .make (),
104
+ ],
105
+ )
106
+ .box
107
+ .white
108
+ .roundedSM
109
+ .outerShadowSm
110
+ .margin (const EdgeInsets .all (4 ))
111
+ .padding (const EdgeInsets .all (12 ))
112
+ .make ()
113
+ .onTap (() {
114
+ Get .to (() => ItemDetails (
115
+ title: "${data [index ]['p_name' ]}" ,
116
+ data: data[index]));
117
+ });
118
+ },
119
+ ),
120
+ )
121
+ ],
122
+ ),
123
+ );
124
+ },
101
125
),
102
126
),
103
127
);
0 commit comments