Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: how to make a TextField with HintText but no Underline?

This is what I'm trying to make:

enter image description here

In the Flutter docs for Text Fields (https://flutter.io/text-input/) it says you can remove the underline by passing null to the decoration. However, that also gets rid of the hint text.

I do not want any underline whether the text field is focused or not.

UPDATE: updated accepted answer to reflect changes in Flutter SDK as of April 2020.

like image 677
TeabaggingSanta Avatar asked Mar 01 '18 00:03

TeabaggingSanta


People also ask

How do I hide the underline in a TextField in Flutter?

To remove TextField underline/border in Flutter, you can simply set the border property to InputBorder. none. This will remove the underline for all states such as Focused, Enabled, Error, Disabled.

How do you get rid of text lines in Flutter?

You can remove the double yellow lines by placing your Text widget inside a Material widget or a widget that contains Material itself like Scaffold, Card, Dialog, Drawer, etc. Note: Don't forget to import 'package:flutter/material. dart' at the top of your Dart file.

How do you add hint to TextField in Flutter?

By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.

How do I get rid of the padding in TextField Flutter?

As of flutter 1.17. 5 (and still the same in 2. X) to completely remove or manipulate the padding manually, first you must set isDense: true and then you can adjust the contentPadding as you wanted or apply padding on the parent widget instead. TextField has not an inputDecorationTheme attribute.


2 Answers

Do it like this:

TextField(   decoration: new InputDecoration.collapsed(     hintText: 'Username'   ), ), 

or if you need other stuff like icon, set the border with InputBorder.none

InputDecoration(     border: InputBorder.none,     hintText: 'Username',   ), ), 
like image 90
Made Baruna Avatar answered Sep 20 '22 15:09

Made Baruna


new flutter sdk since after integration of web and desktop support you need to specify individually like this

TextFormField(     cursorColor: Colors.black,     keyboardType: inputType,     decoration: new InputDecoration(         border: InputBorder.none,         focusedBorder: InputBorder.none,         enabledBorder: InputBorder.none,         errorBorder: InputBorder.none,         disabledBorder: InputBorder.none,         contentPadding:             EdgeInsets.only(left: 15, bottom: 11, top: 11, right: 15),         hintText: "Hint here"),   ) 
like image 20
sourav pandit Avatar answered Sep 22 '22 15:09

sourav pandit