flutter - Align Widget inside Stack 占全屏

标签 flutter

我正在使用对齐在我的堆栈中定位小部件。当我在堆栈中的任何子项中使用对齐时,堆栈会占据全屏。否则堆栈是最高的 child 的高度。我在这里很困惑。 align 不是用来对齐堆栈中的 child 吗?

这是我的代码:

   bottomNavigationBar: Stack(
    children: <Widget>[
      Container(
        color: Colors.greenAccent,
        width: double.infinity,
        height: 45,
      ),
      Align(
        alignment: Alignment.bottomCenter,
        child: Container(
         width: 80,
         height: 80,
          decoration: BoxDecoration(color: Colors.deepPurpleAccent, shape: BoxShape.circle),
          child: IconButton(icon: Icon(Icons.search), onPressed: (){}),
        ),
      )

    ],
  )

现在,当我从我的第二个 child 中删除 Align 小部件时,堆栈和它的 child 一样大。

最佳答案

您没有为其 widthFactorheightFactor 提供 Align 小部件值,根据 Align class documentation ,您提到的行为是预期的:

This widget will be as big as possible if its dimensions are constrained and widthFactor and heightFactor are null.

为了确认这一点,我将值 1.0 分配给 widthFactorheightFactor,然后它返回到预期大小(更大的小部件,即 FloatingActionButton) :

 Align(
        alignment: Alignment.bottomCenter,
        widthFactor: 1.0,
        heightFactor: 1.0,
        child: Container(
          width: 80,
          height: 80,
          decoration: BoxDecoration(color: Colors.deepPurpleAccent, shape: BoxShape.circle),
          child: IconButton(icon: Icon(Icons.search), onPressed: (){}),
        ),
      )

关于flutter - Align Widget inside Stack 占全屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56199162/

相关文章:

flutter - Flutter:使用带有http请求的Firebase实时数据库实现分页

flutter - 使用Null的Dart对变量安全

flutter - Dart 的广播流中的 forEach 会泄漏吗?

Flutter:项目在 'pod update' 之后无法编译

google-maps - 自定义图标方向 anchor Flutter Google map

flutter - 使用 flutter_local_notifications 插件时,待处理的通知在重启后会被取消

text - 如何在 Flutter 中更改整个主题的文本颜色?

list - Flutter Dart List - 如何检查列表是否包含对象

带有前台服务的音频播放器,适用于 iOS+ Android

amazon-web-services - 未处理的异常 : SocketException: Failed host lookup: (OS Error: No address associated with hostname, errno = 7)