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

Flutter:含TextField的可滚动Column无法将文本对齐到底部

解决方法

要实现可滚动表单同时让底部文本固定在页面底部,你可以通过将SingleChildScrollView嵌套在Expanded中,外层用Column包裹,这样既保证表单内容可滚动,又能让底部文本始终对齐页面底部。

具体修改逻辑:

  1. 外层使用Column拆分布局:上方为可滚动的表单区域,下方为固定的底部文本
  2. 用Expanded包裹SingleChildScrollView,让它占据除底部文本外的所有可用空间
  3. 移除原有的Spacer,Expanded已替代其填充剩余空间的作用

修改后的完整代码:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: Padding(
          padding: const EdgeInsets.all(20.0),
          child: Column(
            children: [
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      const SizedBox(height: 100),
                      TextField(decoration: InputDecoration(hintText: 'Field 1')),
                      const SizedBox(height: 10),
                      TextField(decoration: InputDecoration(hintText: 'Field 2')),
                      const SizedBox(height: 10),
                      TextField(decoration: InputDecoration(hintText: 'Field 3')),
                      const SizedBox(height: 10),
                      TextField(decoration: InputDecoration(hintText: 'Field 4')),
                      const SizedBox(height: 10),
                      TextField(decoration: InputDecoration(hintText: 'Field 5')),
                      const SizedBox(height: 10),
                      ElevatedButton(
                        onPressed: () {},
                        child: const Text('SUBMIT'),
                      ),
                    ],
                  ),
                ),
              ),
              const Text('Don\'t have an account?'),
            ],
          ),
        ),
      ),
    );
  }
}

额外补充:如果需要底部文本完全固定在屏幕底部、不随键盘上移,可以直接将文本放在Scaffold的bottomNavigationBar属性中,无需嵌套复杂布局。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 18:13:28