簡體   English   中英

Flutter,如何設置具有最大高度300的靈活高度的項目列表的高度?

[英]Flutter, how can i set the height of list of items with flexible height with max height 300?

這是一張圖片(分支列表)

  • 我有一個容器,里面有一個包含分支列表的列。
  • 我需要將容器的高度設置為靈活,直到它達到高度 = 300,但實際發生的是它始終保持 300,如果它只包含一個項目,高度為 300 [但我需要它采取僅項目的實際高度],如果它包含超過 3 個項目,它仍然是 300。

 : Container(
                          decoration: BoxDecoration(
                              color: Theme.of(context).primaryColorDark,
                              borderRadius:
                                  BorderRadius.all(Radius.circular(10))),
                          ***constraints: BoxConstraints(
                            maxHeight: 300,
                            minHeight: 170,
                          ),***
                          width: double.infinity,
                          padding: EdgeInsets.all(8),
                          margin: EdgeInsets.only(left: 16, right: 16),
                          child: Column(
                            children: [
                              Align(
                                alignment: Alignment.centerLeft,
                                child: Text(
                                  'Select Branch',
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 20,
                                      fontWeight: FontWeight.bold),
                                ),
                              ),
                              SizedBox(
                                height: 8,
                              ),
                              Align(
                                alignment: Alignment.centerLeft,
                                child: Padding(
                                  padding: const EdgeInsets.only(left: 8.0),
                                  child: Text(
                                    'Number of branches = ${_branches.length}',
                                    style: TextStyle(
                                        color: Colors.grey, fontSize: 10),
                                  ),
                                ),
                              ),
                              SizedBox(
                                height: 16,
                              ),
                              Expanded(
                                child: ListView.builder(
                                  itemCount: _branches.length,
                                  itemBuilder: (ctx, i) {
                                    return GestureDetector(
                                      ....
                                      child: Card(
                                        elevation: 8,
                                        shape: RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(12),
                                        ),
                                        color:
                                            Theme.of(context).backgroundColor,
                                        child: Container(
                                          padding: EdgeInsets.all(20),
                                          child: Row(
                                            mainAxisSize: MainAxisSize.min,
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text(
                                                _branches[i]
                                                    .branchDistrict
                                                    .name,
                                                style: TextStyle(
                                                    color: Colors.white,
                                                    fontSize: 16),
                                              ),
                                              (_selectedBranchChecked == i)
                                                  ? Container(
                                                      height: 40,
                                                      width: 40,
                                                      child: Image.asset(
                                                        getAssetsName(
                                                            AssetsImage
                                                                .checkIcon),
                                                        fit: BoxFit.cover,
                                                      ),
                                                    )
                                                  : Container(
                                                      padding: EdgeInsets.only(
                                                          top: 5, bottom: 5),
                                                      height: 40,
                                                      width: 40,
                                                      decoration: BoxDecoration(
                                                        shape: BoxShape.circle,
                                                        color: Colors.white,
                                                      ),
                                                      child: SizedBox(),
                                                    ),
                                            ],
                                          ),
                                        ),
                                      ),
                                    );
                                  },
                                ),
                              ),
                            ],
                          ),
                        )

添加到容器屬性mainAxisSize: MainAxisSize.min中的 Column 中,我敢打賭你必須在這里刪除Expanded小部件

暫無
暫無

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

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