how to remove this that i mark in screenshot - flutter

I want to remove the 0/10 mark below the telephone field (see screenshot)
My code:
Container(
width: 334,
height: 70,
child: Padding(
padding: const EdgeInsets.only(left: 1, right: 30),
child: IntlPhoneField(
decoration: InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
initialCountryCode: 'IN',
onChanged: (phone) {
print(phone.completeNumber);
},
),
),
),

Assuming you're using a normal Flutter TextFormField or equivalent,
counterText: '',

Assuming you have used the TextFormField widget. You can hide counter text by making it an empty value.
Example code:
TextFormField(
decoration: const InputDecoration(
counterText: '',
),
);

It seems you are using intl_phone_field package. The (not so good) documentation contains a disableLengthCheck property. If you set that to true the 0/10 is gone. like this:
IntlPhoneField(
disableLengthCheck: true,
decoration: const InputDecoration(
labelText: 'Phone Number',
border: OutlineInputBorder(
borderSide: BorderSide(),
),
),
initialCountryCode: 'IN',
onChanged: (phone) {
print(phone.completeNumber);
},
),

Related

How to have the label and input text within the same container

I am trying to recreate this textfield design
As you can see the label/hint text is centered when it is not focused and once in focus, the input text and the label/hint text are also centered within the border.
What I tried to recreate this design is first to create the textfield, remove all the borders, and wrap it with a container, and finally play with content padding but I either get text input text off-centered or I get the label/hint text off-centered.
Images below show how the label/hint is off-centered
BUT when in focus
Here sample code
Container(
height: 60,
padding: EdgeInsetsDirectional.only(
start: width * 0.038,
end: width * 0.038,
),
decoration: BoxDecoration(
border: Border.all(
color: state.hasError
? Constant.errorColor
: Constant.greyColor,
width: 1),
borderRadius: const BorderRadius.all(Radius.circular(10)),
),
child: TextField(
inputFormatters: inputFormatter,
controller: controller,
onSubmitted: onSubmitted,
onChanged: state.didChange,
focusNode: focusNode,
textInputAction: textInputAction,
keyboardType: keyboard,
obscureText: obscure,
decoration: InputDecoration(
labelText: label,
alignLabelWithHint: true,
labelStyle: Constant.hintText.copyWith(
color: state.hasError
? Constant.errorColor
: Constant.greyColor,
fontSize: 14,
),
hintText: hint,
hintStyle: Constant.hintText.copyWith(fontSize: 14),
contentPadding: null,
// contentPadding: EdgeInsetsDirectional.only(
// bottom: 7.5,
// ),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
),
),
You could create a custom text box:
Container(
Column(
children: [
Text("insert label text", textAlign: TextAlign.start)
TextField(
...
// no labelText
// remove decorations
)
]
)
);

Horizontal scroll in TextFormField flutter on text input

I have an email input text field when I write more text than the width of this input, the rest of the text is not visible. Is there a way to have a horizontal scroll as I input into this text form field?
The following image describes the behavior I want.
Edit: My Code
Container(
width: 270,
height: 42,
child: new TextFormField(
validator: (val) => val.isEmpty ? 'Enter an email' : null,
decoration: new InputDecoration(
icon: Icon(
Icons.email_outlined,
),
labelText: 'Email',
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
),
keyboardType: TextInputType.emailAddress,
onChanged: (val) {
setState(() => email = val);
},
),
),
This is what happens when I type beyond the width of the TextFormField
There are two ways to go about this:
You can add the isDense property to your TextFormField, in which case your code will look like this:
Container(
width: 270,
height: 42,
child: TextFormField(
textAlignVertical: TextAlignVertical.center,
validator: (val) => val!.isEmpty ? 'Enter an email' : null,
decoration: new InputDecoration(
isDense: true,
icon: Icon(
Icons.email_outlined,
),
labelText: 'Email',
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
),
keyboardType: TextInputType.emailAddress,
onChanged: (val) {
setState(() => email = val);
},
),
),
This fixes the problem to an extent, however if font that extends lower(like commas, semicolons etc. still get clipped off). The next method fixes this:
Use the contentPadding property, since if you check the source code, all isDense does is modify the contentPadding property's value. This is some of the actual code behind isDense:
if (decoration!.filled == true) { // filled == null same as filled == false
contentPadding = decorationContentPadding ?? (decorationIsDense
? const EdgeInsets.fromLTRB(12.0, 8.0, 12.0, 8.0)
: const EdgeInsets.fromLTRB(12.0, 12.0, 12.0, 12.0));
} else {
// Not left or right padding for underline borders that aren't filled
// is a small concession to backwards compatibility. This eliminates
// the most noticeable layout change introduced by #13734.
contentPadding = decorationContentPadding ?? (decorationIsDense
? const EdgeInsets.fromLTRB(0.0, 8.0, 0.0, 8.0)
: const EdgeInsets.fromLTRB(0.0, 12.0, 0.0, 12.0));
}
As you can see, all Flutter does behind the scenes is assign hardcoded values to your arguments based on the parameters you've passed. In your case, the best configuration seems to be:
Container(
width: 270,
height: 42,
child: TextFormField(
textAlignVertical: TextAlignVertical.center,
validator: (val) => val!.isEmpty ? 'Enter an email' : null,
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(12.0, 8.0, 12.0, 8.0),
icon: Icon(
Icons.email_outlined,
),
labelText: 'Email',
border: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(25.0),
borderSide: new BorderSide(),
),
),
keyboardType: TextInputType.emailAddress,
onChanged: (val) {
setState(() => email = val);
},
),
),
The above code fixes your issue, but might create more problems if your font height changes.

How to show label and error message inside the boundry of textformfield in flutter?

I'm using a text and textformfield inside a container to get userName. I need to do the text field validation and get the error message and red color boundary box as shown in expected outcome image. I have included the current output also.
I tried a few other ways also. But nothing worked.
Current output
Expected Output
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(10)),
shape: BoxShape.rectangle,
color: Color(0xFFF4F9FE),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(10, 3, 0, 0),
child: Text("Full Name",
style: TextStyle(color: Color(0xFFA8C3EC)),
),
),
Padding(
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
child: TextFormField(
decoration: new InputDecoration(
hintText: "Enter Your Full Name",
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide(color: Colors.red),
),
disabledBorder: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 1.0),
),
validator: _validateName,
),
),
],
),
);
String _validateName(String value) {
return "Required field cannot be empty";
}
Flutter TextFormField handles error text itself, so we don't require to use variable _validate. It will check at runtime whether you satisfied the condition or not.
final confirmPassword = TextFormField(
controller: widget.confirmPasswordController,
obscureText: true,
decoration: InputDecoration(
prefixIcon: Icon(Icons.lock_open, color: Colors.grey),
hintText: 'Confirm Password',
errorText: validatePassword(widget.confirmPasswordController.text),
contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
),
);
String validatePassword(String value) {
if (!(value.length > 5) && value.isNotEmpty) {
return "Password should contain more than 5 characters";
}
return null;
}
Note: User must add at least one character to get this error message.More info

Flutter TextFormField pointer overlapping the text

When using TextFormField in Flutter and having the form prefilled with text, when I tap somewhere on it in order to start editing the text, I get the little rain drop pointer right over the text:
I expect it to appear a little bit below the form. Something like this:
Here is the code:
Container(
height: 40.0,
child: TextFormField(
style: TextStyle(
fontSize: 17,
),
controller: serverAddressController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: new BorderRadius.circular(10.0),
),
),
onChanged: (value) {
serverAddress = value;
changesSaved = false;
},
textInputAction: TextInputAction.next,
onFieldSubmitted: (_) {
FocusScope.of(context)
.requestFocus(daysBackFocusNode);
},
),
),
How do I do it?
you've set Container height to low but didn't reduce content paddings
just add contentPadding property
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 16, right: 16),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(16.0),
),
),

Flutter when text is bigger than input, text disappears

The problem is that when the text is bigger than the input size, the text just disappears and I don't know why.
Here is my code:
TextField(
focusNode: _focusEmailNode,
controller: _emailController,
decoration: InputDecoration(
border: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: txtEmailBoder),
),
hintText: 'Email',
),
After searching through many sites, I finally got a solution. You can solve this problem by giving decoration and maxlines in the textfield. Give isDense as true in InputDecoration
Example:
Container(
height: 20,
width: 100,
child: TextFormField(
maxLines: 1,
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.fromLTRB(5.0, 1.0, 5.0, 1.0),
),
onChanged: (value) {
print(value);
},
),
);
if you don't give content padding then your text will be cut from the middle, like below.
Be careful when you give padding, you should give padding as needed by your textfield's height. If you give wrong padding then also your text will be invisible.
You need to add
contentPadding: EdgeInsets.zero
to your InputDecoration
Give text field an input formatter with desired length of the text like this:
inputFormatters: [
LengthLimitingTextInputFormatter(50),
],
And then have content padding set to like this :
contentPadding: EdgeInsets.fromLTRB(5.0 , 20.0 , 5.0 , 20.0),
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.fromLTRB(5.0, 50, 5.0, 10.0),
alignment: Alignment.center,
child: TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.blueAccent),
),
hintText: 'Email',
),
)));
}
To Prevent this disappearing use decoration as InputDecoration.collapsed(hintText: "Search Customer")
Full Code is TextField(decoration : InputDecoration.collapsed(hintText: "Search Customer"), textCapitalization: TextCapitalization.sentences)