Best ways to use an Action Block Loop without using an App State variable as your loop index?

Best Practices

When defining a loop within an Action Block, I either wish to run a specific number of time or as a traditional ForEach for all the elements in a list. Now if this list is an App State var itself that I wish to keep updated, using an index that is a Page or Component State var does not seem to generally work. I have resorted to using an App State var as my loop index.

The problem with using an App State var is that I can only run one instance of the Action Block at a time. So I cannot run it in a non-blocking way, or in parallel. And if I do accidentally run multiple instances simultaneously, then there is the danger of munging data for multiple list items.

One example of this (my current need) is reading in Google Places using their api. Each place can have multiple photos. You must run a separate api call to get the url for each photo. Ideally I should be able to create an action block that loops through each photo to get its url. Hence my need and problem described above. I have run into this loop need constantly.

Is there a more appropriate way to do this within FlutterFlow? Or a clever workaround that can be suggested? Thanks-a-bunch!

2 replies