简体   繁体   English

如何根据内容调整小部件的大小

[英]how to resize widget based on content

I am using a draggable scrollable sheet and I want it to show the content based on how much content is currently to show in sheet for ex if I am using a visibility widget and it is visibility is false it should not show the space for it, but if it is true it should automatically resizes itself and show it on screen, I have total 4 widgets in my sheet 2 of them are in visibilty widget我正在使用可拖动的可滚动工作表,如果我使用可见性小部件并且可见性为假,我希望它根据当前在工作表中显示的内容量来显示内容,并且它不应该显示它的空间,但如果是真的,它应该自动调整大小并在屏幕上显示,我的工作表中总共有 4 个小部件,其中 2 个在可见性小部件中

when the visibility of widget changes you can change the minChildSize and maxChildSize of draggableScrollableSheet and set it to a specific value.当小部件的可见性发生变化时,您可以更改 draggableScrollableSheet 的 minChildSize 和 maxChildSize 并将其设置为特定值。

If you want to hide and unhide a widget but don't want that the hidden widget to take space on screen then instead of Visibility you should use if without any curly braces something like this.如果你想隐藏和取消隐藏一个小部件,但不希望隐藏的小部件在屏幕上占据空间,那么如果没有像这样的花括号,你应该使用 Visibility 而不是 Visibility。

Column(
  Children:[
   Text(Hello), 
   if(_isVisible) 
   SizedBox(height:200, width:500)
  ]
  ) 

If you want to add multiple column widget to be hide and show then use spread operator如果要添加多列小部件以隐藏和显示,请使用扩展运算符

Column(
  Children:[
   Text(Hello), 
   if(_isVisible) ...[
   SizedBox(height:200, width:500), 
   Container(height:400, width:500, 
       Color:Colors.red) 
    ]
  ]) 

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

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