I have form where I collect data from client in flutter.
At the last 3 fields I want add dropdown menu with different choice to be done by the customers.
But I cant find how to add dropdown menu choice to the form flutter.
this is the screen shot:
enter image description here
the part of the code interested is:
padding: const EdgeInsets.all(10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
width: 193,
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black,fontSize: 14),
decoration: InputDecoration(
labelText: '',
prefixIcon: Icon(Icons.arrow_drop_down,color: Color(0xFF1f2032),size: 17,),
hintStyle: TextStyle(color: Colors.grey),
hintText: '',
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 35.0),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.circular(5),
),
),
),
),
SizedBox(width: 10,),
Container(
width: 193,
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black,fontSize: 14),
decoration: InputDecoration(
labelText: '',
prefixIcon: Icon(Icons.arrow_drop_down,color: Color(0xFF1f2032),size: 17,),
hintStyle: TextStyle(color: Colors.grey),
hintText: '',
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 35.0),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.circular(5),
),
),
),
),
SizedBox(width: 10,),
Container(
width: 193,
child: TextField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black,fontSize: 14),
decoration: InputDecoration(
labelText: '',
prefixIcon: Icon(Icons.arrow_drop_down,color: Color(0xFF1f2032),size: 17,),
hintStyle: TextStyle(color: Colors.grey),
hintText: '',
contentPadding:
EdgeInsets.symmetric(vertical: 5, horizontal: 35.0),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey, width: 0.3),
borderRadius: BorderRadius.circular(5),
),
),
),
),
],
),
), ```
Related
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,
),
),
),
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)
I have implemented a text form field with validation, and it returns the error message but it gets displayed inside the text form field. Is there a way to show it outside the text form field?
Container(
alignment: Alignment.center,
margin: const EdgeInsets.symmetric(
horizontal: 20),
decoration: BoxDecoration(
color: Colors.grey.withOpacity(0.1),
borderRadius: const BorderRadius.all(
Radius.circular(10))),
child: TextFormField(
autovalidateMode:
AutovalidateMode.onUserInteraction,
controller: _controller,
validator: validatePhone,
textAlignVertical: TextAlignVertical.center,
style: const TextStyle(
color: primaryText,
fontFamily: 'InterMedium',
fontSize: 15),
decoration: const InputDecoration(
counterText: '',
errorStyle: TextStyle(
fontFamily: 'InterMedium',
),
prefixIcon: Padding(
padding: EdgeInsets.only(
left: 20, right: 15),
child: Icon(
Icons.phone_android_rounded,
color: secondaryText,
),
),
hintText: 'Enter mobile number',
hintStyle: TextStyle(
fontFamily: 'InterMedium',
color: secondaryText,
),
border: InputBorder.none,
),
cursorColor: secondaryColor,
maxLines: 1,
maxLength: 10,
keyboardType: TextInputType.phone,
textInputAction: TextInputAction.done,
),
),
How it is now -
How I want it to look like -
Remove parent widget Container and add decoration property of TextFormField like below example !
TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
cursorColor: Colors.black,
validator: validator,
controller: controller,
keyboardType: TextInputType.phone,
style: const TextStyle(fontSize: 16, color: Colors.black, fontFamily: 'Helvetica', fontWeight: FontWeight.normal),
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff13367A)),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff13367A)),
),
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xff13367A)),
),
hintText: hint)),
),
P.S :- If you want to add grey color in your TextFormField then you may use decoration: InputDecoration(fillColor: Colors.grey, filled: true) !
I am creating a employee bio data page, for this i have 4 to 5 categories e.g. Personal data, family info, skills, employee history.
my output should be like this
for all categories, how i can create it in flutter.
i have done this
and want to convert it to like above design.
---------------EDITED QUESTION--------------------------------
I did the below code but it is not meeting my requirement.
Padding(padding: EdgeInsets.fromLTRB(15, 5,50, 0),
child:Container(decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent,width: 100)
),
child:Padding(padding: EdgeInsets.fromLTRB(15, 5,50, 0),
child: TextField(
decoration: InputDecoration(border: InputBorder.none),
),
))
here is its output
please help if anyone know the name of widget or how to create it.
You can get this layout by using Stack, Containers and Column
Stack(
children: <Widget>[
Container(
margin: EdgeInsets.symmetric(
vertical: 20, horizontal: 20),
decoration: BoxDecoration(
border: Border.all(color: Colors.black, width: 2),
),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Column(
children: [
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextFormField(
controller: _addressController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
hintText: "Enter Address",
prefixIcon: Icon(
Icons.home,
color: Colors.grey,
),
hintStyle: TextStyle(
fontStyle: FontStyle.normal,
fontSize: 13,
color: Colors.grey),
enabledBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
focusedBorder: new OutlineInputBorder(
borderSide: new BorderSide(
color: Colors.black, width: 3),
),
),
),
SizedBox(
height: 10,
),
TextButton(
onPressed: () {},
child: Text(
'Submit',
style: TextStyle(
fontSize: 13,
),
),
style: ButtonStyle(
side: MaterialStateProperty.all(
BorderSide(
width: 2, color: Colors.black),
),
foregroundColor:
MaterialStateProperty.all(
Colors.black),
padding: MaterialStateProperty.all(
EdgeInsets.symmetric(
vertical: 2, horizontal: 30)),
textStyle: MaterialStateProperty.all(
TextStyle(fontSize: 30),
),
),
),
],
),
),
),
Positioned(
left: 30,
top: 10,
child: Container(
padding: EdgeInsets.symmetric(
horizontal: 3,
vertical: 2,
),
color: Colors.white,
child: Text(
'Personal Data',
style: TextStyle(
color: Colors.black, fontSize: 12),
),
),
),
],
),
bro take a container giver border to container like this
decoration: BoxDecoration(
border: Border.all(color: Colors.blueAccent)
),
after that take inputfield and make this field border none like this
borde:InputBorder.none
so you can easily do that by this way
I want to achieve the design below but I don't know how to customize this, am still a newbie in Flutter.
I know how to use TextFields but don't know how to go around this :
Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[700]),
hintText: "Email",
fillColor: Colors.white70),
),
SizedBox(height: 50),
TextField(
decoration: new InputDecoration(
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(10.0),
),
),
filled: true,
hintStyle: new TextStyle(color: Colors.grey[700]),
hintText: "Password",
fillColor: Colors.white70),
)
]));
Lutaaya Huzaifah Idris Refer to the documentation as specified by Afridi Kayal in comments for more customization.
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsets.only(left: 25, right: 20),
margin: const EdgeInsets.fromLTRB(20,10,20,10),
child: TextField(
decoration: InputDecoration(
hintText: "Email",
border: InputBorder.none,
),
),
),
Container(
decoration: BoxDecoration(
color: Colors.grey[200],
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsets.only(left: 25, right: 20),
margin: const EdgeInsets.fromLTRB(20,10,20,10),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
border: InputBorder.none,
),
obscureText: true,
),
),
Output: