Skip to content

Using a for loop variable inside a callback leads to a wrong loop state #269

@Zverik

Description

@Zverik

In a code like this:

return ListView(
  children: [
    for (final String line in lines)
      ListTile(
        title: Text(line),
        onTap: () {
          print(line);
        },
      ),
  ],
);

It would create list tiles with different titles, but when tapping on those, the printed line will be the same.

This can be circumvented by extracting the ListTile() call into a method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions