|
9 | 9 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
10 | 10 |
|
11 | 11 | import 'package:auto_size_text/auto_size_text.dart'; |
| 12 | +import 'package:collection/collection.dart'; |
12 | 13 | import 'package:flutter/material.dart'; |
| 14 | +import 'package:woosignal/models/response/product_category_collection.dart'; |
13 | 15 | import '/bootstrap/helpers.dart'; |
14 | 16 | import '/resources/widgets/app_loader_widget.dart'; |
15 | 17 | import '/resources/widgets/buttons.dart'; |
@@ -39,10 +41,28 @@ class _CompoHomeWidgetState extends State<CompoHomeWidget> { |
39 | 41 | } |
40 | 42 |
|
41 | 43 | _loadHome() async { |
42 | | - categories = await (appWooSignal((api) => |
43 | | - api.getProductCategories(parent: 0, perPage: 50, hideEmpty: true))); |
44 | | - categories.sort((category1, category2) => |
45 | | - category1.menuOrder!.compareTo(category2.menuOrder!)); |
| 44 | + if ((widget.wooSignalApp?.productCategoryCollections ?? []).isNotEmpty) { |
| 45 | + List<int> productCategoryId = widget.wooSignalApp?.productCategoryCollections.map((e) => int.parse(e.collectionId!)).toList() ?? []; |
| 46 | + categories = await (appWooSignal((api) => |
| 47 | + api.getProductCategories(parent: 0, perPage: 50, hideEmpty: true, include: productCategoryId))); |
| 48 | + categories.sort((category1, category2) { |
| 49 | + ProductCategoryCollection? productCategoryCollection1 = widget.wooSignalApp?.productCategoryCollections.firstWhereOrNull((element) => element.collectionId == category1.id.toString()); |
| 50 | + ProductCategoryCollection? productCategoryCollection2 = widget.wooSignalApp?.productCategoryCollections.firstWhereOrNull((element) => element.collectionId == category2.id.toString()); |
| 51 | + |
| 52 | + if (productCategoryCollection1 == null) return 0; |
| 53 | + if (productCategoryCollection2 == null) return 0; |
| 54 | + |
| 55 | + if (productCategoryCollection1.position == null) return 0; |
| 56 | + if (productCategoryCollection2.position == null) return 0; |
| 57 | + |
| 58 | + return productCategoryCollection1.position!.compareTo(productCategoryCollection2.position!); |
| 59 | + }); |
| 60 | + } else { |
| 61 | + categories = await (appWooSignal((api) => |
| 62 | + api.getProductCategories(parent: 0, perPage: 50, hideEmpty: true))); |
| 63 | + categories.sort((category1, category2) => |
| 64 | + category1.menuOrder!.compareTo(category2.menuOrder!)); |
| 65 | + } |
46 | 66 |
|
47 | 67 | for (var category in categories) { |
48 | 68 | List<Product> products = await (appWooSignal( |
@@ -73,7 +93,7 @@ class _CompoHomeWidgetState extends State<CompoHomeWidget> { |
73 | 93 | Size size = MediaQuery.of(context).size; |
74 | 94 | List<String>? bannerImages = widget.wooSignalApp!.bannerImages; |
75 | 95 | return Scaffold( |
76 | | - drawer: HomeDrawerWidget(wooSignalApp: widget.wooSignalApp), |
| 96 | + drawer: HomeDrawerWidget(wooSignalApp: widget.wooSignalApp, productCategories: categories), |
77 | 97 | appBar: AppBar( |
78 | 98 | centerTitle: true, |
79 | 99 | title: StoreLogo(), |
|
0 commit comments