简体   繁体   中英

How can I make rounded TextField in flutter?

Material Design for iOS doesn't look good, especially the TextField . So is there any way to create your own ? Or Is ther any way to add some styling to TextField so it will look rounded ?

You can add rounded corners to a TextField within the decoration parameter of it

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

@Rockvole answer is correct but just in case u don't like the default border around the TextField , you can achieve it by overriding the borderSide attribute of the OutlineInputBorder like this:

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,
    ),
),

You can get desired output with the help of Container Have a look..

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),
),

I've collected this solution from several methods and solutions over the internet, it works very well with me, so it could help someone out there: This solution will control the width and height of the TextField , and other properties

Container(
    child: Theme(
      data: Theme.of(context).copyWith(splashColor: Colors.transparent),
      child: TextField(
        autofocus: false,
        style: TextStyle(fontSize: 15.0, color: Color(0xFFbdc6cf)),
        decoration: InputDecoration(
          filled: true,
          fillColor: Colors.white,
          hintText: 'Search',
          contentPadding:
          const EdgeInsets.only(left: 14.0, bottom: 12.0, top: 0.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),
          ),
        ),
      ),
    ),

    decoration: new BoxDecoration (
      borderRadius: new BorderRadius.all(new Radius.circular(30.0)),
      color: Colors.white   ),   width: 250,   height: 50,   margin: new EdgeInsets.fromLTRB(20, 20, 20, 210),   padding: new EdgeInsets.fromLTRB(8, 8, 8, 8),

),

You can try this code bellow:

      decoration:  InputDecoration(
         border: OutlineInputBorder(
             borderRadius: const BorderRadius.all(
                const Radius.circular(10.0), 
             ),
             borderSide: BorderSide(
              width: 0, 
              style: BorderStyle.none,
              ),
             ),
           )

You could approach the purpose in a few different ways:

First Approach:

Container(
      child: new Text (
          "Some Text",
          style: TextStyle(
              color: Colors.black
          )
      ),
      decoration: BoxDecoration (
          borderRadius: BorderRadius.all( Radius.circular(15)),
          color: Colors.white
      ),
      padding: EdgeInsets.all(16.0),
    ),

Second Approach:

 TextField(
      decoration: InputDecoration(
          border: OutlineInputBorder(
            borderRadius: const BorderRadius.all(
              Radius.circular(15.0),
            ),
          ),
          filled: true,
          hintStyle: new TextStyle(color: Colors.grey[600]),
          hintText: "Hint text",
          fillColor: Colors.white),
    )

Third Approach:

TextField(
    textAlign: TextAlign.center,
    controller: someTextXontroller,
    keyboardType: TextInputType.text,
    decoration: InputDecoration(
        hintText: 'Hint Text',
        border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(12),
            borderSide: BorderSide(
                width: 0, 
                style: BorderStyle.none,
            ),
        ),
        filled: true,
        contentPadding: EdgeInsets.all(16),
        fillColor: Colors.blue,
    ),
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM