Answers for "how to iterate object in dart"

0

how to iterate object in dart

// You have several options, the simple way for me is 
  // create method "toJson" inside of the class,
  // and then iterate over the return of method "toJson". 
  
example :

class MyModel() {
  int value1;
  String value2;
  bool value3;
  
  MyModel({
    this.key1,
    this.key2,
    this.key3});
  
  Map<String, dynamic>  toJson() {
    return {"key1": value1, 
        "key2":value2,
        "key3":value3 };}
  }

  MyModel.toJson().forEach((key, value) { });
Posted by: Guest on September-09-2021
0

dart loop through object

var usrMap = {"name": "Tom", 'Email': '[email protected]'}; 
   usrMap.forEach((k,v) => print('${k}: ${v}'));
Posted by: Guest on April-28-2020

Code answers related to "Dart"

Browse Popular Code Answers by Language