title: FutureBuilder snapshot.data getting set to null before the http call
body: <p>I am trying to modify the List fetched during the future call and not call the future function again, so assigned a variable to <code>future</code> option of <code>FutureBuilder</code> and called the actual function in the <code>initState()</code>, but now the build function is rendering straight the <code>snapshot.error</code> condition and the build is not even going in the <code>ConnectionState.loading</code> state. Below is the relevant code snippet:</p>
  <pre><code>class _BusinessDetailScreenState extends State&lt;BusinessDetailScreen&gt; {
    late List&lt;ProductCategory&gt; _uniqueProductCategoryList;
    late Future&lt;List&lt;BusinessProduct&gt;&gt; _productsFetch;
  
    @override
    void initState() {
      super.initState();
      _productsFetch = _fetchDetails();
    }
  
    List&lt;ProductCategory&gt; fetchUniqueCategory (productList) {
      // function body
      return List&lt;ProductCategory&gt;.generate(result.length, (index) {
          return ProductCategory(
            categoryName: result[index][&quot;productCategoryName&quot;],alternateName: result[index][&quot;productCategoryAlternateName&quot;]??= &quot;&quot;, id:result[index][&quot;id&quot;]
          );
      });
    }
  
    Future&lt;List&lt;BusinessProduct&gt;&gt; _fetchDetails() async {
      var queryParams = {
       //params
      };
      var response = await http.get(Uri.https(Provider.of(context)!.baseUrl,'endpoint',queryParams));
      if (response.statusCode == 200) {
        List jsonResponse = json.decode(response.body);
        List&lt;BusinessProduct&gt; products = jsonResponse.map((e) =&gt; BusinessProduct.fromJson(e)).toList();
        _uniqueProductCategoryList = fetchUniqueCategory(products);
        return products;
      }else {
        throw Exception('Failed to load Details');
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return FutureBuilder&lt;List&lt;dynamic&gt;&gt;(
        future: _productsFetch,
        builder: (context,snapshot){
        print(snapshot); //AsyncSnapshot&lt;List&lt;dynamic&gt;&gt;(ConnectionState.done, null, dependOnInheritedWidgetOfExactType&lt;Provider&gt;() or dependOnInheritedElement() was called before _BusinessDetailScreenState.initState() completed.
          if(snapshot.hasData){
            return Scaffold(//for data)
          } else if(snapshot.hasError){
              print(snapshot.error);
              // I/flutter ( 4211): dependOnInheritedWidgetOfExactType&lt;Provider&gt;() or dependOnInheritedElement() was called before _BusinessDetailScreenState.initState() completed.
  
              return Scaffold( // for error)
          } return Scaffold(
              backgroundColor: palletWhite,            
              body: Center(
                child: LoadingComponent(loadingText: 'Fetching data, Please wait',)
              )
          );
        },
      );
    )
  </code></pre>
  <p>Been stuck on this for a while now, is there anything I'm doing wrong or is there some different approach to this that I should try, please let me know</p>