Best practice for calling two different endpoints for a widget?

arjs

What is considered the best practice to use when two different endpoints are needed in order to render something? Right now I'm nesting FutureBuilders but that doesn't seem ideal.

Example:

@override
Widget build(BuildContext context) {
  return new FutureBuilder(
    future: Firestore.instance.collection('games').document(this.documentId).get(),
    builder: (BuildContext gamesContext, AsyncSnapshot gamesSnapshot) {
      return new FutureBuilder(
        future: Firestore.instance.collection('profiles').document(gamesSnapshot.data['authorId']).get(),
        builder: (BuildContext profilesContext, AsyncSnapshot profilesSnapshot) {
          // Code goes here.
        }
      ),
    }
  ),
}

There's got to be a cleaner way, right?

Günter Zöchbauer

You can do this with a single FutureBuilder:

Future<AsyncSnapshot> getProfiles() async {
  var gamesSnapshot = await Firestore.instance.collection('games').document(this.documentId).get();
  return Firestore.instance.collection('profiles').document(gamesSnapshot.data['authorId']).get()
}

@override
Widget build(BuildContext context) {
  return new FutureBuilder(
    future: getProfiles(),
    builder: (BuildContext profilesContext, AsyncSnapshot profilesSnapshot) {
      // Code goes here.
    }
  ),
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Best practice to run Linux service as a different user

From Dev

Best Practice to avoid using 'ifs' for calling methods

From Dev

Best practice for calling the NgbModal open method

From Dev

Best practice for validation of two related inputs in Matlab

From Dev

What is best practice to implement SQS on different environments?

From Dev

Best practice setup for two websites with different style sheets and templates, but similar Django back end

From Dev

Rails - Best practice to have completely two different designs

From Dev

Vue best practice for calling a method in a child component

From Dev

Publish two different endpoints on Kestrel for two different endpoints on ASP.NET Core

From Dev

What is the best practice to get data from two different http end points?

From Dev

Best practice for makefile calling other makefile

From Dev

Rust - Calling function with multiple types best practice

From Dev

Best practice for selecting two columns

From Dev

Best practice for dynamically translating content into different languages

From Dev

Best Practice to chain two functions,, AngularJs/JavaScript

From Dev

Calling a external API class on Observer best practice

From Dev

Best practice when calling self object methods

From Dev

flutter - how to best practice make a countdown widget

From Dev

Best practice for assigning key for different widgets?

From Dev

What is the best convention to generate multiple payload for different endpoints in python code?

From Dev

Stateful Widget updation on calling it with different parameters, not updating?

From Dev

Kubernetes best practice: different config for local or remote

From Dev

div calling two different functions

From Dev

OpenGL best practice for putting two different mesh in the same vertex VBO

From Dev

Best practice for calling save() many times

From Dev

Best practice for calling objects that are private members of a class?

From Dev

Ngrx effect dispatch different actions - best practice

From Dev

AWS DLQ for two consumers, what is best practice?

From Dev

Initialize final variable in Flutter widget - best practice

Related Related

  1. 1

    Best practice to run Linux service as a different user

  2. 2

    Best Practice to avoid using 'ifs' for calling methods

  3. 3

    Best practice for calling the NgbModal open method

  4. 4

    Best practice for validation of two related inputs in Matlab

  5. 5

    What is best practice to implement SQS on different environments?

  6. 6

    Best practice setup for two websites with different style sheets and templates, but similar Django back end

  7. 7

    Rails - Best practice to have completely two different designs

  8. 8

    Vue best practice for calling a method in a child component

  9. 9

    Publish two different endpoints on Kestrel for two different endpoints on ASP.NET Core

  10. 10

    What is the best practice to get data from two different http end points?

  11. 11

    Best practice for makefile calling other makefile

  12. 12

    Rust - Calling function with multiple types best practice

  13. 13

    Best practice for selecting two columns

  14. 14

    Best practice for dynamically translating content into different languages

  15. 15

    Best Practice to chain two functions,, AngularJs/JavaScript

  16. 16

    Calling a external API class on Observer best practice

  17. 17

    Best practice when calling self object methods

  18. 18

    flutter - how to best practice make a countdown widget

  19. 19

    Best practice for assigning key for different widgets?

  20. 20

    What is the best convention to generate multiple payload for different endpoints in python code?

  21. 21

    Stateful Widget updation on calling it with different parameters, not updating?

  22. 22

    Kubernetes best practice: different config for local or remote

  23. 23

    div calling two different functions

  24. 24

    OpenGL best practice for putting two different mesh in the same vertex VBO

  25. 25

    Best practice for calling save() many times

  26. 26

    Best practice for calling objects that are private members of a class?

  27. 27

    Ngrx effect dispatch different actions - best practice

  28. 28

    AWS DLQ for two consumers, what is best practice?

  29. 29

    Initialize final variable in Flutter widget - best practice

HotTag

Archive