簡體   English   中英

Flutter 焦點上的文本字段背景顏色

[英]Flutter textfield background color on focus

我有一個圓形的文本字段。 它運行良好,但是當用戶點擊它時,會出現灰色背景。 如何禁用該飛濺效果?

這是我的代碼和結果:

        new Container(
          margin: const EdgeInsets.only(left: 30.0, top: 60.0, right: 
         30.0),
          height: 40.0,
          decoration: new BoxDecoration(

          color: Colors.white,

            borderRadius: new BorderRadius.all(new Radius.circular(25.7))
          ),

          child: new Directionality(

              textDirection: TextDirection.ltr,
              child: new TextField(
                controller: null,
                autofocus: false,

                style:
                    new TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
                decoration: new InputDecoration(
                  filled: true,

                  fillColor: Colors.white,
                  hintText: 'Username',
                  contentPadding: const EdgeInsets.only(
                      left: 14.0, bottom: 8.0, top: 8.0),
                  focusedBorder: OutlineInputBorder(
                    borderSide: new BorderSide(color: Colors.white),
                    borderRadius: new BorderRadius.circular(25.7),
                  ),
                  enabledBorder: UnderlineInputBorder(
                    borderSide: new BorderSide(color: Colors.white),
                    borderRadius: new BorderRadius.circular(25.7),
                  ),
                ),
              ))),

在此處輸入圖像描述

看起來它是由文本字段上的飛濺效果引起的。 我找不到針對該特定小部件禁用它的方法,但您可以通過將TextField包裝在Theme小部件中並將splashColor設置為透明來使其透明:

Theme(
  data: Theme.of(context).copyWith(splashColor: Colors.transparent),
  child: TextField(
    autofocus: false,
    style: TextStyle(fontSize: 22.0, color: Color(0xFFbdc6cf)),
    decoration: InputDecoration(
      filled: true,
      fillColor: Colors.white,
      hintText: 'Username',
      contentPadding:
          const EdgeInsets.only(left: 14.0, bottom: 8.0, top: 8.0),
      focusedBorder: OutlineInputBorder(
        borderSide: BorderSide(color: Colors.white),
        borderRadius: BorderRadius.circular(25.7),
      ),
      enabledBorder: UnderlineInputBorder(
        borderSide: BorderSide(color: Colors.white),
        borderRadius: BorderRadius.circular(25.7),
      ),
    ),
  ),
);

為此,您應該將filled設置為true

TextField(decoration: InputDecoration( fillColor: Colors.red, filled: true)),

使用 BorderSide.none 作為:

border: OutlineInputBorder(
    borderRadius: BorderRadius.circular(10.0),
    borderSide: BorderSide.none,
),

“顫振文本字段背景顏色”

*在flutter中更改TextField的邊框顏色

TextFormField(
        decoration: InputDecoration(
          labelText: "Resevior Name",
          fillColor: Colors.white,
          focusedBorder:OutlineInputBorder(
            borderSide: const BorderSide(color: Colors.white, width: 2.0),
            borderRadius: BorderRadius.circular(25.0),
          ),
        ),
      )

文本字段形式顏色顫動

TextField(
  style: TextStyle(color: Colors.red),
  decoration: InputDecoration(fillColor: Colors.orange, filled: true),
)

Flutter TextFormField 背景色

TextFormField(
    decoration: InputDecoration(
        labelText: "Resevior Name",
        fillColor: Colors.white,
        filled: true, // dont forget this line
        ...
    )
    ...
)

Flutter 文本字段標簽顏色

labelStyle: TextStyle(
    color: Colors.white,
)

顏色文本字段文本顫動

TextField(
  style: TextStyle(color: Colors.white),
  ...
)

暫無
暫無

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

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