How to change height of a card in flutter
Asked Answered
O

2

41
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),
)
Oozy answered 26/9, 2019 at 10:48 Comment(1)
You can wrap it with a Container: Container(height: 100, child: Card( semanticContainer: true, clipBehavior: Clip.antiAliasWithSaveLayer, child: Image.network( 'placeimg.com/640/480/any',fit: BoxFit.fill,), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), elevation: 5, margin: EdgeInsets.all(10), ))Ditchwater
M
83

To modify the width or height of a card you can wrap it in a Container Widget and provide height and/or width properties to it.

Please see below your code wrapped with a container set with height at 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),
  ),
),
Metaphosphate answered 26/9, 2019 at 11:30 Comment(1)
If the Container is nested in another widget, the width & height may not get applied as expected. You can overcome this by wrapping that Container in an Align widget.Slipshod
I
17

Time is moving, prefer you that: 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),
  ),
),
Infra answered 6/6, 2020 at 9:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.