Search code examples
httpdartgetflutter

How to add filter in http get flutter?


I really want know how to add filter having fields, where, limit, skip and so on using darts http package.

I already try using uri but ... it only accepts Map<String, String>. But my filter is more deep than that.

When using js it was fine ....but using in flutter is not working because of it's strongly typed property.


Solution

  • you can go deeply into Maps , maps can eccept more than one layer , lets say if your filter struct like this

    -color:
    --red ,
    -size:
    --small
    

    then you need to Map<String, String>

    lets go deeply into more complicated level

    -color:
    --backColor:
    ---red
    --fromColor:
    ---orange
    -size:
    --width:
    ---10CM
    --height:
    ---10CM
    

    then you should use a Map<String, Map<String, String>> this mean you can go deeper into your Map as you want also map can handle "dynamic" data type if you dont expect one kind of data type Map the "dynamic" key word can be another map or even a list of Maps !

    see this real dart example:

    Map<String, String> levelOne = {"key1" : "value1", "key2" : "value2"}
    
    Map<String, dynamic> levelTow = {"key1" : "value1", "key2" : levelOne}
    
    Map<String, dynamic> levelThree = {"key1" : "value1", "key2" : levelTow}