繁体   English   中英

颤振:扩展小部件内的 ListView 在我的颤动应用程序中没有滚动

[英]flutter: ListView inside Expanded widget is not scrolling in my flutter app

我只想滚动我的列表项。 但它不工作。 如果我使用 SingleChildScrollView wrap Column 小部件,那么它会滚动,但只有当我单击列项而不是 listTile 项时才会滚动。

这是我的输出这是我的输出 我的预期输出是https://prnt.sc/URbiBkWLuXRZ这是我的代码

SafeArea(
    child: Column(
      children: [
        Expanded(flex: 2, child: customAdminDashboard()),
        Expanded(
            flex: 3,
            child: Column(
              children: [
                const Center(
                    child: Text(
                  "Details of Member",
                  style: TextStyle(
                      fontSize: 18,
                      fontFamily: "Montserrat-BoldItalic",
                      color: Color(0xffed8073)),
                )),
                Padding(
                  padding: const EdgeInsets.only(
                      left: 20, right: 20, top: 2, bottom: 2),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: const [
                      Text(
                        "Member Name",
                        style: TextStyle(
                            fontSize: 18, color: Color(0xff925093)),
                      ),
                      Text("Balance",
                          style: TextStyle(
                              fontSize: 18, color: Color(0xff925093))),
                    ],
                  ),
                ),
                StreamBuilder<QuerySnapshot>(
                  stream: FirebaseFirestore.instance
                      .collection("User-data")
                      .snapshots(),
                  builder: (BuildContext context,
                      AsyncSnapshot<QuerySnapshot> snapshot) {
                    if (snapshot.hasError) {
                      return Text('Something went wrong');
                    }

                    if (snapshot.connectionState ==
                        ConnectionState.waiting) {
                      return Text("Loading");
                    }

                    return ListView.builder(
                        shrinkWrap: true,
                        physics: AlwaysScrollableScrollPhysics(),
                        scrollDirection: Axis.vertical,
                        itemCount: snapshot.data!.docs.length,
                        itemBuilder: (_, index) {
                          DocumentSnapshot _DocumentSnapshot =
                              snapshot.data!.docs[index];
                          return ListTile(
                            leading: Text(_DocumentSnapshot['Name']),
                            trailing: Text(
                                _DocumentSnapshot['Balance'].toString()),
                          );
                        });
                  },
                )
              ],
            ))
      ],
    ),
  ),

我只想滚动我的 listTile 项目

ListView.builder(
                        shrinkWrap: true,
                        physics: AlwaysScrollableScrollPhysics(),
                        scrollDirection: Axis.vertical,
                        itemCount: snapshot.data!.docs.length,
                        itemBuilder: (_, index) {
                          DocumentSnapshot _DocumentSnapshot =
                              snapshot.data!.docs[index];
                          return ListTile(
                            leading: Text(_DocumentSnapshot['Name']),
                            trailing: Text(
                                _DocumentSnapshot['Balance'].toString()),
                          );
                        })
SafeArea(
      child: Column(
        children: [
          Expanded(flex: 2, child: customAdminDashboard()),
          Expanded(
              flex: 3,
              child: Column(
                children: [
                  const Center(
                      child: Text(
                        "Details of Member",
                        style: TextStyle(
                            fontSize: 18,
                            fontFamily: "Montserrat-BoldItalic",
                            color: Color(0xffed8073)),
                      )),
                  Padding(
                    padding: const EdgeInsets.only(
                        left: 20, right: 20, top: 2, bottom: 2),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: const [
                        Text(
                          "Member Name",
                          style: TextStyle(
                              fontSize: 18, color: Color(0xff925093)),
                        ),
                        Text("Balance",
                            style: TextStyle(
                                fontSize: 18, color: Color(0xff925093))),
                      ],
                    ),
                  ),
                  Expanded(
                    child: SingleChildScrollView(
                      child: StreamBuilder<QuerySnapshot>(
                        stream: FirebaseFirestore.instance
                            .collection("User-data")
                            .snapshots(),
                        builder: (BuildContext context,
                            AsyncSnapshot<QuerySnapshot> snapshot) {
                          if (snapshot.hasError) {
                            return Text('Something went wrong');
                          }

                          if (snapshot.connectionState ==
                              ConnectionState.waiting) {
                            return Text("Loading");
                          }

                          return ListView.builder(
                              shrinkWrap: true,
                              physics: NeverScrollableScrollPhysics(),
                              scrollDirection: Axis.vertical,
                              itemCount: snapshot.data!.docs.length,
                              itemBuilder: (_, index) {
                                DocumentSnapshot _DocumentSnapshot =
                                snapshot.data!.docs[index];
                                return ListTile(
                                  leading: Text(_DocumentSnapshot['Name']),
                                  trailing: Text(
                                      _DocumentSnapshot['Balance'].toString()),
                                );
                              });
                        },
                      ),
                    ),
                  )
                ],
              ))
        ],
      ),
    );

请试试这个

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM