title: How to calculate average and create a new list out of a existing list in flutter
body: <p>I have a future which returns a list of 4 items;</p>
  <ol>
  <li>Name</li>
  <li>Type</li>
  <li>Ratings</li>
  <li>number of ratings</li>
  </ol>
  <p>i want to create a new list out of this list with only
  Average Ratings and
  number of ratings.</p>
  <p>I want to add them in a new firestore collection.</p>
  <p>Please note i want to calculate average for the result of each call so i am avoiding a cloud function because that will calculate average of all the values in existing collection. So flow is, app calls a cloud function, get values and then it calculate average of all the ratings in that call's result.</p>
  <p>My future is;</p>
  <pre><code> Future&lt;List&lt;allItems&gt;&gt; createList() async {
  
  HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('ratingClass');
  final results = await callable;
  final datList = await results.call(&lt;String, dynamic&gt;{
    'filename': fileName,
  
  });
  var resultData = await datList.data;
  
  var jList = json.decode(abcdef);
  
  for (var data in jList){
    originalList.add(new allItems( data['name'],data['type'], data['rating'].toString(), data['numberofrating'].toString()));
  }
  
  
  for (var ddata in jList!){
    if (ddata != null) {
      myCollection.add({
        'name': def['name'],
        'type':def['type'],
        'rating':def['ratings'],
        'numberofrating':def['numberofrating'],
  
      });
    }}
  
  return originalList;
  
  }
  </code></pre>