Sizing elements to percentage of screen width/height

前端 未结 10 1743
情深已故
情深已故 2020-11-30 17:11

Is there a simple (non-LayoutBuilder) way to size an element relative to screen size (width/height)? For example: how do I set the width of a CardView to be 65% of the scree

10条回答
  •  春和景丽
    2020-11-30 17:30

    you can use MediaQuery with the current context of your widget and get width or height like this double width = MediaQuery.of(context).size.width double height = MediaQuery.of(context).size.height after that, you can multiply it with the percentage you want

提交回复
热议问题