Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
480 views
in Technique[技术] by (71.8m points)

flutter - 在颤抖中获取小部件的高度(getting height of a widget in flutter)

I have made a list of widgets

(我列出了小部件)

List<Widget> my_list = [Text("Hello World"),Text("Hello Flutter")];

And I want to make a Widget which takes argument as list of widgets only in its constructor, and I have to do something using this widgets in which I need the size of each widget.

(我想制作一个仅在其构造函数中将参数作为窗口小部件列表的窗口小部件,并且我必须使用此窗口小部件执行某些操作,其中我需要每个窗口小部件的大小。)

Below is my Widget

(以下是我的小部件)

class MyCustomWidget extends StatefulWidget{
List<Widget> widget_list;
MyCustomWidget(this.widget_list);
@override
_MyCustomWidgetState createState() => _MyCustomWidgetState();
}

class _MyCustomWidgetState extends State<MyCustomWidget>{
List<double> widget_height; 
@override
  Widget build(BuildContext context) {
  return null;
  }
}

In this list( widget_height ) I have to save the height of each widget that is in the list( widget_list ).

(在这份名单中( widget_height )我必须保存在列表中(每个插件的高度widget_list )。)

How to do this.

(这该怎么做。)

Is there any method like widget_list[0].getHeight() ?

(是否有类似widget_list[0].getHeight() ?)

Edit: I can't use global key.

(编辑:我不能使用全局密钥。)

Refer comment section for more detail.

(请参阅评论部分以获取更多详细信息。)

And I need all this data before rendering the object.

(在渲染对象之前,我需要所有这些数据。)

So maybe we can override initState() method to get all this data betfore rendering.

(因此,也许我们可以重写initState()方法以在渲染之前获取所有这些数据。)

Maybe I an not correct in the last part about rendering.

(也许我对渲染的最后部分不正确。)

  ask by Abhishek Patil translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...