首页 > 解决方案 > 如何在颤动中将文本字段内的文本与底部对齐?

问题描述

所以我想把里面的文字放在TextField最底部。

import 'package:flutter/material.dart';

void main() => runApp(const Home());

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: TextField(
            textAlignVertical: TextAlignVertical(y: -0.0),
            decoration: InputDecoration(filled: true)
          ),
        ),
      ),
    );
  }
}

我尝试使用textAlignVertical但它不起作用。

标签: flutterdart

解决方案


尝试添加contentPadding

import 'package:flutter/material.dart';

void main() => runApp(const Home());

class Home extends StatelessWidget {
  const Home({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: TextField(
            textAlignVertical: TextAlignVertical(y: -0.0),
            decoration: InputDecoration(
              filled: true,
              contentPadding: EdgeInsets.only(bottom: 0.0), //here
            ),
          ),
        ),
      ),
    );
  }
}


推荐阅读