When click textformfield:
Not click textformfield:
How to disable textformfield border when clicked. I want when the textformfield is clicked the border doesn't change to blue color. Does anyone know how to make it?
This is my code:
TextFormField(
controller: searchPatient,
decoration: InputDecoration(
suffixIcon: InkWell(
onTap: () => {
setState(() {
_getAppointmentList(
searchPatient.text,
selectedStatus,
0);
})
},
child: Container(
height: 25,
color: Color.fromRGBO(
14, 113, 176, 1),
child: AspectRatio(
aspectRatio: 2 / 1,
child: Center(
child: Icon(
Icons.search,
color: Colors.white,
)),
),
),
),
hintText:
'Search Patient Namore, MRN ID.',
hintStyle: TextStyle(
color: Colors.grey,
fontSize: 16,
),
/* contentPadding:
EdgeInsets.symmetric(
vertical: 20,
horizontal: 15),*/
contentPadding:
EdgeInsets.symmetric(
horizontal: 15),
border: OutlineInputBorder(
borderSide: BorderSide(
width: 1,
color: Colors.black),
),
),
),
Set the focusedBorder same as enabledBorder (enabledBorder is applied as default view)
The focusedBorder will be applied on the tap event (when the text field is focused)
TextFormField(
decoration: InputDecoration(
enabledBorder: const OutlineInputBorder(borderSide: BorderSide()),
focusedBorder: const OutlineInputBorder(borderSide: BorderSide()),
),
)
Related
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 want to achieve this
Here is my code so far,
Padding(
padding: EdgeInsets.fromLTRB(5, 10, 5, 10),
child: Container(
decoration: BoxDecoration(
boxShadow: [
const BoxShadow(
blurRadius: 1,
),
],
borderRadius: BorderRadius.circular(5.0),
),
child: TextFormField(
keyboardType: TextInputType.text,
validator: (value) {
if (value.isEmpty) {
return MessageForm.required_message;
}
return null;
},
controller: _fullnameInput,
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
// enabledBorder: OutlineInputBorder(
// borderRadius: BorderRadius.circular(10.0),
// borderSide: BorderSide(
// color: AppColors.primary,
// width: 1.0,
// ),
// ),
border: OutlineInputBorder(),
labelText: 'Full Name',
labelStyle: TextStyle(fontSize: 15),
),
),
),
),
there result is not like i expect, here is the result
So how can i achieve it ? fyi, i'm not using nullsafety
You gotta play with the values like offset and blurRadius but here is an example:
BoxShadow(
color: Colors.black,
blurRadius: 15,
offset: Offset(-5, 5),
),
Wrap your TextFormField in a Card. Example:
runApp(MaterialApp(
color: Colors.grey[50],
home: Center(
child: SizedBox(
width: 100,
child: Card(
elevation: 5,
child: TextFormField(
decoration: InputDecoration(
fillColor: Colors.white,
filled: true,
border: InputBorder.none,
labelText: 'Full Name',
labelStyle: TextStyle(fontSize: 15),
),
),
),
),
)));
Output:
Play with the elevation property to increase or decrease the amount of shadow
I have this TextFormField wrapped in container for shadow effect.
And input decoration for field styling.
The icon background color and field background color are different.
I am not able to change the icon background color of the field.
I am trying to achieve
Please suggest a way to change the icon background color.
Here is the code
Container(
margin: const EdgeInsets.all(24.0),
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
boxShadow: [
BoxShadow(
spreadRadius: 10.0,
blurStyle: BlurStyle.outer,
blurRadius: 4.0,
color: Colors.black26,
),
],
),
child: Material(
child: TextFormField(
maxLines: 1,
decoration: InputDecoration(
icon: Icon(
Icons.search,
size: 24.0,
color: Theme.of(context).primaryColor,
),
isDense: true,
hintText: 'Search',
contentPadding: const EdgeInsets.symmetric(vertical: 8.0),
fillColor: Theme.of(context).scaffoldBackgroundColor,
filled: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
focusedBorder: InputBorder.none,
border: InputBorder.none,
),
onFieldSubmitted: (text) {
// Perform search
},
),
),
)
Wrap the Icon with a Container and give it a color.
Container(
color: Colors.red,
child: Icon(
Icons.search,
size: 24.0,
color: Theme.of(context).primaryColor,
),
)
Add color attribute to Material widget to change icon background color.
Container(
margin: const EdgeInsets.all(24.0),
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(10.0),
),
boxShadow: [
BoxShadow(
spreadRadius: 10.0,
blurStyle: BlurStyle.outer,
blurRadius: 4.0,
color: Colors.black26,
),
],
),
child: Material(
color: Colors.transparent //Changed here
child: TextFormField(
maxLines: 1,
decoration: InputDecoration(
icon: Icon(
Icons.search,
size: 24.0,
color: Colors.black,
),
isDense: true,
hintText: 'Search',
contentPadding: const EdgeInsets.symmetric(vertical: 8.0),
fillColor: Theme.of(context).scaffoldBackgroundColor,
filled: true,
floatingLabelBehavior: FloatingLabelBehavior.never,
focusedBorder: InputBorder.none,
border: InputBorder.none,
),
onFieldSubmitted: (text) {
// Perform search
},
),
),
),
I add comments in the code to report where i changed.
This is the result:
I am trying to make a textfield with rounded border and some drop shadow,
when i use elevation it shows some parts outside the border, please have alook in the image i had attached.
Container(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Container(
height: 30.0,
child: Material(
elevation: 2.0,
shadowColor: Colors.grey,
child: TextField(
autofocus: false,
style: TextStyle(
color: Colors.black,
),
decoration: kTextFieldDecorationCircular,
onChanged: (value){
searchWord = value;
},
onEditingComplete: searchTheWord,
),
),
),
),
);
const kTextFieldDecorationCircular = InputDecoration(
contentPadding: EdgeInsets.all(2.0),
filled: true,
fillColor: Colors.white,
prefixIcon: Icon(Icons.search, color: Colors.grey,),
hintText: 'Search',
hintStyle: TextStyle(color: Colors.grey),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(50.0)),
),
);
This is my code.
Thank you in advance.
You could add this to your Material widget:
borderRadius: BorderRadius.all(Radius.circular(50.0)),