Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

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) { });
 
PREVIOUS NEXT
Tagged: #iterate #object #dart
ADD COMMENT
Topic
Name
6+4 =