Problem with filling the list after await command

Solution 1:

Add await before imgList.forEach like

List<String> list = [];
await imgList.forEach((element) async {
  final String filePath = element.path;
  final res =
      filePath.substring(filePath.lastIndexOf('im'), filePath.length);
  
  final ref = FirebaseStorage.instance.ref().child('images').child(res);
  await ref.putFile(File(element.path));
  final imageUrl = await ref.getDownloadURL();
  list.add(imageUrl);
});

final doc = FirebaseFirestore.instance.collection('cars').doc();

edit

if this doesn't work then you may use for loop instead of forEach like

List<String> list = [];
    for(var element in imgList) {
      final String filePath = element.path;
      final res =
          filePath.substring(filePath.lastIndexOf('im'), filePath.length);
      
      final ref = FirebaseStorage.instance.ref().child('images').child(res);
      await ref.putFile(File(element.path));
      final imageUrl = await ref.getDownloadURL();
      list.add(imageUrl);
    }
    
    final doc = FirebaseFirestore.instance.collection('cars').doc();