How can I set the height of my input field? - flutter

I am trying to make some input field but I can't seem the get the height right. The height of the top one is good but the text is offsetted. I tried to change the height of the textstyle but it did not work. I tried to change the container height but it offsets the text. I tried to change the text height but it doesn't work. What can I do?
Container
(
width: 200,
height: 40,
child: TextFormField
(
keyboardType: TextInputType.phone,
style: Theme.of(context).textTheme.body1,
decoration: InputDecoration
(
hintText: 'Enter your name',
hintStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
)
),
validator: (value) {
return value.isEmpty ? 'Please enter your name' : null;
},
),
),
SizedBox(height: 10,),
Container
(
width: 200,
child: TextFormField(
keyboardType: TextInputType.phone,
style: Theme.of(context).textTheme.body1,
decoration: InputDecoration(
hintText: 'Enter your phone number',
hintStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
)
),
validator: (value) {
return value.isEmpty ? 'Please enter your phone number' : null;
},
),
),

The offset appear because you set the height of container smaller minimum height of TextField. You can fix it by increasing the height or reducing contentPadding. Like this
Container
(
alignment: Alignment.bottomRight,
width: 200,
height: 30,
child: TextFormField
(
keyboardType: TextInputType.phone,
style: Theme.of(context).textTheme.body1,
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration
(
contentPadding: EdgeInsets.all(5),
hintText: 'Enter your name',
hintStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder
(
gapPadding: 0.0,
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder
(
gapPadding: 0.0,
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
)
),
validator: (value) {
return value.isEmpty ? 'Please enter your name' : null;
},
),
),
SizedBox(height: 10,),
Container
(
width: 200,
child: TextFormField(
keyboardType: TextInputType.phone,
style: Theme.of(context).textTheme.body1,
decoration: InputDecoration(
hintText: 'Enter your phone number',
contentPadding: EdgeInsets.all(5),
hintStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
)
),
validator: (value) {
return value.isEmpty ? 'Please enter your phone number' : null;
},
),
),

Please try this...
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Container(
margin: EdgeInsets.all(10),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Container(
child: TextFormField(
keyboardType: TextInputType.phone,
style: Theme.of(context).textTheme.body1,
decoration: InputDecoration(
hintText: 'Enter your name',
hintStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2.0,
),
)),
validator: (value) {
return value.isEmpty ? 'Please enter your name' : null;
},
),
),
SizedBox(
height: 10,
),
Container(
child: TextFormField(
keyboardType: TextInputType.phone,
style: Theme.of(context).textTheme.body1,
decoration: InputDecoration(
hintText: 'Enter your phone number',
hintStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
),
validator: (value) {
return value.isEmpty
? 'Please enter your phone number'
: null;
},
),
),
],
),
),
),
);

Bro wrap with SizeBox like this :😎
SizedBox(
height: 45,
child: TextField(
enabled: enabled,
textCapitalization: textCapitalization,
onEditingComplete: onEditingComplete,
obscureText: obscure,
controller: controller,
keyboardType: keyboardType,
style: AppTheme.normalTextStyle(),
decoration: InputDecoration(
contentPadding: textFieldPadding(),
prefixIcon: perfixIcon,
hintText: hint,
fillColor: Colors.white,
hintStyle: AppTheme.normalTextStyle(),
border: OutlineInputBorder(
borderSide: BorderSide(width: 0.0, color: HexColor("#F1F1F1")),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: HexColor("#F1F1F1")),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: HexColor("#F1F1F1")),
),
),
inputFormatters: [LengthLimitingTextInputFormatter(maxLength)],
onTap: onTap,
onSubmitted: onSubmit,
),
);

Related

how to align items inside textformfields?

How do I properly align the prefix icon, the hintText, the actual value that the user has typed in and the suffix icon? I am using textformfield for this one.
Widget yourNameWidget(yourNameCtrlr) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
child: TextFormField(
style: const TextStyle(fontFamily: 'Poppins', fontSize: 12),
controller: yourNameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(18),
isDense: true,
prefixIcon: const Icon(Icons.person),
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Color(0xFFCECECE)),
borderRadius: BorderRadius.circular(12),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Color(0xFFCECECE)),
),
// this does not align with the prefix and the hint text
suffix: GestureDetector(
onTap: () {
yourNameCtrlr.clear();
},
child: const Icon(
Icons.clear,
size: 16,
),
),
hintText: 'Your Name',
fillColor: const Color(0xFFFEFEFE),
filled: true,
),
validator: (value) {
if (value!.isEmpty || !RegExp(r'^[a-z A-Z]+$').hasMatch(value)) {
return "Please enter a valid name.";
} else {
return null;
}
},
onChanged: (value) {},
),
);
}
I want the three of it (prefix,hint text, suffix) should be aligned.
Here is the image for the preview of the textformfield
https://prnt.sc/BxYxnZx1G5od
I was used this type of textformfield please see the reference below:
TextFormField(
controller: textEditingController,
cursorColor: AppTheme.secondaryColor,
autofocus: true,
onChanged: (txt) {
},
style: const TextStyle(
fontSize: 16.0, color:
Color.fromARGB(255,4,4,4)),
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: AppTheme.secondaryColor_30,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: AppTheme.secondaryColor_30,
),
),
hintText:
StringConstants.searchForAGroupOrFriend,
hintStyle: Theme.of(context)
.textTheme
.caption!
.copyWith(color: AppTheme.grey2),
fillColor: AppTheme.secondaryColor_10,
contentPadding: const EdgeInsets.only(top: 10),
filled: true,
prefixIcon: GestureDetector(
onTap: () {
},
child: Image.asset(
Assets.icBackRound,
scale: 3.5,
color: AppTheme.backDarkGrey,
),
),
suffixIcon: GestureDetector(
child: Image.asset(
Assets.searchIcon,
color: AppTheme.secondaryColor,
scale: 3.5,
),
onTap: () {
},
),
),
),

The error message keeps resizing my textform field

I have wrapped a container and a sizedbox around the textform field to fit the error message in the container but its keeps resizing the widget.
Container(
decoration: BoxDecoration(
color: Color(0xffFAFAFA),
borderRadius: BorderRadius.circular(10.0),
),
height: 73,
width: 396,
child: Center(
child: TextFormField(
keyboardType: TextInputType.number,
onSaved: (Value) => print(phonenumber),
decoration: InputDecoration(
contentPadding: EdgeInsets.fromLTRB(10.0, 50.0, 0.0, 00.0),
isDense: true,
hintStyle: TextStyle(
fontFamily: "Proxima Nova",
fontWeight: FontWeight.w300,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
borderSide: BorderSide(
//color: Colors.amber,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
borderSide: BorderSide(width: 1, color: Colors.transparent),
),
focusedBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Colors.transparent),
),
// labelText: '',
),
inputFormatters: [
FilteringTextInputFormatter.deny(
RegExp(
r'^\s*(?:\+?(\d{1,3}))?[-. (]*(\d{3})[-. )]*(\d{3})[-. ]*(\d{5})(?: *x(\d+))?\s*$'),
)
],
controller: phonenumber,
validator: (value) {
if (value != null && value.isEmpty) {
return 'Kindly register with another number or Log In';
} else
return null;
},
),
),
),
i wrapped a container around the textformfield and a sizedbox around the textformfield but,the error message keeps resizing the container.
Please remove container height , this is causing shrink.

How could show an error message from a textformfield's validator (which is inside Container)?

I have the following issue.
I have a TextFormField where the user has to put some data (for example his email).
I am using a validator , but when the error raises from the TextFormField's validator, the error message and my TextFormField's values are not show properly.
Here is the code:
Container(
height: 60,
margin: EdgeInsets.only(right: 10, left: 10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
border: Border.all(
color: const Color(0xFF59C48C),
width: 2.0,
style: BorderStyle.solid),
),
child: Container(
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Center(
child: Container(
child: Image.asset("images/email.png",
width: 30, height: 30))),
const SizedBox(
width: 10,
),
Expanded(
child: Center(
child: TextFormField(
validator: (mail) =>
bloc.mailValidator(mail ?? "")
? null
: "Invalid Email",
obscureText: false,
controller: _emailController,
keyboardType:
TextInputType.emailAddress,
style: const TextStyle(
color: Colors.black),
decoration: const InputDecoration(
hintText: "Email",
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 20,
),
labelStyle: TextStyle(
color: Colors.black,
fontSize: 20,
),
),
),
),
),
]),
),
),
),
),
I would like to show the error beside the expanded TextFormField or on the border of it like the image below.
Thank you in advance!
Use OutlineInputBorder with label or labelText
decoration: const InputDecoration(
hintText: "Email",
labelText: "Email",
focusedBorder: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(),
errorBorder: OutlineInputBorder(),
disabledBorder: OutlineInputBorder(),
TextFormField(
autovalidateMode: AutovalidateMode.always,
validator: (mail) {
return "Enter dasdasd"; //handle the error text
},
obscureText: false,
keyboardType: TextInputType.emailAddress,
style: const TextStyle(color: Colors.black),
decoration: const InputDecoration(
hintText: "Email",
labelText: "Email",
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(),
errorBorder: OutlineInputBorder(),
disabledBorder: OutlineInputBorder(),
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 20,
),
),
),

Flutter Sign Up Page Where First and Last Name are Next To Each Other

I currently am creating a sign up page for an app and want my layout to be different. I currently have fields for First Name, Last Name, Email address, Password, and Confirm Password. I need to add another field below the Name fields so I want to move Last Name up next to First Name.
I want to lay out my app similar to this:
Desired sign up layout
But my App is currently looking like this:
current signup layout
The code below shows how I sloppily ended up with my current layout.
Widget build(BuildContext context) {
return Scaffold(
body: Container(
padding: EdgeInsets.all(30),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topRight,
end: Alignment.bottomCenter,
colors: [Color(0xFF6cc5de), Colors.white]),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
//mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
height: 200.0,
child: Image.asset('assets/carebloomlogo.png'),
),
Container(
height: 50,
child: Text(
'C A R E • B L O O M',
style: GoogleFonts.raleway(
fontWeight: FontWeight.bold,
fontSize: 35,
textStyle: TextStyle(
color: Color(0xFF3E8094),
)),
textAlign: TextAlign.center,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: FNMFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "First Name",
labelStyle: TextStyle(
color: FNMFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _firstname = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: LNMFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Last Name",
labelStyle: TextStyle(
color: LNMFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _lastname = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: EmailFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Email",
labelStyle: TextStyle(
color: EmailFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _email = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: PassFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Enter Password",
labelStyle: TextStyle(
color: PassFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _email = input,
),
),
Container(
height: 85,
child: TextFormField(
obscureText: true,
focusNode: RePassFocusNode,
cursorColor: Color(0xFF3E8094),
decoration: InputDecoration(
labelText: "Re-Enter Password",
labelStyle: TextStyle(
color: RePassFocusNode.hasFocus
? Colors.black
: Color(0xFF3E8094)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFF3E8094)))),
onChanged: (input) => _email = input,
),
),
Container(
width: 300,
height: 60,
child: new ElevatedButton(
child: Text('New User? Sign Up!'),
style: ElevatedButton.styleFrom(
primary: Color(0xFF3E8094),
onPrimary: Colors.white,
shadowColor: Color(0xFF6cc5de),
elevation: 5,
padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20.0),
side: BorderSide(color: Color(0xFF6CC5DE))),
),
onPressed: () {},
),
),
// ElevatedButton(
// onPressed: _launchURL,
// child: Text('No Account? Sign Up!'),
// style: ElevatedButton.styleFrom(primary: Color(0xFF3E8094)),
// ),
//loginMethod: auth.anonLogin)
],
),
),
);
}
}
I have tried switching between, rows and columns, throwing rows in columns, trying a grid (probably incorrectly), but nothing is getting me where I want to be.
Needs to be a column with 4 elements: a row that has two fields (first and last), then a field for email, then a field for password, then a field for confirm. I think the only thing you're missing is starting with Row() as the first of the children: of the outer Column().

How can I make rounded TextField in flutter?

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 TextField so it will look rounded ?
You can add rounded corners to a TextField within the decoration parameter of it
TextField(
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
filled: true,
hintStyle: TextStyle(color: Colors.grey[800]),
hintText: "Type in your text",
fillColor: Colors.white70),
)
#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,
),
),
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),
),
You can try this code bellow:
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
borderSide: BorderSide(
width: 0,
style: BorderStyle.none,
),
),
)
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),
),
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,
),
),
Try this in TextFormField:
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),