Flutter Stack布局,使用Positioned子组件无法铺满宽度的问题
2020-03-05 21:31 浏览(3109 更新于 2020-09-27 15:15

开发侧滑搜索菜单,Drawer 内容代码如下

ConstrainedBox(
  constraints: BoxConstraints.expand(),
  child: Stack(
    fit: StackFit.expand,
    children: <Widget>[
      ListView(
        children:[
          _buildHeader(),
          _buildTime(),
          MyWidgets.separator(height: 1,bgColor: StyleColors.bg_grey),
          _buildTag(),
          MyWidgets.separator(height: 1,bgColor: StyleColors.bg_grey),
          _buildTag(),
          MyWidgets.separator(height: 1,bgColor: StyleColors.bg_grey),
          _buildTag(),
          MyWidgets.separator(height: 1,bgColor: StyleColors.bg_grey),
          _buildTag(),
        ],
      ),
      Positioned(
        bottom: 0,
        child: _buildBtn(),
      ),
    ],
  ),
)

界面如下


_buildBtn 内容为 

Container(
  height: 50,
//  width: double.infinity,
  decoration: BoxDecoration(
    color: StyleColors.main_color
  ),
  child: Text('bottom'),
);

想bottom铺满底部宽带

但是设置 width: double.infinity, 报错:BoxConstraints forces an infinite width.

可以将 Positioned 替换为 Align

Align(child: _buildBtn(),alignment: Alignment.bottomCenter,)

Container 宽度设置为 width: double.infinity,

效果如下

评论(5)
发布评论
回复X
聊天室(0