@@ -9,64 +9,95 @@ import 'package:emart/services/firestore_service.dart';
9
9
import 'package:emart/views/category_screen_view/item_details.dart' ;
10
10
import 'package:get/get.dart' ;
11
11
12
- class CategoryDetails extends StatelessWidget {
12
+ class CategoryDetails extends StatefulWidget {
13
13
final String ? title;
14
14
const CategoryDetails ({
15
15
super .key,
16
16
required this .title,
17
17
});
18
18
19
19
@override
20
- Widget build ( BuildContext context) {
21
- var controller = Get . find < ProductController >();
20
+ State < CategoryDetails > createState () => _CategoryDetailsState ();
21
+ }
22
22
23
- return bgWidget (
24
- child: Scaffold (
25
- appBar: AppBar (title: title! .text.white.fontFamily (bold).make ()),
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
- );
23
+ class _CategoryDetailsState extends State <CategoryDetails > {
24
+ @override
25
+ void initState () {
26
+ super .initState ();
27
+ switchCategory (widget.title);
28
+ }
36
29
37
- var data = snapshot.data! .docs;
30
+ switchCategory (title) {
31
+ if (controller.subCat.contains (title))
32
+ productMethod = FirestoreService .getSubcategoryProducts (title);
33
+ else
34
+ productMethod = FirestoreService .getProducts (title);
35
+ }
38
36
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 ]}"
51
- .text
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 )
62
- .make (),
63
- ),
64
- ),
37
+ var controller = Get .find <ProductController >();
38
+
39
+ dynamic productMethod;
40
+
41
+ @override
42
+ Widget build (BuildContext context) {
43
+ return bgWidget (
44
+ child: Scaffold (
45
+ appBar: AppBar (title: widget.title! .text.white.fontFamily (bold).make ()),
46
+ body: Column (
47
+ crossAxisAlignment: CrossAxisAlignment .start,
48
+ children: [
49
+ SingleChildScrollView (
50
+ physics: const BouncingScrollPhysics (),
51
+ scrollDirection: Axis .horizontal,
52
+ child: Padding (
53
+ padding: const EdgeInsets .only (left: 12 ),
54
+ child: Row (
55
+ children: List .generate (
56
+ controller.subCat.length,
57
+ (index) => "${controller .subCat [index ]}"
58
+ .text
59
+ .color (darkFontGrey)
60
+ .size (12 )
61
+ .fontFamily (semibold)
62
+ .makeCentered ()
63
+ .box
64
+ .white
65
+ .padding (const EdgeInsets .symmetric (horizontal: 4 ))
66
+ .margin (const EdgeInsets .all (4 ))
67
+ .roundedSM
68
+ .size (120 , 60 )
69
+ .make ()
70
+ .onTap (() {
71
+ switchCategory ("${controller .subCat [index ]}" );
72
+ print (index);
73
+ setState (() {});
74
+ }),
65
75
),
76
+ ),
77
+ ),
78
+ ),
79
+ 20. heightBox,
80
+ StreamBuilder (
81
+ stream: productMethod,
82
+ builder: (BuildContext context,
83
+ AsyncSnapshot <QuerySnapshot > snapshot) {
84
+ if (! snapshot.hasData)
85
+ return Expanded (child: loadingIndicator ());
86
+ else if (snapshot.data! .docs.isEmpty)
87
+ return Expanded (
88
+ child: "No Products found"
89
+ .text
90
+ .color (darkFontGrey)
91
+ .makeCentered (),
92
+ );
93
+
94
+ var data = snapshot.data! .docs;
66
95
67
- // products
68
- 20. heightBox,
69
- Expanded (
96
+ return
97
+ // products
98
+ Expanded (
99
+ child: Padding (
100
+ padding: const EdgeInsets .all (12.0 ),
70
101
child: GridView .builder (
71
102
physics: const BouncingScrollPhysics (),
72
103
shrinkWrap: true ,
@@ -118,11 +149,11 @@ class CategoryDetails extends StatelessWidget {
118
149
});
119
150
},
120
151
),
121
- )
122
- ],
123
- ) ,
124
- );
125
- } ,
152
+ ),
153
+ );
154
+ } ,
155
+ ),
156
+ ] ,
126
157
),
127
158
),
128
159
);
0 commit comments