How to Call Dynamic Variable on Flutter

Viewed 149

I have the following code

List toCheck = ['province','regency','district','village'];
  List data = [];
  toCheck.forEach((value) {
    //sample data would looke like (object.province)
    if(object.value!=null){ => need to call with object.value
      data.add(value);
    }
  });

If it is in php, that would be look like ${$value}

1 Answers

Try this:

   ElevatedButton(onPressed: (){
                    List toCheck = ['province','regency','district','village'];
                    List data = [];
                    toCheck.forEach((value) {
                      //sample data would looke like (object.province)
                      if(value!=null){ 
                      data.add(value);
                      }
                    });

If I understand what you want correctly, this should check if the values of your list are not null, and if so, it will add each value to the data list.

Related