简体   繁体   English

dart中的响应式容器圆角

[英]Responsive container round corners in dart

I was thinking, in Dart/Flutter, can you insert a responsive value for a radius instead of this fixed value in below line我在想,在 Dart/Flutter 中,你能不能在下一行插入一个半径的响应值而不是这个固定值

topLeft: Radius.circular(20.0)

I wish I can just do somthing like:我希望我可以做类似的事情:

topLeft: Radius.circular(SOME SECRET CODE HERE JUST LIKE MEDIAQUERY THING THAT GETS RATIO FROM SCREEN SIZE)

I have used MediaQuery in我在中使用过 MediaQuery

 body: Container(
        width: MediaQuery.of(context).size.height * 0.4,
        height: MediaQuery.of(context).size.height * 0.6,
),

and it perfectly gave me these ratios of the drawn container in respect to screen size, so I need the round corners to inherit specific ratios just like the width and height.它完美地给了我绘制容器相对于屏幕尺寸的这些比率,所以我需要圆角来继承特定的比率,就像宽度和高度一样。

You can create some variables that holds the calculated value of the corners then use a setState to rebuild the screen.您可以创建一些变量来保存角落的计算值,然后使用 setState 来重建屏幕。 So the container will be rebuild with the new value.因此容器将使用新值重建。

double leftCornerRadius = 0.0;
//calculate the corner and setstate
setState(){
  leftCornerRadius = 15.0;
}
//and on the container user the variable
topLeft: Radius.circular(leftCornerRadius)

So everytime you recalculate the radius using setState will change the radius on the widget.因此,每次使用 setState 重新计算半径时,都会更改小部件上的半径。 Hope i could help.希望我能帮上忙。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM