You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter实现Card居中、Button置于屏幕底部的布局方案咨询

Flutter布局解决方案:Card居中+Button居底

下面给你两种可行的实现方案,直接替换现有布局即可:

方案一:Column + Expanded + Center

利用Expanded占据屏幕除按钮外的所有剩余空间,再用Center让Card在该区域居中,按钮自然落在屏幕底部:

Scaffold(
  body: Column(
    children: [
      Expanded(
        child: Center(
          child: Card(
            child: SizedBox(
              width: 200,
              height: 200,
              child: Center(child: Text('居中Card')),
            ),
          ),
        ),
      ),
      Padding(
        padding: const EdgeInsets.all(16.0),
        child: ElevatedButton(
          onPressed: () {},
          child: Text('底部按钮'),
        ),
      ),
    ],
  ),
)

方案二:Stack + Positioned

用Stack实现层叠布局,Center包裹Card实现居中,Positioned固定按钮在底部:

Scaffold(
  body: Stack(
    children: [
      Center(
        child: Card(
          child: SizedBox(
            width: 200,
            height: 200,
            child: Center(child: Text('居中Card')),
          ),
        ),
      ),
      Positioned(
        bottom: 16,
        left: 16,
        right: 16,
        child: ElevatedButton(
          onPressed: () {},
          child: Text('底部按钮'),
        ),
      ),
    ],
  ),
)

这两种方案都能精准实现你的需求,方案一更贴合线性布局的逻辑,方案二更灵活适合复杂层叠场景。

内容的提问来源于stack exchange,提问作者Manish Paul

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 01:17:02