如何在颤动中将文本字段内的文本与底部对齐?

时间:2021-07-16 12:39:32

标签: flutter dart

所以我希望 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 但它不起作用。

1 个答案:

答案 0 :(得分:1)

尝试添加 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
            ),
          ),
        ),
      ),
    );
  }
}