dart - 如何创建具有一个动态高度行的 3 行 Flutter 布局

标签 dart flutter flutter-layout

我目前在 Flutter 中创建基本的 3 行页面布局时遇到问题。

其中两行应具有固定高度,其余行应占据页面的其余高度。

合适的 Widget 结构是什么?我想 Expanded 应该是其中的一部分?

伪 XAML

<RowDefinitions>
    <RowDefinition Height="50" />
    <RowDefinition Height="*" />
    <RowDefinition Height="75" />
</RowDefinition>

线框

Wireframe

当前状态

  // Gets the fixed top column.
  static Row _topBackgroundColumn = new Row(
    children: <Widget>[
      Padding(
        padding: EdgeInsets.all(20),
        child: Image(
            image: AssetImage("assets/animation-bird-1.png"),
            height: 50,
            alignment: AlignmentDirectional.topStart,
        )
      )
    ],
  );

  static Container _contentContainer = new Container(
    alignment: Alignment.center,
    child: Center(
      child: Text("bla")
    ),
  );

  // Gets the fixed, image-heavy bottom column.
  static Container _bottomBackgroundColumn = new Container(
    child:
      Image(
        image: AssetImage("assets/background-bottom.png"),
        repeat: ImageRepeat.repeatX,
        height: 50,
        alignment: Alignment.bottomCenter,
      )
  );
  static Container _pageContainer = new Container(
    child: Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      verticalDirection: VerticalDirection.down,
      children: <Widget>[
        _topBackgroundColumn, // Container with an image
        _contentContainer, // Container with a label
        _bottomBackgroundColumn, // Container with an image
      ],
    ),
  );

enter image description here

最佳答案

 Column(
       crossAxisAlignment: CrossAxisAlignment.stretch,
       verticalDirection: VerticalDirection.down,
       children: <Widget>[
         _topBackgroundColumn, // Container with an image
         Expanded(child: _contentContainer), // Container with a label
         _bottomBackgroundColumn, // Container with an image
       ],
     )

关于dart - 如何创建具有一个动态高度行的 3 行 Flutter 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53780700/

相关文章:

flutter - flutter :sliverAppBar棍子图标底部

dart - 如何在 Angular.Dart 中通过 bool 属性过滤 ng-repeat?

Flutter - 如何在 Dart 中使用 HTTP 发送 POST 请求?

flutter - 在flutter中我们如何使用audio_service来获取动态数据

flutter - 如何在 flutter 中添加文本和轮播图片?

list - 如何处理 ListTile flutter 中的右溢出

flutter - 抖动重建导致数据更改

flutter - 如何使用全局 Key 从 Flutter 中的另一个小部件更新小部件状态?

flutter - 文本对齐底部将文本保持在屏幕顶部

android - 在 Flutter ListView 中加载更多选项