Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter: Cupertino TextField with hintText

I'd like to add hint text to CupertinoTextField without importing the material theme. Up to this point I tried mixing CupertinoTextField with InputDecoration like so:

CupertinoTextField(
   decoration: InputDecoration.collapsed(
       hintText: 'Enter you email'
   )
)

which results in the following error:

The argument type 'InputDecoration' can't be assigned to the parameter type 'BoxDecoration'

enter image description here

like image 293
kosiara - Bartosz Kosarzycki Avatar asked Mar 11 '19 07:03

kosiara - Bartosz Kosarzycki


People also ask

How do you style hintText in Flutter?

Here is the step by step instructions: Step 1: Locate the file where you have placed the TextField widget. Step 2: Inside the TextField widget, add the decoration parameter and assign the InputDecoration widget. Step 3: Inside the InputDecoration widget, add the hintStyle parameter and assign the TextStyle widget.

How do you get rid of the bottom line of a TextField in Flutter?

Steps to Remove TextField Underline/Border 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 decorate a 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.


2 Answers

I think you can achieve what you want with the placeholder property of CupertinoTextField.

Example:

CupertinoTextField(
   placeholder: "Enter Email",
)
like image 189
thedarthcoder Avatar answered Nov 15 '22 10:11

thedarthcoder


In the CupertinoTextField it's called placeholder not hint

you cant add like that

CupertinoTextField(
   placeholder: "Your placeholder here",
)

and for styling the placeholder i think you can't at the moment because its static and it's not customizable on iOS either.

like image 30
Mohamed hassan kadri Avatar answered Nov 15 '22 10:11

Mohamed hassan kadri