Home > Blockchain >  Flutter loop through object (Basics)
Flutter loop through object (Basics)

Time:10-26

Would like to loop through a multidimensional object but appear to be missing something.

String label, action;
    var symbol;
    Object toggles = [
      {
        label = 'Reckless',
      },
      {
        label = 'Feckless',
      },
      {
        label = 'Legless',
      },
    ];

I attempted to use this in a Row:

   Row(
       children: for (var toggle in toggles) {
Text('label ${toggle.label}')
                  },
                );

Error message concerns for stating that it expected an identified. Clearly I'm not fully understanding how to do this.

CodePudding user response:

I tried to run your code. The error :

Error: The type 'Object' used in the 'for' loop must implement 'Iterable<dynamic>'.

You cannot iterate on an Object.

If you change Object toggles = to List toggles = for example (which is iteratable), then, it is working.

  • Related