如何设置Card的高度并灵活制作?

时间:2020-06-26 06:06:30

标签: flutter dart flutter-layout

我想为胶片解贴卡的屏幕底部设置最小高度,并在描述较大时调整大小并滚动。我尝试这样做,但是当说明很小时,卡片就变小了,看起来好像很糟糕。

_screenHalf = (MediaQuery.of(context).size.height - AppBar().preferredSize.height) / 2;

   Widget _buildFilmDescriptionPage() {
    return Hero(
      tag: '$name',
      child: Container(
        width: double.infinity,
        decoration: BoxDecoration(
          image: DecorationImage(
              image: ExactAssetImage(image),
              fit: BoxFit.cover,
              alignment: Alignment.topCenter),
        ),
        child: _buildFilmDescriptionCard()
      ),
    );
  }

  ListView _buildFilmDescriptionCard() {
    return ListView(
          children: <Widget>[
             Card(
                elevation: 5,
                clipBehavior: Clip.hardEdge,              
                margin: EdgeInsets.only(top: _screenHalf),
                shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.vertical(
                      top: Radius.circular(20)
                    )
                ),
                child: Column(
                    children: <Widget>[
                      Container(
                        margin: const EdgeInsets.only(
                            top: 5, bottom: 5, left: 10, right: 10),
                        child: Text(
                          name,
                          style: TextStyle(
                            fontSize: 18,
                            color: Colors.black,
                          ),
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.only(
                            top: 5, bottom: 5, left: 10, right: 10),
                        child: Text(
                          date,
                          style: TextStyle(
                            fontSize: 14,
                            color: Colors.black,
                          ),
                        ),
                      ),
                      Container(
                          margin: const EdgeInsets.only(
                              top: 5, bottom: 5, left: 10, right: 10),
                          child: Text(
                            description,
                            style: TextStyle(
                              fontSize: 14,
                              color: Colors.black,
                            ),
                          ),
                        ),
                    ],
                  ),
              ),
          ],
        );
  }

enter image description here

1 个答案:

答案 0 :(得分:-1)

您可以使用ConstrainedBox (Docs) 并将其包装在SingleChildScrollView中。另外:如果您需要查找小部件,请考虑在此处制作书签:WidgetCatalog