title: Show different widget if API fails to fetch files
body: <p>I'm working on an app where I need to show a button if API fails to fetch data and show a ListView.builder() is API fetches data.</p>
  <p>The progress so far is, if the API fetches data, ListView.builder() is displayed but if it fails to fetch the data, Button is not shown and the progress indicator keeps running.</p>
  <p>Here's my code..</p>
  <pre><code>import 'package:flutter/material.dart';
  
  import '../Services/fetch_nifty_data.dart';
  
  class NiftyScreen extends StatefulWidget {
    @override
    _NiftyScreenState createState() =&gt; _NiftyScreenState();
  }
  
  class _NiftyScreenState extends State&lt;NiftyScreen&gt; {
    Map&lt;String, dynamic&gt;? niftyDetails = {};
    late bool? isLoading;
  
    @override
    void initState() {
      super.initState();
      getNiftyData();
    }
  
    getNiftyData() async {
      setState(() {
        isLoading = true;
      });
      this.niftyDetails = await fetchNiftyData();
      setState(() {
        isLoading = false;
      });
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: isLoading!
            ? LinearProgressIndicator()
            : niftyDetails!.isNotEmpty
                ? ListView.builder(
                    itemCount: niftyDetails![&quot;filtered&quot;][&quot;data&quot;].length,
                    itemBuilder: (_, index) {
                      return ListTile(
                        title: Text(
                            '${niftyDetails![&quot;filtered&quot;][&quot;data&quot;][index][&quot;strikePrice&quot;]}'),
                      );
                    },
                  )
                : Center(
                    child: MaterialButton(
                      onPressed: getNiftyData,
                      child: Text(
                        'Nothing to show. Refetch?',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      color: Colors.red[900],
                      textColor: Colors.white,
                    ),
                  ),
      );
    }
  }
  
  </code></pre>
  <p>Can anybody help me with this?</p>