dart - 如何使用一个动态高度行创建 3 行 Flutter 布局
问题描述
我目前在 Flutter 中创建基本的 3 行页面布局时遇到问题。
其中两行应具有固定高度,其余行应占用页面的其余高度。
合适的 Widget 结构是什么?我想那个Expanded
应该是它的一部分?
伪 XAML
<RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="*" />
<RowDefinition Height="75" />
</RowDefinition>
线框
当前状态
// 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
],
),
);
解决方案
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
],
)
推荐阅读
- python - 使用 cloudcraper 模块创建 .exe (pyinstaller) 时出错
- javascript - 让我最后一次点击的按钮存储在本地存储中
- nginx - 使入口可用
/ 在 Kubernetes 集群中 - flutter - 如何在 Flutter 中使用可滑动标签
- javascript - React延迟后的最佳路由方式?
- powershell - 批处理文件中的错误处理 powershell 命令
- laravel - 如何从数据透视表中获取“价值”字段(产品到“价值”)?-Laravel
- oracle - 如何在oracle中从空间中提取单词?
- firebase - 导航栏颤动
- spring-boot - Spring Boot ClassNotFoundException org.springframework.core.metrics.ApplicationStartup