logo

Crowdly

(Code Evaluation) Evaluate the correctness of the following code snippet. D...

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

(Code Evaluation)

Evaluate the correctness of the following code snippet. Does it display a CircularProgressIndicator while data is loading, and does it handle the snapshot.data null case correctly?

 

 

Future<String> fetchData() async {

  await Future.delayed(Duration(seconds: 2));

  return 'Data loaded';

}

 

FutureBuilder<String>(

  future: fetchData(),

  builder: (context, snapshot) {

    if (snapshot.connectionState == ConnectionState.waiting) {

      return CircularProgressIndicator();

    } else if (snapshot.hasData) {

      return Text(snapshot.data!);

    } else {

      return Text('Error loading data');

    }

  },

);

More questions like this

Want instant access to all verified answers on e-learning.msa.edu.eg?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!