0

Here is my demo json response. Suppose I want to show All data from "CategoryList but I dont to show the list where "CategoryName": "NEW ARRIVALS", in my App.. How can I ignore specefic data from My Json response? Can I Filter it out by keyword New?

If New keyword arries in CategoryName in will ignore whole list

{
    "Status": 1,
    "Message": "",
    "CategoryList": [
          {
        "CategoryId": "2",
        "CategoryName": "Women",
        "CategoryImage": "https://ductImage/vkzvquiex2747i.jpg",
        "CategoryNote": "Satin Night Suits For Women",
        "SubCategoryList": [
            {
                "CategoryId": "2",
                "CategoryName": "Women",
                "SubCategoryId": "10",
                "SubCategoryName": "Satin & Lace",
                "SubCategoryImage": "https://oductImage/cxb1920565muxxb.jpg",
                "SubCategoryNote": "Ultra chic sophisticated & easy-breezy Collection"
            },               
           
            {
                "CategoryId": "2",
                "CategoryName": "Women",
                "SubCategoryId": "16",
                "SubCategoryName": "Bathrobe",
                "SubCategoryImage": "https://ProductImage/19eprae16hd3vqc.jpg",
                "SubCategoryNote": "Super-soft Bathrobe's for cosy moments at home."
            },
            {
                "CategoryId": "2",
                "CategoryName": "Women",
                "SubCategoryId": "39",
                "SubCategoryName": "Bedroom Slippers",
                "SubCategoryImage": "https:///ProductImage/bpq1tb8g2mawc18.jpg",
                "SubCategoryNote": "Leisure home room slippers."
            }
        ]
    },



        {
            "CategoryId": "12",//========Want to ignore where `CategoryId": "12`==========
            "CategoryName": "NEW ARRIVALS",
            "CategoryImage": "https://oductImage/wq35lbuzanbpzh.jpg",
            "CategoryNote": "Custom Designed & Exclusive Night Wears",
            "SubCategoryList": [
                {
                    "CategoryId": "12",
                    "CategoryName": "NEW ARRIVALS",
                    "SubCategoryId": "45",
                    "SubCategoryName": "New Arrivals For Women",
                    "SubCategoryImage": "https://n/ProductImage/llwyc6wiky73jts.jpg",
                    "SubCategoryNote": "My night My Style with Customized Women Night Suit"
                },
                {
                    "CategoryId": "12",
                    "CategoryName": "NEW ARRIVALS",
                    "SubCategoryId": "46",
                    "SubCategoryName": "New Arrivals For Men",
                    "SubCategoryImage": "https://in/ProductImage/1pj9oyq0zpgfu9c.jpg",
                    "SubCategoryNote": "Comfortable Customizable Men night Suites "
                },
                {
                    "CategoryId": "12",
                    "CategoryName": "NEW ARRIVALS",
                    "SubCategoryId": "47",
                    "SubCategoryName": "New Arrivals For Kids",
                    "SubCategoryImage": "https://.in/ProductImage/norg12vhysn5fbm.jpg",
                    "SubCategoryNote": "Be Fashionable, be divine, be yourself and Shine"
                }
            ]
        },
        {
            "CategoryId": "13",
            "CategoryName": "Bedsheet",
            "CategoryImage": "https://ductImage/r9eqe10ltoxqxo.jpg",
            "CategoryNote": "Cotton Rich Printed Bedsheets",
            "SubCategoryList": [
                {
                    "CategoryId": "13",
                    "CategoryName": "Bedsheet",
                    "SubCategoryId": "50",
                    "SubCategoryName": "Bedsheet",
                    "SubCategoryImage": "https://roductImage/e8wigvfgulr15j5.jpg",
                    "SubCategoryNote": "Ultrafine Cotton BedSheet "
                }
            ]
        },

  ]
}

My Ui part to show data in my App Screen.

   FutureBuilder(
                future: AllCategories_SubCat(),
                builder: (BuildContext context, AsyncSnapshot snapshot) {
                  if (snapshot.connectionState != ConnectionState.done) {
                    return Center(
                        child:
                            // Lottie.network(
                            //     'https://assets1.lottiefiles.com/packages/lf20_YMim6w.json'));
                            CupertinoActivityIndicator());
                  }
                  if (snapshot.hasError) {
                    return Text(
                        "Somthing went wrong. Please try after some time.");
                  }

                  if (snapshot.hasData) {
                    return ListView.builder(
                      scrollDirection: Axis.horizontal,
                      physics: BouncingScrollPhysics(),
                      shrinkWrap: true,
                      itemCount: snapshot.data.length,
                      itemBuilder: (BuildContext context, int index) =>
                          Padding(
                        padding:
                            EdgeInsets.only(left: blockSizeHorizontal * 5),
                        child: GestureDetector(
                          onTap: () {
                            Navigator.push(
                                context,
                                MaterialPageRoute(
                                    builder: (BuildContext context) =>
                                        Sub_categories_page(
                                            snapshot.data[index])));
                          },
                          child: SizedBox(
                            //width: blockSizeHorizontal * 68,
                            width: getProportionateScreenWidth(180),
                            height: blockSizeVertical * 15,..........
..........
.........
5
  • Your code isn't reproduceable should I show it you in a custom code? Commented Jan 12, 2022 at 13:30
  • yeah..No issue. I just need the logic Where I can ignore this CategoryId": "12" list...( I didn't post the whole class file code because its to lengthy.) Commented Jan 12, 2022 at 13:32
  • DO You need the actual Api?.. I can provide you shortly. Commented Jan 12, 2022 at 13:37
  • No. I'm just sharing a reference let me know if you didn't get that. But how do you define that which id you have to hide? Commented Jan 12, 2022 at 13:39
  • In my opinion, the transformation should be done before passing the list to the builder because a validation to not show category 12 would cause it to not be displayed visually but the space of the item would remain in the view, you can or do an order by putting that element first and start painting at pos 1 or remove that item from the list Commented Jan 12, 2022 at 15:16

1 Answer 1

1

you can apply this filter to the list before sending it to the builder

 categoryList.removeWhere((element) => element.CategoryId == '12');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.