Search Dart dynamic json collection in Flutter

I am familiar with Lynq operation in C# , which I think one of the flexible tools the language provide us. Dart and Flutter has same feature , may be all modern language have them.

I this example I will show you how dynamic or any collection can filtered in Dart. We have a Json extracted collection which is a Linked list, the collection is extracted in the following way. (so you can understand how I get those)

var test_data =
          await http.get('');
      var tdata = json.decode(test_data.body);

Filtering the List

The about code is a part of a Covid Dashboard Example , which is a Flutter native app project. The source can be found on my GitHub Repo, in case you need them.

The list includes dictionary key,value pair , so I can search for them using the where. To do this I first covert the data into a List.

 var t_data = tdata['states_tested_data'] as List;

Then we can use where to filter the list using keys and get the list. Remember in place filter didn’t change any thing as follows.

t_data.where((element) =>element['state'] == 'Kerala')

we can get another list from the above as follows which what exactly we needed.

var l = t_data.where((element) =>
                 element['state'] == 'Delhi').toList();

Explore other Dart article to learn more about Dart and Flutter

Published by


A developer,teacher and a blogger obsessed with Python,Dart and open source world from India

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.