title: How to initialise Firestore query in initState in flutter
body: <p>I am trying to load the data from Firestore, with the help of streambuilder i am getting the respective data and displaying it to the user.</p>
  <p>I am passing the value to a variable called 'total' and this total is inialised with 0 and when i try to show this total value it first should the default(0) value and the it takes the value from Firestore.</p>
  <p>Below you can see the code</p>
  <pre><code>            StreamBuilder&lt;DocumentSnapshot&gt;(
                  stream: FirebaseFirestore.instance.collection('UserData').doc(getUid()).snapshots(),
                  builder: (context, AsyncSnapshot&lt;DocumentSnapshot&gt; snapshot) {
                    if (!snapshot.hasData) return const Text(&quot;Loading...&quot;);
                    final DocumentSnapshot? document = snapshot.data;
                    final Map&lt;String, dynamic&gt; documentData = document?.data() as Map&lt;String, dynamic&gt;;
  
                    accountList = (documentData['accounts'] as List).map((accountList) =&gt; accountList as Map&lt;String, dynamic&gt;).toList();
                    // getTotalFund(accountList);
                    List amountData=[];
                    double convertAmount;
  
                    for(int i=0; i&lt;accountList.length;i++){
                      if(accountList[i]['accountType'] == 'Savings' || accountList[i]['accountType'] == 'Cash' ){
                        amountData.add(double.parse(accountList[i]['amountBalance'].replaceAll(',','')));
                      }
                    }
                    convertAmount = amountData.reduce((value, element) =&gt; value + element);
                    totalFund = amountFormat.format(convertAmount);
  
                    return Text(
                      documentData['name'],
                      style: const TextStyle(
                        fontSize: 16,
                        fontFamily: &quot;Gilroy SemiBold&quot;,
                      ),
                    );
                  }),
  </code></pre>
  <p>the value total amount i am getting in the Text widget.</p>
  <pre><code>Text('\u{20B9} ', style: TextStyle(color: Color(0xff9c9c9c), fontFamily: &quot;Gilroy Medium&quot;, fontSize: 23)),
  Text(totalFund.toString(),style: const TextStyle(color: Colors.black, fontFamily: &quot;Gilroy Bold&quot;, fontSize: 35)),
  </code></pre>
  <p>how to load the totalFund in initState so it will not show the null value.</p>
  <p><a href="https://i.stack.imgur.com/xnhbD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xnhbD.png" alt="screenshot" /></a></p>