I am new to flutter and I am trying to learn the platform. So, here I am trying to display information from jsonplaceholder onto a alertdialog while is activated when a button is pressed in main.dart(I haven't included the code here). While the data loads I want to the alert dialog to appear and show a circularprogressindicator and after the data loads up the progress indicator is replaced by the 3 containers.
import 'dart:math';
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:http/http.dart' as http;
showAlertDialog(BuildContext context)async
{
Map res=await fetchData();
Color bc=(res["id"]%2==0)?(const Color.fromARGB(255, 44, 255, 2)):(const Color.fromARGB(255,255,0, 0));
AlertDialog alert=AlertDialog
(
title: const Text("TextFromNet"),
content:Column
(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children:
[
Container
(
//text from res and color bc
),
const SizedBox(height:15),
Container
(
//text from res and color bc
),
const SizedBox(height:15),
Container
(
//text from res and color bc
),
]
)
);
showDialog
(
context:context,
builder:(BuildContext context){return alert;},
);
return const CircularProgressIndicator();
}
fetchData()async
{
final response=await http.get(Uri.parse('https://jsonplaceholder.typicode.com/albums/${Random().nextInt(100)}'));
if(response.statusCode==200) {return json.decode(response.body);}
else {throw Exception('Failed to Fetch');}
}
Currently the alertdialog appears after about 1seconds of pressing the button, I want a circularprogressindicator to be shown in this time inside the alertdialog with th title of "TextFromInternet". I tried searching for some way but i couldn't figure out a clear path. I am guessing I have to do something realted to the state of the alertdialog but I am not sure. Please help. I have removed code from the containers to make the code shorter.