How can I make rounded TextField in flutter?

前端 未结 5 600
予麋鹿
予麋鹿 2021-02-02 05:35

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 TextFie

相关标签:
5条回答
  • 2021-02-02 05:52

    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),
    ),
    
    0 讨论(0)
  • 2021-02-02 05:54

    You can add rounded corners to a TextField within the decoration parameter of the 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),
    )
    
    0 讨论(0)
  • 2021-02-02 05:54

    @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,
        ),
    ),
    
    0 讨论(0)
  • 2021-02-02 05:55

    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,
        ),
    ),
    
    0 讨论(0)
  • 2021-02-02 06:00

    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),
    
    ),
    
    0 讨论(0)
提交回复
热议问题