flutter - 使容器小部件垂直填充父级

标签 flutter

TL;DR 需要容器填充垂直空间,以便它可以充当 ontap 监听器。尝试了大多数解决方案,但似乎没有任何效果。

所以我想做的是让我的容器填满垂直空间,同时仍然具有固定的宽度。 Two first is what I have and third is what I want .这个想法是通过手势 ontap 监听器使容器透明。如果有人对不同的解决方案有更好的想法,请随时提出建议。

    Widget build(BuildContext context) {
    return new GestureDetector(
      onHorizontalDragUpdate: _move,
      onHorizontalDragEnd: _handleDragEnd,
      child: new Stack(
        children: <Widget>[
          new Positioned.fill(           
            child: new Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                new Container(
                  child: new IconButton(                          
                    padding: new EdgeInsets.only(top: 16.0, bottom: 16.0, left: 24.0, right: 24.0),
                    icon: new Icon(Icons.warning),
                    color: Colors.black12,
                    onPressed: () {},
                  )
                ),
              ],
            ),
          ),
          new SlideTransition(
            position: new Tween<Offset>(
              begin:  Offset(0.0, 0.0),
              end: const Offset(-0.6, 0.0),
            ).animate(_animation),
            child: new Card(
              child: new Row(
                children: <Widget>[
                  new Container(
                    width: 20.0,
                    height: 20.0,
                    color: Colors.amber,
                  ),
                  new Expanded(
                    child: new Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        
                        _getListTile(),
                        _ifStoplineIsToBeShown()
                      ],
                    ),
                  )
                ],
              )
            ),
          ),
        ],
      )
    );
  }

考虑到我尝试了很多不同的东西但似乎没有任何效果,我很确定我错过了一些东西。

我还上传了一张带有调试画的图片here .

PS。我知道我已将高度设置为固定值,但这是显示容器的唯一方法。

最佳答案

诀窍是结合 IntrinsicHeight 小部件和 RowcrossAxisAlignment: CrossAxisAlignment.stretch

这会强制 Row 的子级垂直扩展,但 Row 将占用尽可能少的垂直空间。

Card(
  child: IntrinsicHeight(
    child: Row(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        Container(
          width: 20.0,
          color: Colors.amber,
        ),
        // Expanded(...)
      ],
    ),
  )
)

关于flutter - 使容器小部件垂直填充父级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51155208/

相关文章:

android - 如何在 flutter 默认日期选择器中删除时间戳或仅从日期选择器获取日期?

flutter - 意外字符(在字符2处)

firebase - 使用带有双变量的Flutter和带数字字段类型混淆的Firestore

php - Flutter&Redis客户

flutter - '_route == ModalRoute.of(context)' : is not true

flutter - 将 flutter PageView 对齐到屏幕左侧

flutter - 创建一个 Flutter TextFormField,其中两个角为圆角,两个角为直切角

dialog - 是否可以禁用对话框上的阴影/覆盖?

android - 迁移到AndroidX后,已经将compileSdkVersion更新为28,但是仍然收到关于fontVariationSettings和ttcIndex的gradle错误

flutter - 我如何从外部小部件访问内部小部件的动画 Controller (或状态)?