如何在颤动中创建圆形TextField?

问题描述 投票:9回答:3

iOS的Material Design看起来不太好,尤其是TextField。那么有没有办法创建自己的?或者是否可以向TextField添加一些样式以使其看起来圆润?

flutter
3个回答
20
投票

您可以在TextField的装饰参数中为TextField添加圆角

new TextField(
  decoration: new InputDecoration(
      border: new OutlineInputBorder(
        borderRadius: const BorderRadius.all(
          const Radius.circular(10.0),
        ),
      ),
      filled: true,
      hintStyle: new TextStyle(color: Colors.grey[800]),
      hintText: "Type in your text",
      fillColor: Colors.white70),
)

9
投票

你可以在Container的帮助下获得所需的输出看看..

new Container(
  child: new Text (
      "Text with rounded edges.",
      style: new TextStyle(
          color: Colors.blue[500],
          fontWeight: FontWeight.w900
      )
  ),
  decoration: new BoxDecoration (
      borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
      color: Colors.black
  ),
  padding: new EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 16.0),
),

6
投票

@Rockvole答案是正确的但是如果你不喜欢TextField周围的默认边框,你可以通过覆盖borderSideOutlineInputBorder属性来实现它,如下所示:

TextField(
    textAlign: TextAlign.center,
    controller: searchCtrl,
    keyboardType: TextInputType.text,
    decoration: InputDecoration(
        hintText: 'Enter a product name eg. pension',
        hintStyle: TextStyle(fontSize: 16),
        border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(8),
            borderSide: BorderSide(
                width: 0, 
                style: BorderStyle.none,
            ),
        ),
        filled: true,
        contentPadding: EdgeInsets.all(16),
        fillColor: colorSearchBg,
    ),
),
© www.soinside.com 2019 - 2024. All rights reserved.