I am trying to add a search input control to the app header in my Flutter web app.
See...
Widget _buildSearchControl() {
return Container(
alignment: Alignment.centerLeft,
color: Colors.white,
padding: EdgeInsets.only(right: 20),
margin: EdgeInsets.all(10),
width: 300,
child: TextField(
style: TextStyle(backgroundColor: Colors.white, color: Colors.black),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search,color: Colors.black,),
suffixIcon: IconButton(
icon: const Icon(Icons.clear,color: Colors.black,),
onPressed: () {
/* Clear the search field */
},
),
hintText: 'Search...',
border: InputBorder.none),
),
);
}
However, when entering the text, the characters are not vertically centre aligned as I wpuld expect
Is there a way I can have the characters input to the TextField control vertically centered so that they line up with the icons?
Have you tried this textAlignVertical property?
TextField(
textAlignVertical: TextAlignVertical.center,
....
),
I wrap the Container with Padding.
And add contentPadding: const EdgeInsets.all(5), to InputDecoration
...
Padding(
padding: const EdgeInsets.all(8.0).copyWith(bottom: 0),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Theme.of(context).primaryColor, width: 2),
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: Colors.white
),
child: TextFormField(
controller: _controller,
onChanged: (string) {},
style: TextStyle(color: Theme.of(context).primaryColor),
cursorColor: Theme.of(context).primaryColor,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(5),
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
labelText: 'Enter',
labelStyle: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 16,
fontWeight: FontWeight.w500),
prefixIcon: Icon(
Icons.document_scanner_sharp,
color: Theme.of(context).primaryColor,
),
suffixIcon: Padding(
padding: const EdgeInsets.only(top: 5.0),
child: IconButton(
alignment: Alignment.topLeft,
icon: const Icon(
Icons.clear,
size: 25,
color: Colors.red,
),
tooltip: 'Clear',
onPressed: () {
FocusScope.of(context).unfocus();
_controller.clear();
}
),
)
)
),
),
),
Use this , maybe it depends on your contentPadding
Container(
width: 300,
height: 56,
margin: EdgeInsets.fromLTRB(0, 0, 0, 20),
child: TextFormField(
key: widget.globalKey,
autocorrect: false,
onTap: widget.onClick,
minLines: widget.minLines,
maxLines: widget.maxLines,
textInputAction: TextInputAction.done,
onChanged: (val) => widget.onChangeValue(val),
style: getInputStyle,
initialValue: widget.initialValue,
textAlign: TextAlign.left,
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: widget.controller,
keyboardAppearance: Brightness.dark,
decoration: InputDecoration(
contentPadding: REdgeInsets.fromLTRB(
14, 16, 0, 16),
labelText: widget.labelText,
hintText: widget.hintText,
floatingLabelBehavior: FloatingLabelBehavior.auto,
labelStyle: getLabelStyle,
hintStyle: getLabelStyle,
fillColor: widget.backGroundColor ,
filled: true,
prefix: widget.prefix,
),
),
)
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'm trying to get an expandableTextFormField in bottomNavBar that will automatically increase in height as the user types into a new line. In my bottomNavBar code below, I gave the container a height of 60px so it doesn't take up the whole screen.
bottomNavigationBar: SafeArea(
child: Container(
height: 60,
color: Colors.white,
margin: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
padding: const EdgeInsets.only(
left: 12,
right: 8,
),
child: Row(
children: [
CircleAvatar(
backgroundImage: NetworkImage(url),
radius: 15,
),
Flexible(
child: Padding(
padding: const EdgeInsets.only(
left: 16,
right: 8,
top: 2,
bottom: 2,
),
child: TextFormField(
expands: true,
maxLines: null,
minLines: null,
style: TextStyle(
fontSize: 14,
),
textCapitalization: TextCapitalization.sentences,
controller: commentEditingController,
decoration: InputDecoration(
filled: true,
fillColor: Color(0x27AFAFAF),
hintText: 'Comment as $displayName...',
hintStyle: TextStyle(color: Color(0xFFAFAFAF)),
),
),
),
),
InkWell(
onTap: () {
},
child: Container(
padding: const EdgeInsets.symmetric(
vertical: 8, horizontal: 8),
child: const Text(
'Post',
style: TextStyle(color: Colors.blue),
),
),
)
],
),
);
},
),
),
I also attached a screenshot for more explanation of what I'm talking about:
here's my implementation
Container(
margin: const EdgeInsets.only(top: 20, bottom: 8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(2),
),
constraints: BoxConstraints(
minWidth: MediaQuery.of(context).size.width,
maxWidth: MediaQuery.of(context).size.width,
minHeight: 25.0,//min height you want to take by container
maxHeight: 100.0,//max height you want to take by container
),
child: Scrollbar(
child: TextField(
keyboardType: TextInputType.multiline,
textInputAction: TextInputAction.done,
onSubmitted: (value) {
},
maxLines: null,
// focusNode: focusNode,
controller: _message,
style: const TextStyle(color: Colors.white),
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 13, vertical: 13),
hintText: "Message(optional)",
hintStyle:
TextStyle(color: Colors.white24, fontSize: 14),
),
),
),
),
I was trying to make two cards with Expanded. Everything works fine except that the card is taking too much space in the bottom and won't stop when there is no more TextFormField.
This is my code and below there is a screenshot.
Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
"Ajouter Un Nouveau Fournisseur",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.normal),
),
elevation: 10,
),
backgroundColor: Color(0xFFFFFFFE),
body: SafeArea(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 6,
child: Padding(
padding: EdgeInsets.all(30),
child: Card(
color: Color(0xFFF5F5F5),
elevation: 20,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
child: Text(
'Informations Générales',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold),
),
),
Divider(
thickness: 1,
),
Form(
key: formKey,
child: Padding(
padding: EdgeInsets.all(15.0),
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Nom Du Fournisseur',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Siége Social',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Pays',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.location_on)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Ville/Région',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.location_city,
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Numéro de Téléphone',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.phone,
),
),
),
),
],
),
),
),
],
),
),
),
),
Expanded(
flex: 6,
child: Padding(
padding: EdgeInsets.all(30),
child: Card(
color: Color(0xFFF5F5F5),
elevation: 20,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Container(
width: MediaQuery.of(context).size.width * 0.35,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
child: Text(
'Informations Financieres',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold),
),
),
Divider(
thickness: 1,
),
Form(
key: formKey,
autovalidateMode: AutovalidateMode.disabled,
child: Padding(
padding: EdgeInsets.all(15.0),
child: Column(
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Nom Du Fournisseur',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Siége Social',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Pays',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.location_on)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Ville/Région',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.location_city,
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Numéro de Téléphone',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.phone,
),
),
),
),
],
),
),
),
],
),
),
),
),
),
],
),
),
);
For every Column widget, use mainAxisSize: MainAxisSize.min,.
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
More about mainaxissize property.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.white,
leading: IconButton(
icon: Icon(Icons.arrow_back, color: Colors.black),
onPressed: () => Navigator.of(context).pop(),
),
title: Text(
"Ajouter Un Nouveau Fournisseur",
textAlign: TextAlign.center,
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 20,
fontWeight: FontWeight.normal),
),
elevation: 10,
),
backgroundColor: Color(0xFFFFFFFE),
body: SafeArea(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
flex: 6,
child: Padding(
padding: EdgeInsets.all(30),
child: Card(
color: Color(0xFFF5F5F5),
elevation: 20,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
child: Text(
'Informations Générales',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold),
),
),
Divider(
thickness: 1,
),
Form(
key: formKey,
child: Padding(
padding: EdgeInsets.all(15.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Nom Du Fournisseur',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Siége Social',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Pays',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.location_on)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Ville/Région',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.location_city,
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Numéro de Téléphone',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.phone,
),
),
),
),
],
),
),
),
],
),
),
),
),
Expanded(
flex: 6,
child: Padding(
padding: EdgeInsets.all(30),
child: Card(
color: Color(0xFFF5F5F5),
elevation: 20,
clipBehavior: Clip.antiAliasWithSaveLayer,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Container(
width: MediaQuery.of(context).size.width * 0.35,
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.rectangle,
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 20, 0, 10),
child: Text(
'Informations Financieres',
style: TextStyle(
fontFamily: 'Montserrat',
color: Colors.black,
fontSize: 15,
fontWeight: FontWeight.bold),
),
),
Divider(
thickness: 1,
),
Form(
key: formKey,
autovalidateMode: AutovalidateMode.disabled,
child: Padding(
padding: EdgeInsets.all(15.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Nom Du Fournisseur',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Siége Social',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.perm_identity)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Pays',
//prefixIcon: Icon(Icons.email),
icon: Icon(Icons.location_on)),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Ville/Région',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.location_city,
),
),
),
),
Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 15),
child: TextFormField(
keyboardType: TextInputType.text,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'Numéro de Téléphone',
//prefixIcon: Icon(Icons.email),
icon: Icon(
Icons.phone,
),
),
),
),
],
),
),
),
],
),
),
),
),
),
],
),
),
);
}
}
I want to load an SVG image inside TextFormFieldin Flutter. I have used this SVG loading library.But everytime the svg image is displayed in center and TextFormField's hint text is not getting displayed. I want to load SVG at the end of TextFormField.
Here is my code:
Form(
key: _formKey,
child: Column(
children: [
new RectWithBorder(AppColors.white, AppColors.gray, 1.0, BorderRadius.circular(6.0), new EdgeInsets.all(0.0), new Padding(
padding: new EdgeInsets.all(10.0),
child: TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: Strings.emailOrMobileText,
),
keyboardType: TextInputType.text,
controller: emailController,
validator: Utils.isValidEmailOrMobile,
onSaved: (String value){
this.email = value;
},
))),
new RectWithBorder(AppColors.white, AppColors.gray, 1.0, BorderRadius.circular(6.0), new EdgeInsets.fromLTRB(0, 10.0, 0, 0), new Padding(
padding: new EdgeInsets.all(10.0),
child: TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: Strings.passwordText,
suffixIcon: new Padding(
padding: const EdgeInsets.all(5.0),
child: new SizedBox(
height: 20,
child: SvgPicture.asset("assets/images/invisible.svg"),
),
),
),
keyboardType: TextInputType.text,
obscureText: true,
validator: _validatePassword,
onSaved: (String value){
this.password = value;
},
),)
),
new RoundedButton(
title: Strings.loginButtonText.toUpperCase(),
backgroundColor: AppColors.accent,
radius: 6.0,
textStyle: new TextStyle(fontSize: 18.0, fontWeight: FontWeight.bold, color: AppColors.white),
textColor: AppColors.white, margin: new EdgeInsets.fromLTRB(0, 20, 0, 0), onPressed: (){
Utils.isConnectedToInternet().then((isConnected){
if(isConnected == null || !isConnected){
Utils.showSnackBar(context, Strings.noInternetConnection);
} else{
// _verifyCaptcha();
_executeLogin(email, password);
}
});
},),
new Container(
margin: new EdgeInsets.fromLTRB(0, 30.0, 0, 0),
child: new GestureDetector(
child: Text(
Strings.forgotPasswordText,
style: new TextStyle(
color: AppColors.primary,
fontSize: 15.0
),
),
))
],
),
),
but it displays SVG as below image
Any help what's wrong with this?
Replace your decoration code from here.
decoration: InputDecoration(
hintText: "Password",
isDense: true,
suffixIconConstraints: BoxConstraints(
minWidth: 2,
minHeight: 2,
),
suffixIcon: InkWell(
child: new Padding(
padding: const EdgeInsets.all(5.0),
child: new SizedBox(
height: 20,
child:
SvgPicture.asset("assets/images/invisible.svg"),
),
), onTap: () {}))