title: Cannot save values from Firestore ​in a List
body: <p>Good evening everyone, I have a problem with Firebase. Basically I'm creating a leaderboard and I have to find the 7 users with the most points, no problem on that one but I can't understand how to save the data of the 7 users into a List to show them later in a Text widget.</p>
  <p>The function I created is this :</p>
  <pre><code>    Future&lt;void&gt; getLeaderboard() async {
      return await FirebaseFirestore.instance
          .collection(&quot;leaderboard&quot;)
          .orderBy('Score', descending: true)
          .limit(7)
          .get()
          .then((QuerySnapshot querySnapshot) =&gt; {
        querySnapshot.docs.forEach((doc) {
          setState(() {
            LeaderboardPositionList.add(doc[&quot;Nick&quot;]);
            LeaderboardPositionList.add(doc[&quot;Score&quot;]);
          });
        }),
      });
    }
  </code></pre>
  <p>I created the List : <code>List&lt;String&gt; LeaderboardPositionList;</code></p>
  <p>and I initialized the function</p>
  <pre><code>  @override
    void initState() {
      super.initState();
      asyncMethod();
    }
  
    void asyncMethod() async {
     await getLeaderboard();
    }
  </code></pre>
  <p>and to recall the various nicknames and scores of the 7 users to put them in a text widget I do this:</p>
  <pre><code>Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[1],
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontFamily: 'Roboto',
                                    color: const Color(0xFF3A404C),
                                    fontSize: 20.0.sp),
                                textAlign: TextAlign.center,
                              ),
  </code></pre>
  <p>But when I open the page it always remain in loading.</p>
  <p>If i do <code>print(doc[&quot;Nick]);</code></p>
  <p>The first nickname in the leaderboard is printed.</p>
  <p>I also found this &quot;error&quot; in debugging :
  Tried calling: add(&quot;lolc&quot;) ...(lolc is one of the nick in the leaderboard).</p>
  <p>This is all the code of the page :</p>
  <pre><code>import 'package:sizer/sizer.dart';
  import 'package:flutter/material.dart';
  import 'package:firebase_auth/firebase_auth.dart';
  import 'package:cloud_firestore/cloud_firestore.dart';
  import 'package:goodgoals_android/pages/home_page.dart';
  import 'package:goodgoals_android/pages/profile_page.dart';
  import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';
  import 'package:goodgoals_android/services/authentication.dart';
  
  
  class soloLeaderboardPage extends StatefulWidget {
    soloLeaderboardPage({Key key, this.auth, this.userId, this.logoutCallback, this.home})
        : super(key: key);
  
    final BaseAuth auth;
    final VoidCallback logoutCallback;
    final String userId;
    final HomePage home;
  
    @override
    State&lt;StatefulWidget&gt; createState() =&gt; new _soloLeaderboardPageState();
  }
  
  
  class _soloLeaderboardPageState extends State&lt;soloLeaderboardPage&gt; {
  
    final _formKey = new GlobalKey&lt;FormState&gt;();
    final databaseReference = FirebaseFirestore.instance;
    final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
  
    var _selectedTab = _SelectedTab.leaderboard;
  
  List&lt;String&gt; LeaderboardPositionList = [];
  
    @override
    void initState() {
      super.initState();
      asyncMethod();
    }
  
    void asyncMethod() async {
     await getLeaderboard();
    }
  
    void _handleIndexChanged(int i) {
      setState(() {
        _selectedTab = _SelectedTab.values[i];
        print(&quot;Valore $i&quot;);
        if (i == 0) {
          Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) =&gt; HomePage(),
              ));
        }
        else if (i == 3) {
          Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) =&gt; ProfilePage(),
              ));
        }
        else if (i == 2) {
          Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) =&gt; soloLeaderboardPage(),
              ));
        }
      });
    }
    Future&lt;void&gt; getLeaderboard() async {
      return await FirebaseFirestore.instance
          .collection(&quot;leaderboard&quot;)
          .orderBy('Score', descending: true)
          .limit(7)
          .get()
          .then((QuerySnapshot querySnapshot) =&gt; {
        querySnapshot.docs.forEach((doc) {
          print(&quot;Done&quot;);
          setState(() {
            LeaderboardPositionList.add(doc[&quot;Nick&quot;]);
            LeaderboardPositionList.add(doc[&quot;Score&quot;]);
          });
        }),
      });
    }
  
  
  
    @override
    Widget build(BuildContext context) {
  
      return new Scaffold(
        body: Stack(
            children: &lt;Widget&gt;[
              _showForm(),
  
            ]
        ),
      );
    }
  
    Widget _showForm() {
  
      return new Container(
          padding: EdgeInsets.all(10.0),
          child: new Form(
            key: _formKey,
            child: new ListView(
              physics: const NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              children: &lt;Widget&gt;[
                leaderbordSelector(),
                showPodium1(),
                showOtherPosition(),
                bottomBarMimic(),
                //bottomBarMimic(),
              ],
  
            ),
          ));
    }
  
    Widget bottomBarMimic() {
      return Positioned(
        width: 100.0.w,
        bottom: 0,
        left: 0,
        child: Container(
            color: Colors.white,
            child: SalomonBottomBar(
              currentIndex: _SelectedTab.values.indexOf(_selectedTab),
              onTap: _handleIndexChanged,
              items: [
                SalomonBottomBarItem(
                  icon: Icon(Icons.home),
                  title: Text(&quot;Home&quot;),
                  selectedColor: Colors.purple,
                ),
                SalomonBottomBarItem(
                  icon: Icon(Icons.menu_book_sharp),
                  title: Text(&quot;Magazine&quot;),
                  selectedColor: Colors.pink,
                ),
                SalomonBottomBarItem(
                  icon: Icon(Icons.bar_chart),
                  title: Text(&quot;Leaderboard&quot;),
                  selectedColor: Colors.orange,
                ),
                SalomonBottomBarItem(
                  icon: Icon(Icons.person),
                  title: Text(&quot;Profile&quot;),
                  selectedColor: Colors.teal,
                ),
              ],
            )),
      );
    }
  
    Widget leaderbordSelector() {
      return new Padding(
        padding: EdgeInsets.symmetric(vertical: 5.0.h, horizontal: 17.0.h),
        child: Row(
          children: &lt;Widget&gt;[
            IconButton(
                icon: Icon(Icons.person, color: Colors.blue),
                onPressed: () {}
            ),
            IconButton(
                icon: Icon(Icons.people),
                onPressed: () {}
            ),
          ],
        ),
      );
    }
  
  
    Widget showPodium1() {
      return Container(
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: &lt;Widget&gt;[
              Column(
                children: &lt;Widget&gt;[
                  Container(
                    height: 20.0.h,
                    width: 30.0.w,
                    decoration: BoxDecoration(
                        color: const Color(0xFFFFFFFF),
                        borderRadius: BorderRadius.all(Radius.circular(5.0)),
                        border: Border.all(color: Colors.black),
                        boxShadow: [
                          BoxShadow(
                            color: Colors.grey.withOpacity(0.5),
                            spreadRadius: 2,
                            blurRadius: 7,
                            offset: Offset(0, 3),
                          )
                        ]
                    ),
                    child: Stack(
                        children: &lt;Widget&gt;[
                          Container(
                            width: 80.0.w,
                            height: 10.0.h,
                            decoration: new BoxDecoration(
                                shape: BoxShape.circle,
                                image: new DecorationImage(
                                  fit: BoxFit.fitHeight,
                                  image: AssetImage('assets/images/no_image.png'),
                                )),
                          ),
  
                          Container(
                              height: 10.0.h,
                              width: 10.0.w,
                              child:
                              new Image(
                                image: AssetImage(
                                    &quot;assets/images/medal_third.png&quot;),
                              )),
  
                          Stack(
                            alignment: Alignment.center,
                            children: &lt;Widget&gt;[
                              Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[0],
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontFamily: 'Roboto',
                                    color: const Color(0xFF3A404C),
                                    fontSize: 20.0.sp),
                                textAlign: TextAlign.center,
                              ),
                              new Align(alignment: Alignment.bottomCenter,
                                child: Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[1],
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontFamily: 'Roboto',
                                      color: const Color(0xFF3A404C),
                                      fontSize: 15.0.sp),
                                ),
                              ),
  
                            ],
                          ),
                        ]),
                  )],
              ),
  
              Column(
                children: &lt;Widget&gt;[
                  Container(
                      height: 20.0.h,
                      width: 30.0.w,
                      decoration: BoxDecoration(
                          color: const Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.all(Radius.circular(5.0)),
                          border: Border.all(color: Colors.black),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.grey.withOpacity(0.5),
                              spreadRadius: 2,
                              blurRadius: 7,
                              offset: Offset(0, 3),
                            )
                          ]
                      ),
                      child: Stack(
                        children: &lt;Widget&gt;[
                          Container(
                            width: 80.0.w,
                            height: 10.0.h,
                            decoration: new BoxDecoration(
                                shape: BoxShape.circle,
                                image: new DecorationImage(
                                  fit: BoxFit.fitHeight,
                                  image: AssetImage('assets/images/no_image.png'),
                                )),
                          ),
                          Container(
                              height: 10.0.h,
                              width: 10.0.w,
                              child:
                              new Image(
                                image: AssetImage(
                                    &quot;assets/images/medal_first.png&quot;),
                              )),
  
                          Stack(
                            alignment: Alignment.center,
                            children: &lt;Widget&gt;[
                              Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[2],
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontFamily: 'Roboto',
                                    color: const Color(0xFF3A404C),
                                    fontSize: 20.0.sp),
                                textAlign: TextAlign.center,
                              ),
                              new Align(alignment: Alignment.bottomCenter,
                                child: Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[3],
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontFamily: 'Roboto',
                                      color: const Color(0xFF3A404C),
                                      fontSize: 15.0.sp),
                                ),
                              ),
  
                            ],
                          ),
                        ],
                      )
                  ),
                ],
              ),
  
              Column(
                children: &lt;Widget&gt;[
                  Container(
                      height: 20.0.h,
                      width: 30.0.w,
                      decoration: BoxDecoration(
                          color: const Color(0xFFFFFFFF),
                          borderRadius: BorderRadius.all(Radius.circular(5.0)),
                          border: Border.all(color: Colors.black),
                          boxShadow: [
                            BoxShadow(
                              color: Colors.grey.withOpacity(0.5),
                              spreadRadius: 2,
                              blurRadius: 7,
                              offset: Offset(0, 3),
                            )
                          ]
                      ),
                      child: Stack(
                        children: &lt;Widget&gt;[
                          Container(
                            width: 80.0.w,
                            height: 10.0.h,
                            decoration: new BoxDecoration(
                                shape: BoxShape.circle,
                                image: new DecorationImage(
                                  fit: BoxFit.fitHeight,
                                  image: AssetImage('assets/images/no_image.png'),
                                )),
                          ),
                          Container(
                              height: 10.0.h,
                              width: 10.0.w,
                              child:
                              new Image(
                                image: AssetImage(
                                    &quot;assets/images/medal_second.png&quot;),
                              )),
  
                          Stack(
                            alignment: Alignment.center,
                            children: &lt;Widget&gt;[
                              Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[4],
                                style: TextStyle(
                                    fontWeight: FontWeight.bold,
                                    fontFamily: 'Roboto',
                                    color: const Color(0xFF3A404C),
                                    fontSize: 20.0.sp),
                                textAlign: TextAlign.center,
                              ),
                              new Align(alignment: Alignment.bottomCenter,
                                child: Text(LeaderboardPositionList == null ?  &quot;Loading...&quot; : LeaderboardPositionList[5],
                                  style: TextStyle(
                                      fontWeight: FontWeight.bold,
                                      fontFamily: 'Roboto',
                                      color: const Color(0xFF3A404C),
                                      fontSize: 15.0.sp),
                                ),
                              ),
  
                            ],
                          ),
                        ],
                      )
                  ),
                ],
              ),
  
            ],
          ));
    }
  
  
    Widget showOtherPosition() {
      return Card(
        margin: EdgeInsets.symmetric(vertical: 4.0.h),
        elevation: 0,
        color: Colors.transparent,
        child: Padding(
            padding: EdgeInsets.symmetric(vertical: 0.5.h),
            child: Column(
              children: &lt;Widget&gt;[
                Wrap(
                  spacing: 5.0,
                  children: &lt;Widget&gt;[
                    Container(
                      height: 10.0.h,
                      width: 500.0.w,
                      color: Colors.transparent,
                      child: Container(
                        decoration: BoxDecoration(
                            color: const Color(0xFFFFFFFF),
                            borderRadius: BorderRadius.all(Radius.circular(10.0)),
                            boxShadow: [
                              BoxShadow(
                                color: Colors.grey.withOpacity(0.5),
                                spreadRadius: 1,
                                blurRadius: 7,
                                offset: Offset(0, 3),
                              )
                            ]
                        ),
                      ),
                    ),
                    SizedBox(height: 20),
                    Container(
                      height: 10.0.h,
                      width: 500.0.w,
                      color: Colors.transparent,
                      child: Container(
                        decoration: BoxDecoration(
                            color: const Color(0xFFFFFFFF),
                            borderRadius: BorderRadius.all(Radius.circular(10.0)),
                            boxShadow: [
                              BoxShadow(
                                color: Colors.grey.withOpacity(0.5),
                                spreadRadius: 1,
                                blurRadius: 7,
                                offset: Offset(0, 3),
                              )
                            ]
                        ),
                      ),
                    ),
                    SizedBox(height: 20),
                    Container(
                        height: 10.0.h,
                        width: 500.0.w,
                        color: Colors.transparent,
                        child: Container(
                          decoration: BoxDecoration(
                              color: const Color(0xFFFFFFFF),
                              borderRadius: BorderRadius.all(
                                  Radius.circular(10.0)),
                              boxShadow: [
                                BoxShadow(
                                  color: Colors.grey.withOpacity(0.5),
                                  spreadRadius: 1,
                                  blurRadius: 7,
                                  offset: Offset(0, 3),
                                )
                              ]
                          ),
                        )),
                    SizedBox(height: 20),
                    Container(
                      height: 10.0.h,
                      width: 500.0.w,
                      color: Colors.transparent,
                      child: Container(
                        decoration: BoxDecoration(
                            color: const Color(0xFFFFFFFF),
                            borderRadius: BorderRadius.all(Radius.circular(10.0)),
                            boxShadow: [
                              BoxShadow(
                                color: Colors.grey.withOpacity(0.5),
                                spreadRadius: 1,
                                blurRadius: 7,
                                offset: Offset(0, 3),
                              )
                            ]
                        ),
                      ),
                    ),
  
                  ],
                )
              ],
            )),
      );
    }
  
  }
  enum _SelectedTab {home, magazine, leaderboard, ProfilePage}
  </code></pre>