如何在颤动中更改卡片的高度

jus*_*sty 20 height dart flutter flutter-card

Card(
  semanticContainer: true,
  clipBehavior: Clip.antiAliasWithSaveLayer,
  child: Image.network( 'https://placeimg.com/640/480/any',fit: BoxFit.fill),
  shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.circular(10.0),
  ),
  elevation: 5,
  margin: EdgeInsets.all(10),
)
Run Code Online (Sandbox Code Playgroud)

Joã*_*res 54

要修改卡片的宽度或高度,您可以将其包装在容器小部件中并为其提供高度和/或宽度属性。

请在下面查看您的代码,其中包含一个高度为 500 的容器:

Container(
  height: 500,
  child: Card(
    semanticContainer: true,
    clipBehavior: Clip.antiAliasWithSaveLayer,
    child: Image.network(
      'https://placeimg.com/640/480/any', fit: BoxFit.fill,),
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(10.0),
    ),
    elevation: 5,
    margin: EdgeInsets.all(10),
  ),
),
Run Code Online (Sandbox Code Playgroud)

  • 如果容器嵌套在另一个小部件中,则宽度和高度可能不会按预期应用。您可以[通过将该容器包装在对齐小部件中来克服这个问题](/sf/answers/3830249041/)。 (5认同)

小智 5

时间在移动,更喜欢你:https : //api.flutter.dev/flutter/widgets/SizedBox-class.html

SizedBox(
  height: double.infinity,
  child: Card(
    semanticContainer: true,
    clipBehavior: Clip.antiAliasWithSaveLayer,
    child: Image.network(
      'https://placeimg.com/640/480/any', 
      fit: BoxFit.fill,
    ),
    shape: RoundedRectangleBorder(
      borderRadius: BorderRadius.circular(10.0),
    ),
    elevation: 5,
    margin: EdgeInsets.all(10),
  ),
),
Run Code Online (Sandbox Code Playgroud)