I am trying to understand why IDE is not complaining about changing the type from Object to Future in this function:
class PromotionRepository implements IPromotionRepository {
final CollectionReference collection =
FirebaseFirestore.instance.collection('promotions');
Future<List<Promotion>> getAllPromotions() async {
QuerySnapshot query = await collection.get();
List<Promotion> promotions =
query.docs.map((doc) => Promotion.fromFirestore(doc)).toList();
return promotions;
}
}
In this case I am returning List<Promotion>
, not the Future<List<Promotion>
, but in method signature I have returning type defined as Feature...
There is no difference if I change to just List<Promotion>
. It works the same way in both cases.
You return List<Promotion>
but inside async method. Everything returned in async methods is a Future
.
You even declared type before name of the method.
Here you have few simple samples. Notice, that everywhere true
is returned, but in different types of methods.
void main() {
print(streamTest().runtimeType); // result: Stream<bool>
print(asyncTest().runtimeType); // result: Future<bool>
print(syncTest().runtimeType); // esult bool
}
Stream<bool> streamTest() async* {
yield true;
}
Future<bool> asyncTest() async => true;
bool syncTest() => true;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments