Home > Net >  why this listview leaving a space in flutter
why this listview leaving a space in flutter

Time:05-11

  MaterialApp(
  home: Scaffold(
    body: DefaultTabController(
      length: 3,
      child: NestedScrollView(
        headerSliverBuilder: (context, value) {
          // GetTopRated();
          return [
            SliverAppBar(
              elevation: 0,
              backgroundColor: primaryColor,
              expandedHeight: MediaQuery.of(context).size.height * .30,
              stretch: true,
              centerTitle: true,
              leading: GestureDetector(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child: Icon(Icons.arrow_back_outlined)),

              flexibleSpace: FlexibleSpaceBar(
                // background: Image.network(
                //   name,
                //   height: MediaQuery.of(context).size.height * .23,
                // ),
                centerTitle: true,
                title: Text(widget.name),
              ),
            ),
            SliverPersistentHeader(
              delegate: _SliverAppBarDelegate(
                  TabBar(
                    labelColor: Colors.white,
                    labelStyle: TextStyle(fontSize: 18),
                    tabs: [
                      Tab(
                        text: "Table",
                      ),
                      Tab(
                        text: "Played",
                      ),
                      Tab(
                        text: "Upcoming",
                      ),
                    ],
                  ),
                  primaryColor),
              // pinned: true,
            )
          ];
        },
        // body: upcomingMatches(),
        body: TabBarView(children: [
          // table(context, i),
          // playedMatches(context),
          // upcomingMatches()

          FutureBuilder(
            future: getData(widget.league_id),
            builder: (context, snapshot) {
              if (!snapshot.hasData) {
                return Container(
                  height: MediaQuery.of(context).size.height,
                  color: primaryColor,
                  child: Center(
                    child: CircularProgressIndicator(
                      color: Colors.white,
                    ),
                  ),
                );
              }
              return SingleChildScrollView(
                child: Container(
                  color: secondaryColor,
                  child: Column(
                    children: [
                      Container(

                        child: Row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Container(),
                            Container(
                              width: MediaQuery.of(context).size.width * .43,
                              padding: EdgeInsets.symmetric(vertical: 6),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment:
                                MainAxisAlignment.spaceBetween,
                                children: [
                                  Text(
                                    "PL",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color: Colors.white,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    "W",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color: Colors.white,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    "D",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color: Colors.white,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    "L",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color: Colors.white,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  Text(
                                    "PTS",
                                    style: TextStyle(
                                        fontSize: 15,
                                        color: Colors.white,
                                        fontWeight: FontWeight.bold),
                                  ),
                                  SizedBox(),
                                ],
                              ),
                            ),
                          ],
                        ),
                      ),

                      ListView.builder(

                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        itemBuilder: (context, index) {
                          return Container(
                            // color: secondaryColor,
                            padding: EdgeInsets.symmetric(vertical: 10),
                            child: Row(
                              // crossAxisAlignment: CrossAxisAlignment.center,
                              mainAxisAlignment:
                              MainAxisAlignment.spaceBetween,
                              children: [
                                GestureDetector(
                                  onTap: () {
                                    print(snapshot.data[index].team_id);
                                    Navigator.of(context).push(
                                      MaterialPageRoute(
                                        builder: (context) => TeamInfo(
                                            context,
                                            snapshot.data[index].team_id,
                                            snapshot.data[index].team_badge,
                                            snapshot.data[index].team_name),
                                      ),
                                    );
                                  },

                                  child: Row(
                                    children: [
                                      Image.network(
                                        snapshot.data[index].team_badge,
                                        width: 35,
                                        errorBuilder: (BuildContext context,
                                            Object object,
                                            StackTrace stackTrace) {
                                          return Image.network(
                                            snapshot.data[index].team_badge,
                                            width: 30,
                                            errorBuilder:
                                                (BuildContext context,
                                                Object object,
                                                StackTrace stackTrace) {
                                              return Image.network(
                                                imageError,
                                                width: 30,
                                              );
                                            },
                                          );
                                        },
                                      ),
                                      SizedBox(
                                        width: 10,
                                      ),
                                      Container(
                                        width: MediaQuery.of(context)
                                            .size
                                            .width *
                                            .28,
                                        child: Text(
                                          snapshot.data[index].team_name,
                                          style: TextStyle(
                                            color: Colors.white,
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                                Container(
                                  width: MediaQuery.of(context).size.width *
                                      .43,
                                  child: Row(
                                    crossAxisAlignment:
                                    CrossAxisAlignment.center,
                                    mainAxisAlignment:
                                    MainAxisAlignment.spaceBetween,
                                    children: [
                                      Text(
                                        snapshot.data[index]
                                            .overall_league_payed,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Text(
                                        snapshot
                                            .data[index].overall_league_W,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Text(
                                        snapshot
                                            .data[index].overall_league_D,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Text(
                                        snapshot
                                            .data[index].overall_league_L,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      Text(
                                        snapshot
                                            .data[index].overall_league_PTS,
                                        style: TextStyle(
                                            fontSize: 14,
                                            color: Colors.white,
                                            fontWeight: FontWeight.bold),
                                      ),
                                      SizedBox(),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          );
                        },
                        itemCount: snapshot.data.length,
                      ),
                    ],
                  ),
                ),
              );
            },
          ),
          // Container(
          //   child: Text("data"),
          // ),
          Container(
            color: backgroundColor,
            child: FutureBuilder(
              future: getMatchesPlayed(widget.league_id),
              builder: (context, snapshot) {
                if (!snapshot.hasData) {
                  return Container(
                    height: MediaQuery.of(context).size.height,
                    color: primaryColor,
                    child: Center(
                      child: CircularProgressIndicator(
                        color: Colors.white,
                      ),
                    ),
                  );
                }
                return ListView.builder( //there 
                  itemCount: snapshot.data.length,
                  itemBuilder: (__, index) {
                    int itemCount = snapshot.data.length ?? 0;
                    int reversedIndex = itemCount - 1 - index;

                    return Card(
                      color: secondaryColor,
                      margin: EdgeInsets.all(10),
                      shape: RoundedRectangleBorder(
                          borderRadius: BorderRadius.circular(10)),
                      child: Container(
                          padding: EdgeInsets.all(10),
                          child: Column(
                            children: [
                              SizedBox(height:13),
                              Row(
                                crossAxisAlignment:
                                CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    width:
                                    MediaQuery.of(context).size.width *
                                        0.391,
                                    child: Row(
                                      mainAxisAlignment:
                                      MainAxisAlignment.end,
                                      children: [
                                        Container(
                                          width: MediaQuery.of(context)
                                              .size
                                              .width *
                                              0.29,
                                          child: Text(
                                            snapshot.data[reversedIndex]
                                                .match_hometeam_name,
                                            textAlign: TextAlign.end,
                                            style: TextStyle(
                                                color: Colors.white,
                                                fontSize: 17),
                                          ),
                                        ),
                                        SizedBox(width: 5),
                                        Image.network(
                                          snapshot.data[reversedIndex]
                                              .team_home_badge,
                                          width: 35,
                                          errorBuilder: (BuildContext,
                                              Object, StackTrace) {
                                            return Image.network(
                                                imageError);
                                          },
                                        ),
                                      ],
                                    ),
                                  ),
                                  Container(
                                    padding:
                                    EdgeInsets.symmetric(horizontal: 7),
                                    child: Row(
                                      children: [
                                        Text(snapshot.data[reversedIndex]
                                            .match_hometeam_score " - " snapshot.data[reversedIndex].match_awayteam_score,style:TextStyle(
                                          color: Colors.white,
                                          fontSize: 17,
                                          fontWeight: FontWeight.w600,
                                        ),),

                                      ],
                                    ),
                                  ),
                                  Container(
                                    width:
                                    MediaQuery.of(context).size.width *
                                        0.391,
                                    child: Row(
                                      children: [
                                        Image.network(
                                          snapshot.data[reversedIndex]
                                              .team_away_badge,
                                          width: 35,
                                          errorBuilder: (BuildContext,
                                              Object, StackTrace) {
                                            return Image.network(
                                                imageError);
                                          },
                                        ),
                                        SizedBox(width: 5),
                                        Container(
                                          width: MediaQuery.of(context)
                                              .size
                                              .width *
                                              0.29,
                                          child: Text(
                                            snapshot.data[reversedIndex]
                                                .match_awayteam_name,
                                            textAlign: TextAlign.start,
                                            style: TextStyle(
                                                color: Colors.white,
                                                fontSize: 17),
                                          ),
                                        ),
                                      ],
                                    ),
                                  )
                                ],
                              ),
                              SizedBox(height: 4 ),
                              Container(
                                decoration: BoxDecoration(
                                    color: Colors.grey[350],
                                    borderRadius: BorderRadius.circular(11)
                                ),
                                child: Text(
                                  snapshot.data[reversedIndex].match_status,
                                  style: TextStyle(color: Colors.black),
                                ),
                                padding: EdgeInsets.symmetric(horizontal: 7,vertical: 2),
                              ),
                            ],
                          )),
                    );
                  },
                );
              },
            ),
          ),
          Container(
            child: Text("data"),
          ),
        ]),
      ),
    ),
  ),
  debugShowCheckedModeBanner: false,
);

} }

there is a futurebuilder that make get a data from a function the put them like in the following picture but there is a space in the listview i have commented what i think the error is and i dont know what is the problem

enter image description here

CodePudding user response:

The ListView widget has a default padding from the top. If you want to remove it, you should pass new padding with the size you want.

Eg.

ListView.builder(
 padding: EdgeInsets.zero /// Removes the padding from all sides.
 ...
);

or

ListView(
 padding: EdgeInsets.zero
 ...
);

You can also check here.

CodePudding user response:

Open Flutter Performance tab (you can search with search button) in Android Studio and click to the blue button(Show Debug Paint). Thus you will be able to inspect paddings and margins of widgets.

  • Related