flutter

How to show multiple alert dialog one by one?


I want to display alert dialog as per my rest API gives the data array.

I mean for example my rest API gives me data like :

"data": [
        {
            "id": "6",
            "user_id": "315",
            "message": "http://www.google.com",
            "status": "active",
            "date": "2020-04-09 17:18:00",
            "created": "2020-04-06 04:48:08"
        },
        {
            "id": "7",
            "user_id": "315",
            "message": "http://www.google.com",
            "status": "active",
            "date": "2020-04-09 17:18:00",
            "created": "2020-04-06 04:49:46"
        },
]

i want to display alert dialog as per my data length in flutter.


Solution

  • You can chain the dialogs with a recursive function.

    void recursiveShowDialog(List arr, int index) async {
        if (index >= arr.length) {
            return;
        }
        await showDialog( *dialog code here with arr[index]*);
        recursiveShowDialog(arr, index + 1);
    }
    

    Then you can call this function where you want the dialogs to start

    recursiveShowDialog(data, 0);
    

    Where data is the list of items to be used in the dialog.