簡體   English   中英

包含在單個子滾動視圖中的列中的列表視圖不滾動 flutter

[英]list view in column wrapped inside singlechild scrollview not scrolling flutter

我想在 flutter 的列表視圖中實現滾動。但整個屏幕都在滾動。嘗試將列表視圖包裝在容器內,然后在單個子滾動視圖中,但這也不起作用 [1]: https://i.stack.imgur .com/1K3q0.png

    Scaffold(
     
      resizeToAvoidBottomInset: false,
      body: Container(
        height: double.maxFinite,
        // padding: const EdgeInsets.only(left: 8.0, right: 8),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Container(
              width: MediaQuery.of(context).size.width,
              child: Card(
                elevation: 15,
                child: Container()
                //DashboardAppbar(emp: loggedinEmpDetails),
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            selected == 0
                ? ListView(
                //  shrinkWrap: true,
                //   physics: NeverScrollableScrollPhysics(),
                 children: [
                   leaves == null
                       ? CircularProgressIndicator()
                       : DashboardCards(leaves!),
                   const SizedBox(
                     height: 10,
                   ),
                   for (int i = 0; i < userLeaves!.length; i++)
                     dashboardLeaveCards(
                         emp: employee![0],
                         userLeaves: userLeaves![i],
                         selected: selected,
                         leaveReasons: leaveReason),
                   const SizedBox(
                     height: 5,
                   )
                 ],
                    )
                : Column(

將物理和 shrinkWrap 添加到列表視圖

ListView(
  shrinkWrap:true,
  physics : NeverScrollableScrollPhysics(),
)

並刪除您添加物理的內部 SingleChildScrollView ..

編輯

而不是 listview 使用 List.generate


    Scaffold(
     
      resizeToAvoidBottomInset: false,
      body: Container(
        height: MediaQuery.of(context).size.height,
        // padding: const EdgeInsets.only(left: 8.0, right: 8),
        child:  Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Container(
              width: MediaQuery.of(context).size.width,
              child: Card(
                elevation: 15,
                child: Container()
                //DashboardAppbar(emp: loggedinEmpDetails),
              ),
            ),
            const SizedBox(
              height: 10,
            ),
            selected == 0
                ? Expanded( 
              child:ListView(
              shrinkWrap: true,
                 // physics: NeverScrollableScrollPhysics(),
                 children: [
                   leaves == null
                       ? CircularProgressIndicator()
                       : DashboardCards(leaves!),
                   const SizedBox(
                     height: 10,
                   ),
                   for (int i = 0; i < userLeaves!.length; i++)
                     dashboardLeaveCards(
                         emp: employee![0],
                         userLeaves: userLeaves![i],
                         selected: selected,
                         leaveReasons: leaveReason),
                   const SizedBox(
                     height: 5,
                   )
                 ],
                    )
                : Column(
             mainAxisSize: MainAxisSize.min,
             )
)

您不需要包裝多個可滾動小部件,只需將ListView包裝為Expanded小部件,並遵循此小部件結構。

body: Column(
  mainAxisSize: MainAxisSize.min,
  mainAxisAlignment: MainAxisAlignment.start,
  children: [
    Container(
      width: MediaQuery.of(context).size.width,
      child: Card(elevation: 15, child: Container()
          //DashboardAppbar(emp: loggedinEmpDetails),
          ),
    ),
    const SizedBox(
      height: 10,
    ),
    selected == 0
        ? Expanded(
            child: ListView(
              children: [
                //  leaves == null
                //      ? CircularProgressIndicator()
                //      : DashboardCards(leaves!),
                const SizedBox(
                  height: 10,
                ),
                for (int i = 0; i < 4; i++)
                  Container(
                    height: 100,
                  ),
                const SizedBox(
                  height: 5,
                )
              ],
            ),
          )
        : SingleChildScrollView(
            child: Column(
              children: [],
            ),
          )
  ],
),
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM