簡體   English   中英

如何更改 Flutter 上的默認 TextFormField 高度和字體顏色

[英]How to change TextFormField height and Font color from default on Flutter

我想更改 TextFormField 高度和字體顏色。

           TextFormField(
              decoration: const InputDecoration(
                  border: OutlineInputBorder(),
                  filled: true,
                  icon: Icon(Icons.person),
                  hintText: 'Nick Name',
                  labelText: 'Nick Name',
              ),
            ),

我怎么寫呢?

您可以使用contentPadding調整大小和樣式屬性以更改顏色和文本相關屬性。

 TextFormField(
        decoration: const InputDecoration(
            contentPadding: EdgeInsets.all(20), // change height
            border: OutlineInputBorder(),
            filled: true,
            icon: Icon(Icons.person),
            hintText: 'Nick Name',
            labelText: 'Nick Name',
            hintStyle:
                TextStyle(color: Colors.amber)), // change hint text color
        style: TextStyle(color: Colors.red), // change input text color
      ),

要增加TextFormField高度,您可以在InputDecoration中使用contentPadding屬性並將值賦給vertical參數,如下所示:

decoration: InputDecoration(
                  contentPadding: EdgeInsets.symmetric(vertical: 30),

要更改labelhint的字體顏色,您可以使用MaterialApp中的Theme來執行此操作,如下所示:

theme: ThemeData(
      inputDecorationTheme: InputDecorationTheme(
            labelStyle: TextStyle(color: Colors.black),
            hintStyle: TextStyle(color: Colors.black),

      )),

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM