Flutter textformfield - flutter

How can I have a new line property in the textfield widget? SO that the text entered when reaches a certain point, it shifts to a new line. Can anyone help me fix this?
Code :
body: Center(
child: Container(
height: 500,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 2,
),
borderRadius: BorderRadius.circular(10)),
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: TextFormField(
decoration: InputDecoration(
hintText: 'UserName',
hintStyle:
TextStyle(fontWeight: FontWeight.w400, fontSize: 24.0)),
),
),
),
)
Output:

From the Official Docs, The maxLines property can be set to null to remove the restriction on the number of lines. By default, it is one, meaning this is a single-line
text field. maxLines must not be zero.
You just have to add maxLines: null
body: Center(
child: Container(
height: 500,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 2,
),
borderRadius: BorderRadius.circular(10)),
child: Padding(
padding: const EdgeInsets.only(left: 16.0),
child: TextFormField(
maxLines: null,
decoration: InputDecoration(
hintText: 'UserName',
hintStyle:
TextStyle(fontWeight: FontWeight.w400, fontSize: 24.0)),
),
),
),
)

Related

How to change the position of the text in the textformfield?

This is the design I want:
This is my current design:
I am new to using flutter. I want to ask for an opinion on how to make text in the textformfield at what position according to the design I want. I try to use contentPadding: EdgeInsets.symmetric(vertical: 40), and height in textformfield style but still can't solve my problem. Please advise from stack overflow.
This is my code:
Container(
width: double.infinity,
margin: EdgeInsets.fromLTRB(10, 0, 10, 10),
padding: EdgeInsets.all(15),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'Important patient note',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 950,
child: TextFormField(
textAlign: TextAlign.start,
style: const TextStyle(color: Colors.black),
controller: importantNotes,
onSaved: (String? value) {
importantNotes.text = value!;
},
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(70.0),
border: OutlineInputBorder(),
hintText: 'Important patient note',
hintStyle: TextStyle(
color: Colors.black, fontSize: 16,),
),
),
)
],
))
Just remove contentPadding: EdgeInsets.all(70.0),
SizedBox(
width: 950,
child: TextFormField(
textAlign: TextAlign.start,
maxLines : 5, // add this
style: const TextStyle(color: Colors.black),
controller: importantNotes,
onSaved: (String? value) {
importantNotes.text = value!;
},
decoration: const InputDecoration(
contentPadding: EdgeInsets.all(70.0), // remove or set it to 0
border: OutlineInputBorder(),
hintText: 'Important patient note',
hintStyle: TextStyle(
color: Colors.black, fontSize: 16,),
),
)),
try this one
Widget textfield(
String hint, TextEditingController _controller, bool obsecurtext) {
return Container(
width: MediaQuery.of(context).size.width - 70,
height: 60,
child: TextFormField(
obscureText: obsecurtext,
controller: _controller,
decoration: InputDecoration(
labelStyle: TextStyle(fontSize: 15),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(21),
borderSide:
BorderSide(width: 1, color: Color.fromARGB(255, 226, 135, 230)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(21),
borderSide:
BorderSide(width: 1, color: Color.fromARGB(255, 231, 127, 127)),
),
hintText: hint,
),
),
);
}
usage textfield("Email", _email, false)

How to build a cupertino textfield

How can I achieve something like this in Flutter?
I am talking about the 2 textfield on grey. Are they a Cupertino Textfield?
You can use cupertinotextfield.borderless to meet your requirements. Here is an example:
Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
decoration: BoxDecoration(
color: Colors.grey[400],
borderRadius: BorderRadius.circular(10)),
padding: const EdgeInsets.all(10),
child: Column(
mainAxisSize: MainAxisSize.min,
children: const [
CupertinoTextField.borderless(
padding: EdgeInsets.only(left: 65, top: 10, right: 6, bottom: 10),
prefix: Text('Name'),
placeholder: 'Required',
),
Divider(
thickness: 1,
color: Colors.black,
),
CupertinoTextField.borderless(
padding: EdgeInsets.only(left: 15, top: 10, right: 6, bottom: 10),
prefix: Text('Card Number'),
),
],
),
),
)
Play around with the widgets parameters to customise it to your own needs.
Try below code
Using CupertinoTextField
Container(
padding: EdgeInsets.all(8),
height: 100,
width: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey.shade300,
),
child: Column(
children: [
CupertinoTextField(
placeholder: 'Required',
prefix: Text(
'Name',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
decoration: BoxDecoration(),
),
Divider(
thickness: 1,
color: Colors.grey,
),
CupertinoTextField(
prefix: Text(
'Card Number',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
decoration: BoxDecoration(),
),
],
),
),
Result Screen->
Using TextField
Container(
padding: EdgeInsets.all(8),
height: 135,
width: 300,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(20),
color: Colors.grey.shade300,
),
child: Column(
children: [
TextField(
decoration: new InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(
top: 15,
),
child: Text(
'Name',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: "Required",
),
),
Divider(
thickness: 1,
color: Colors.grey,
),
TextField(
decoration: new InputDecoration(
prefixIcon: Padding(
padding: EdgeInsets.only(
top: 15,
right: 10,
),
child: Text(
'Card Number',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
),
],
),
),
Result Screen->

flutter center text with suffix icon

SizedBox(
width: 150,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
suffixIcon: Icon(
Icons.keyboard_arrow_down_outlined,
color: kGreyColor,
),
hintStyle: TextStyle(fontSize: 20),
hintText: "Bugün"),
),
),
how can i make this design I did something but it didn't turn out well
eddit:Content padding coming theme but not looking exactly center
You can achieve this by using a Container and a Stack.
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(color: Colors.grey)),
child: Stack(
children: const [
Padding(
padding: EdgeInsets.symmetric(horizontal: 40, vertical: 5),
child: Text("Bugün"),
),
Positioned.fill(
child: Align(
alignment: Alignment.centerRight,
child: Icon(
Icons.keyboard_arrow_down_outlined,
),
),
)
],
),
)
You can check the code on this DartPad
/* Don't change your code just add this you will get your exact answer. */
SizedBox(
width: 150,
child: TextField(
textAlign: TextAlign.end,
decoration: InputDecoration(
suffixIcon: Icon(
Icons.keyboard_arrow_down_outlined,
color: Colors.grey,
),
hintStyle: TextStyle(fontSize: 20,),
hintText: "Bugün"),
),
),

How to style this kind of Text Field

I want to style this kind of TextField.
The main problem that I'm facing is to design the US$ part in leading the TextField. This is my code so far.
/// My Place Bid Text Field
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: "Place Bid",
labelStyle: TextStyle(fontSize: 24)),
),
),
],
),
),
Which gives me output
I know this question is not that complicated, but I'm still relatively new to flutter so your help would be much appreciated.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample"),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[500],
),
borderRadius: BorderRadius.all(Radius.circular(8))),
width: double.infinity,
height: 50,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
color: Colors.grey.shade300,
height: 50,
child: Align(
alignment: Alignment.center,
child: Text(
"RS \u20B9",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
)),
SizedBox(
width: 10,
),
Expanded(
child: Container(
height: 50,
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Bid",
labelStyle: TextStyle(fontSize: 24)),
)))
],
),
),
));
}
Output
You can use the prefixIcon to add a widget at the beginning of the textfield:
Container(
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: Container(
padding: const EdgeInsets.all(13),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
border: const OutlineInputBorder(),
labelText: 'Hint Text',
),
),
),
],
),
)
example:
https://dartpad.dev/a89aff20d67e2cb31da6a07ba7c17910
Based on your solution.
Notice the "IntrinsicHeight" widget. It makes all the children inside the child the same size (depending on the biggest one). The "Center" widget inside the prefix makes the Container go max height + center the text inside of it. Just make sure not to use IntrinsicHeight too much, since the docs state that it's a bit resource heavy.
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: InputBorder.none,
labelText: "Place Bid",
),
),
),
],
),
),
),
The second code is almost the same, except there's no label after typing the text inside the TextField.
Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
border: InputBorder.none,
hintText: "Place Bid",
),
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border:Border.all(color:Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft:Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: new OutlineInputBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
bottomRight:
Radius.circular(4),
),
),
isDense: true,
labelText: "Place Bid",
labelStyle:
TextStyle(fontSize:24)),
),
),
],
),
),

Flutter - How to make a custom input field with custom prefix design?

How to make a custom input field with custom prefix design?e like the image below
I tried a lot for it but I can't make the prefix part inside the input
Add dependency for country code picker
Row(
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 24),
width: MediaQuery.of(context).size.width - 127,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30),
bottomLeft: Radius.circular(30))),
margin: EdgeInsets.only(top: 16),
child: TextFormField(
controller: _phoneNumberController,
keyboardType: TextInputType.phone,
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Phone",
hintStyle: TextStyle(
color: CustomColors.LightGrey,
fontWeight: FontWeight.w100)))),
VerticalDivider(
width: 0.2,
color: Colors.grey,
),
Container(
margin: EdgeInsets.only(top: 16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topRight: Radius.circular(30),
bottomRight: Radius.circular(30))),
child: CountryCodePicker(
initialSelection: 'IN',
hideMainText: false,
showFlag: false,
),
),
],
),
You could use prefixIcon property of InputDecorator to display somethig.
TextField(
decoration: InputDecoration(
prefixIcon: SizedBox(
width: 50,
child: Center(
child: Text(
'+91',
style: TextStyle(color: Colors.black),
),
),
),
),
),
You could also use prefix property but the text will disappear if text field is not focused.
If you want to add line after the prefix you could replace SizedBox with Container instead. And use border property.
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(),
prefixIcon: Container(
width: 50,
margin: EdgeInsets.only(right: 10),
decoration: BoxDecoration(
border: Border(
right: BorderSide(
color: Color(0xFF272727),
width: 1,
),
),
),
child: Center(
child: Text(
'+91',
style: TextStyle(color: Colors.black),
),
),
),
),
),