skip to Main Content

In flutter i have a simple ListView which that contains some data into that, for example you suppose i have 5 row in it,

now for each row in ListView i want to send request to the server to get response, you suppose again each row into this list is Instagram pages posts, and i want to get like count from server for each row in the list. or like with Telegram as you maybe know when we scroll posts, we can see posts seen.

could you help me how can i implementing this feature in Flutter? sending request from each row in the list

enter image description here

2

Answers


  1. If you would have more than a fixed number of 5 rows, the ListView.builder constructor is what you want:

    ListView.builder(
      itemCount: items.length,
      itemBuilder: (context, index) async {
        final response = await http.get('https://anyurl/getData/contentId/${index}');
    
        final parsedResponse = parseResponse(response);
    
        return ListTile(
          title: Text('${parsedResponse.title}'),
        );
      },
    );
    

    The ListView builder gives you the index of the list item currently being built and lets you create any widgets that are displayed as elements.

    parseResponse is a dummy function, which of course does not exist, because it has to be implemented by yourself.

    Login or Signup to reply.
  2. ListView.builder(
      itemCount: items.length,
      itemBuilder: (context, index) async {
        var itemPosition = index+1;
        final response = await http.get('https://anyurl/getData/contentId/$itemPosition');
        final item = parseResponse(response);
        return ListTile(
          title: Text('${item.name'), \name is your fetched JSON
        );
      },
    );
    

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search