I'm getting an
'await' can only be used in 'async' or 'async*' methods.
In popup error:
The await expression can only be used in an async function. Try
marking the function body with either 'async' or
'async*'.dart(await_in_wrong_context)
firestore.dart
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:workout/main.dart';
class FirestoreViewModel {
Future<List<int>> getDocuments(
String type, int numValues, bool isDescending) async {
List<int> _list;
QuerySnapshot documents = await FirebaseFirestore.instance
.collection('workouts')
.where('id', isEqualTo: googleSignIn.currentUser.id)
.orderBy('date', descending: isDescending)
.limit(numValues)
.get();
_list = documents.docs.map((snapshot) => snapshot['water'] as int).toList();
return _list;
}
}
file.dart
import 'package:workout/services/firestore_view_model.dart';
List<int> _waters = await FirestoreViewModel().getDocuments("water", 7, true);
I just can't seem to get a list with all the Futures, awaits, and asyncs going around. I've looked at other solutions on here but they are set up a bit differently. Either way, I don't know how to create a method that returns a list, when the firestore is full of futures. Any ideas would be appreciated.
question from:
https://stackoverflow.com/questions/65648913/dart-future-async-not-working-as-expected 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…