列中定位的小部件导致卡溢出

时间:2019-03-14 05:04:33

标签: dart flutter flutter-layout

我目前正在学习颤动,并且遇到了以下问题:卡未停留在列的边界内,但未引起溢出。我的目标是将卡放置在底部,并将文本放置在卡上方。

这是我的代码:



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
          children: <Widget>[
            Stack(
              children: <Widget>[
                Container(
                    height: MediaQuery.of(context).size.height,
                    child:
                        Image.asset("assets/testimage.jpg", fit: BoxFit.cover)),
                Positioned(
                  bottom: 10.0,
                  child: Card(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(15.0)),
                    child: Text(
                      "A description would be going here, this is just placeholder text.",
                      style: TextStyle(fontSize: 30),
                    ),
                  ),
                )
              ],
            ),
          ],
        ),
      ),
    );
  }
}

问题和预期结果的图像示例

Problem

Desired Outcome

1 个答案:

答案 0 :(得分:0)

您需要定义-right: 1.0, left: 1.0,以及Positioned中的底部。小部件。

   @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Column(
        children: <Widget>[
          Stack(
            children: <Widget>[
              Container(
                  height: MediaQuery.of(context).size.height,
                  child: Image.network("https://placeimg.com/640/480/any",
                      fit: BoxFit.cover)),
              Positioned(
                bottom: 1.0,
                right: 1.0,
                left: 1.0,
                child: Card(
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(15.0)),
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Text(
                      "A description would be going here, this is just placeholder text.",
                      style: TextStyle(fontSize: 30),
                    ),
                  ),
                ),
              )
            ],
          ),
        ],
      ),
    );
  }

输出:

enter image description here