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

问题描述 投票:0回答:1

我目前正在学习扑克,并遇到一个问题,卡不在列的范围内,但不会导致溢出。我的目标是将卡片放在底部,并将文字放在卡片上方。

这是我的代码:



  @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

dart flutter flutter-layout
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.