小部件的卡上的高度高度颤动
我想根据其中的小部件的高度设置卡的高度。 我使用globalKey
并将其设置在我的小部件中,但返回null。
谁能帮我怎么做?
final GlobalKey _Key = GlobalKey();
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
builder: (context) {
return Container(
key : _key,
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.zero,
children: [
PressWidget(),
PaddingButtonCard(),
],
),
);
},
);
当我打印_key.currentContext?.findRenderObject()。size
时,返回null。
I want to set the height for my cards based on the height of the widgets in it.
I use globalKey
and set it in my widget but return null.
can anyone help me how can I do that?
final GlobalKey _Key = GlobalKey();
showModalBottomSheet(
context: context,
useRootNavigator: true,
isScrollControlled: true,
isDismissible: true,
enableDrag: true,
builder: (context) {
return Container(
key : _key,
child: ListView(
shrinkWrap: true,
padding: EdgeInsets.zero,
children: [
PressWidget(),
PaddingButtonCard(),
],
),
);
},
);
when I print _Key.currentContext?.findRenderObject().size
, return null.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诸如卡之类的小部件应自动包装它的内容,因此,除非内容物的高度不受限制(例如
listView
或展开的
widget),否则不需要测量或这样的测量实现这一目标的技术。在您的
card> card
中,尝试,作为测试,将容器
放置一个 ,并观察卡的自动自动尺寸:A Widget like a card should automatically wrap it's contents, so unless the contents have an unconstrained height (like a
ListView
orExpanded
widget), you shouldn't need measuring or such techniques to achieve this.Try, as a test, putting a
Container
with a setheight
inside yourCard
, and observe how the card automatically sizes itself: