【发布时间】:2019-05-15 18:46:18
【问题描述】:
我目前在 Flutter 中创建基本的 3 行页面布局时遇到问题。
其中两行应具有固定高度,其余行应占用页面的其余高度。
合适的小部件结构是什么?我猜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
],
),
);
【问题讨论】:
-
你为什么到处使用
static? -
@AndreyTurkovsky 你是完全正确的。我尝试了很多,有时因为我在另一个小部件中使用它需要
static,但我在玩过之后从未删除它。我会修改它。
标签: dart flutter flutter-layout