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)),
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,
),
),
)
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()),
),
)
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 have a problem, when the textfield is tapped, the flutter keyboard opens up and it cover almost the whole the screen, including the TextField.
I've tried all the solutions I've seen online:
Wrapping the widget in a SingleScrollView
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height),
Set Scaffold to not resizeonBottom
Still, the keyboard is hiding the textField.
This is what I did:
return SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
[....................]
Padding(
padding: const EdgeInsets.all(8.0),
child: ConstrainedBox(
constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height/2),
child: TextField(
style: TextStyle(
color: TheBaseColors.lightRed,
fontWeight: FontWeight.bold,
fontFamily: 'FoundersGrotesqueXCond',
),
onTap: () {},
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(
hintText: 'OCCUPATION',
hintStyle: TextStyle(fontSize: 20.0, color: Colors.blueGrey),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: TheBaseColors.lightRed),
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: TheBaseColors.lightRed),
),
border: UnderlineInputBorder(
borderSide: BorderSide(color: TheBaseColors.lightRed),
),
),
),
),
),
],
),
);
}
}
Try wrap your single child in an scaffold and set the property resizeToAvoidBottomInset to true. So when you tap something in this page, the keyboard will push your page up to not cover your page.
Scaffold(
resizeToAvoidBottomInset: false,
child: ....
)
Padding(
padding:
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
child: Container(
color: Colors.white,
child: Padding(
padding: const EdgeInsets.all(13.0),
child: Row(
children: [
Expanded(
child: TextFormField(
controller: _msgController,
keyboardType: TextInputType.text,
decoration: InputDecoration(
contentPadding: new EdgeInsets.symmetric(
vertical: 15.0, horizontal: 15.0),
border: OutlineInputBorder(
// width: 0.0 produces a thin "hairline" border
borderRadius: BorderRadius.all(Radius.circular(60.0)),
borderSide: BorderSide.none,
//borderSide: const BorderSide(),
),
hintStyle:
TextStyle(color: Colors.black, fontSize: 14.0),
filled: true,
fillColor: Colors.grey[300],
hintText: 'write here...'),
),
),
)
Add this
How do I stop the keyboard from appearing if the user clicks on this help icon... Here is a screenshot
Any type of help will greatly appreciated
Here is my code
TextFormField(
obscureText: false,
controller: urlController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter instagram url';
}
return null;
},
decoration: InputDecoration(
focusedBorder:OutlineInputBorder(
borderSide: const BorderSide(color: Colors.green, width: 1.0),
borderRadius: BorderRadius.circular(8.0),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
borderSide: BorderSide(width: 1,color: Colors.green),
),
filled: true,
fillColor: Colors.white,
border: InputBorder.none,
labelText: 'Paste Your URL',
suffixIcon: IconButton(
onPressed: (){},
icon: Icon(Icons.help),
iconSize: 30.0,
color: Colors.grey[400],
),
),
)
Use suffix property instead of suffixIcon and if it still doesn't work on its own, wrap it with a IgnorePointer widget.
However, I assume that that ? button will have a onTap function, if so, it should then it shouldn't be a problem.
suffix: IgnorePointer(
child:IgnorePointer(
child: IconButton(
onPressed: () {},
icon: Icon(Icons.help),
iconSize: 30.0,
color: Colors.grey[400],
),
);
),
suffixIcon is now part of the TextField so we cannot do it using focus node as per changes made by flutter team.
However you can create your layout with Stack widget.
Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Stack(alignment: Alignment.centerRight, children: [
TextFormField(
focusNode: focusNode,
obscureText: false,
controller: urlController,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter instagram url';
}
return null;
},
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide:
const BorderSide(color: Colors.green, width: 1.0),
borderRadius: BorderRadius.circular(8.0),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8)),
borderSide: BorderSide(width: 1, color: Colors.green),
),
filled: true,
fillColor: Colors.white,
border: InputBorder.none,
labelText: 'Paste Your URL',
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(
Icons.help,
size: 30.0,
color: Colors.grey,
),
),
])),
Or you can use use CupertinoTextField
try this:
suffixIcon: IconButton(
onPressed: (){
FocusScope.of(context).unfocus();
//or FocusScope.of(context).requestFocus(new FocusNode());
},
icon: Icon(Icons.help),
iconSize: 30.0,
color: Colors.grey[400],
),
[EDITED]
or simple use Stack to avoid touching Textfield when touching icon:
Stack(
children: [
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(right: 20.0),
),
),
Positioned(
right: 0,
child: Container(
width: 20,
height: 20,
child: IconButton(onPressed:(){}, icon: Icon(Icons.add),),
),
),
],
),
stack(
children: [
TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.only(right: 20.0),
),
),
Positioned(
right: 0,
child: Container(
width: 20,
height: 20,
child: IconButton(onPressed:(){}, icon: Icon(Icons.add),),
),
),
],
),