'How to display certain category using WordPress api

I'm developing a mobile app using WordPress API and I'm trying to display only certain categories instead of all the categories.

Currently I'm doing it like this and it showing all the categories but just wondering how can I filter and only show category with ID 4 and 5?

//My API call
   void getCategories() async {
      try {
        var response = await Network().simpleGet("/categories?parent=0");

        var body = json.decode(response.body);
        if (response.statusCode == 200) {
          categories.state = body;
          var box = await Hive.openBox('appBox');
          box.put('categories', json.encode(body));
        } else {}
        loadingCategories.value = false;
      } catch (e) {
        print(e);
      }
    }


//This is how I'm displaying
Row(
                                        children: categories.state
                                            .map((category) => Container(
                                                  padding: EdgeInsets.symmetric(
                                                      vertical: 10),
                                                  margin: EdgeInsets.only(
                                                      right: 10),
                                                  child: InkWell(
                                                    onTap: () => Navigator.push(
                                                        context,
                                                        MaterialPageRoute(
                                                            builder: (context) =>
                                                                CategoryDetail(
                                                                    category:
                                                                        category))),
                                                    child: Text(
                                                      category['name'],
                                                      style: TextStyle(
                                                          color: color.state ==
                                                                  'dark'
                                                              ? Color(
                                                                  0xFFA19E9C)
                                                              : primaryText),
                                                    ),
                                                  ),
                                                ))
                                            .toList(),
                                      ),
```


Solution 1:[1]

I would suggest instead of

categories.state.map((category)

You do something like

categories.state.where((category) => category == xx).map((category)

Just add some filtering logic there ...

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andreas