Returning Future<Object> instead of Object

dgebert

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.

Owczar

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

ReadToken() is returning "Instance of 'Future<Object>'"

From Dev

Console returning [Object object] instead of object members

From Dev

Why is it returning address instead of object?

From Dev

Promise returning a function instead of an object

From Dev

Laravel returning "Object" instead of Array?

From PHP

Returning a object gets true instead of beeing an object

From Dev

Problem with Python returning a NoneType object instead of the Object

From Java

Thymeleaf returning a String array instead of List<Object>

From Javascript

javascript push returning number instead of object

From Dev

jwplayer returning function instead of player object

From Python

Django HttpResponse returning object instead of stated string

From Dev

Linq select returning string instead of object

From Dev

NGRX 8 reducer returning Object instead of Array

From Dev

simple string split is returning object instead array

From Dev

Creating constructors using "this" instead of simply returning an object

From Dev

Python returning Hexadecimal address instead of object

From Dev

Laravel getCountForPagination() returning Object instead of int

From Dev

React.CloneElement returning an object instead of function

From Dev

jquery val returning object instead of string

From Dev

Redux - returning an array instead of an object in the reducer

From Dev

Contract function returning a transaction object instead of a BOOL

From Dev

Returning SVG object or XML string instead of an Image

From Dev

Mocked method is returning null instead of expected object

From Dev

Redux returning a proxy object instead of the state

From Dev

Python returning object "placement" instead of float

From Dev

Returning [object Promise] instead of actual value

From Dev

Reduce function returning an object instead of an array

From Dev

Returning Mono<Object> instead of Mono<Void>

From Dev

JSON.parse returning [Object Object] instead of value

Related Related

  1. 1

    ReadToken() is returning "Instance of 'Future<Object>'"

  2. 2

    Console returning [Object object] instead of object members

  3. 3

    Why is it returning address instead of object?

  4. 4

    Promise returning a function instead of an object

  5. 5

    Laravel returning "Object" instead of Array?

  6. 6

    Returning a object gets true instead of beeing an object

  7. 7

    Problem with Python returning a NoneType object instead of the Object

  8. 8

    Thymeleaf returning a String array instead of List<Object>

  9. 9

    javascript push returning number instead of object

  10. 10

    jwplayer returning function instead of player object

  11. 11

    Django HttpResponse returning object instead of stated string

  12. 12

    Linq select returning string instead of object

  13. 13

    NGRX 8 reducer returning Object instead of Array

  14. 14

    simple string split is returning object instead array

  15. 15

    Creating constructors using "this" instead of simply returning an object

  16. 16

    Python returning Hexadecimal address instead of object

  17. 17

    Laravel getCountForPagination() returning Object instead of int

  18. 18

    React.CloneElement returning an object instead of function

  19. 19

    jquery val returning object instead of string

  20. 20

    Redux - returning an array instead of an object in the reducer

  21. 21

    Contract function returning a transaction object instead of a BOOL

  22. 22

    Returning SVG object or XML string instead of an Image

  23. 23

    Mocked method is returning null instead of expected object

  24. 24

    Redux returning a proxy object instead of the state

  25. 25

    Python returning object "placement" instead of float

  26. 26

    Returning [object Promise] instead of actual value

  27. 27

    Reduce function returning an object instead of an array

  28. 28

    Returning Mono<Object> instead of Mono<Void>

  29. 29

    JSON.parse returning [Object Object] instead of value

HotTag

Archive