Toujo
Toujo

Reputation: 345

How to ignore an arrayList item from json response in flutter?

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,..........
..........
.........

Upvotes: 0

Views: 217

Answers (1)

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

 categoryList.removeWhere((element) => element.CategoryId == '12');

Upvotes: 1

Related Questions