How to add search button? - flutter

Design I want:
My current design:
Hello. I want to ask. How to make a search column that has a button and a textfield like the design image I want. My design is now a textfield with an icon. The icon is in the textfield.
This is my code for search design:
Container(
width: 1120,
alignment: Alignment.topRight,
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: SizedBox(
width: 310,
height: 40,
child: TextFormField(
decoration: InputDecoration(
suffixIcon: IconButton(
iconSize: 25,
icon: const Icon(
Icons.search,
),
color: Colors.blue,
onPressed: () => ""),
hintText: 'Search Document',
contentPadding:
EdgeInsets.symmetric(
vertical: 20,
horizontal: 15),
border: OutlineInputBorder(),
),
),
), Container(
width: 1120,
alignment: Alignment.topRight,
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: SizedBox(
width: 310,
height: 40,
child: TextFormField(
decoration: InputDecoration(
suffixIcon: IconButton(
iconSize: 25,
icon: const Icon(
Icons.search,
),
color: Colors.blue,
onPressed: () => ""),
hintText: 'Search Document',
contentPadding:
EdgeInsets.symmetric(
vertical: 20,
horizontal: 15),
border: OutlineInputBorder(),
),
),
),

Try this code:
TextFormField(
decoration: InputDecoration(
suffixIcon: InkWell(
onTap: () => "",
child: Container(
height: 25,
color: Colors.blue,
child: AspectRatio(
aspectRatio: 2 / 1,
child: Center(
child: Icon(
Icons.search,
color: Colors.white,
)),
),
),
),
hintText: 'Search Document',
contentPadding: EdgeInsets.symmetric(horizontal: 15),
border: OutlineInputBorder(
borderSide: BorderSide(width: 1, color: Colors.black),
),
),
)

Related

How to reduce the height of the DropDownButtonFormField so that the text inside it does not go out of the middle in flutter?

When I set a height for my container that is the parent of DropDownButtonFormField, I have no problem when the height is 55, but when the height is less (42) than a certain limit, the text inside it looks like this.
As it is clear in the picture, cat is no longer in the middle of the container.
this is my code:
Container(
alignment: Alignment.center,
width: double.infinity,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: const Color(0xFF616161),
width: 0.65,
),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 10, 0),
child: DropdownButtonFormField(
enableFeedback: true,
menuMaxHeight: 200,
icon: Icon(Icons.keyboard_arrow_down_rounded),
iconSize: 21,
alignment: Alignment.center,
// decoration: InputDecoration.collapsed(hintText: ''),
decoration: InputDecoration(
border: InputBorder.none,
prefixIcon: Icon(Icons.location_on_rounded),
),
dropdownColor: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
elevation: 2,
// isExpanded: true,
value: cityValue,
onChanged: (String? newValue) {
setState(() {
cityValue = newValue!;
});
},
items: <String>['Tehran', 'Cat', 'Tiger', 'Lion']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style:
TextStyle(fontSize: 15, color: Color(0xff707070)),
),
);
}).toList(),
),
),
),
The icon is in the middle but not the text.
I used Offset, but then the icon gets messed up.
The default Icon size 24, so you need minimum height 48 to view properly. It would be better not to force it have certain height.You can remove height 40 for better UX.
Now let say you like to have fixed hight, for this case, you need to maintain padding for yourself.
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 6), //this one
prefixIcon: Icon(Icons.location_on_rounded),
),
Container(
alignment: Alignment.center,
width: double.infinity,
height: 40,
decoration: BoxDecoration(
color: Colors.white,
border: Border.all(
color: const Color(0xFF616161),
width: 0.65,
),
borderRadius: BorderRadius.circular(8),
),
child: Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
child: DropdownButtonFormField(
enableFeedback: true,
menuMaxHeight: 200,
icon: Icon(Icons.keyboard_arrow_down_rounded),
iconSize: 20,
alignment: Alignment.center,
// decoration: InputDecoration.collapsed(hintText: ''),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top: 6), //this one
prefixIcon: Icon(Icons.location_on_rounded),
),
dropdownColor: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(8)),
elevation: 2,
onChanged: (String? newValue) {},
items: <String>['Tehran', 'Cat', 'Tiger', 'Lion']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style:
TextStyle(fontSize: 15, color: Color(0xff707070)),
),
);
}).toList(),
),
),
),
A quick solution is adding a contentPadding to the InputDecoration.
contentPadding: EdgeInsets.symmetric(vertical: 7),
Try below code using InputDecoration
DropdownButtonFormField(
decoration: const InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(width: 1, color: Colors.grey),
),
contentPadding: EdgeInsets.symmetric(
horizontal: 10.0,
vertical: 3.0,
),
border: OutlineInputBorder(),
prefixIcon: Icon(
Icons.location_on_rounded,
color: Colors.grey,
),
),
dropdownColor: Colors.white,
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
icon: const Icon(Icons.keyboard_arrow_down_rounded),
onChanged: (value) => {
cityValue = value!,
},
items: <String>['Tehran', 'Cat', 'Tiger', 'Lion']
.map(
(e) => DropdownMenuItem(
value: e,
child: Text(e),
),
)
.toList(),
),
Your Result Screen->

Textformfiled flutter: prefix and suffix not in line with the content

The textformfiled i want
and My textformfield now
I'm trying create a search field like this.(attach this link) but the suffix, prefix icon not align with content
I am also attaching the code that I am using for this TextFormfield:
Container(
height: 35,
width: Get.width - 40,
decoration: BoxDecoration(
color: backgroundColor.withOpacity(.8),
borderRadius: BorderRadius.circular(20),
),
child: TextFormField(
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
contentPadding: const EdgeInsets.only(
left: 15, bottom: 10, top: 10, right: 15),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: 'Search',
prefix: IconButton(
constraints: const BoxConstraints(),
icon: Image.asset(
'assets/icons/back.png',
width: 20,
height: 20,
fit: BoxFit.scaleDown,
),
onPressed: () => toast(content: 'back action'),
padding: EdgeInsets.zero,
),
suffix: IconButton(
constraints: const BoxConstraints(),
icon: Image.asset(
'assets/icons/plus_circle.png',
width: 20,
height: 20,
fit: BoxFit.scaleDown,
),
onPressed: () => toast(content: 'clear action'),
padding: EdgeInsets.zero,
),
),
),
),
You can use CupertinoSearchTextField and modify the way it as you like. If it doesnt satisfy, you can choose row over prefix and suffix alignment. Here are three looks and code.
CupertinoSearchTextField
child: CupertinoSearchTextField(
padding: EdgeInsets.all(8),
borderRadius: BorderRadius.circular(20),
// decoration: BoxDecoration(
// color: Colors.grey,
// borderRadius: BorderRadius.circular(20),
// ),
prefixIcon: Icon(Icons.arrow_back_ios),
),
Using Row
Container(
width: 400,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(20),
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
IconButton(
iconSize: 16,
icon: Icon(
Icons.ads_click,
),
onPressed: () {},
padding: EdgeInsets.zero,
),
Expanded(
child: TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: 'Search',
isDense: true,
),
)),
IconButton(
iconSize: 16,
icon: Icon(
Icons.ads_click,
),
onPressed: () {},
padding: EdgeInsets.zero,
),
],
),
),
Using Prefix and suffix
Container(
width: 400,
decoration: BoxDecoration(
color: Colors.grey,
borderRadius: BorderRadius.circular(20),
),
child: TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: 'Search',
isDense: true,
prefix: IconButton(
iconSize: 16,
icon: Icon(
Icons.ads_click,
),
onPressed: () {},
padding: EdgeInsets.zero,
),
suffix: IconButton(
iconSize: 16,
constraints: const BoxConstraints(),
icon: Icon(Icons.ads_click),
onPressed: () {},
padding: EdgeInsets.only(right: 16),
),
),
),
),
IF you need to change size, provide height and width(if needed wrapped with SizedBox)
Wrap the icon in a column widget and give mainAxisAlignment center
Column(
mainAxisAlignment: MainAxisAlignment.center,
children:[ Icon(),]
)
This will bring the icon to the center of the text field

flutter - align an element of a Row () at the bottom when the TextField is multiline?

how can I make the RawMaterialButton stay down when the TextField multiline is enabled?
I am attaching some images to better understand what I need
That's my code:
Row(
children: [
Flexible(
child: TextField(
keyboardType: TextInputType.multiline,
minLines: 1,
maxLines: 6,
style: TextStyle(fontSize: 19.0),
controller: _controller,
decoration: InputDecoration(
hintText: 'Type a message...',
contentPadding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color(0xFF25BBC2), width: 1.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Color(0xFF25BBC2), width: 2.0),
borderRadius: BorderRadius.all(Radius.circular(32.0)),
),
),
),
),
SizedBox(
width: 4.0,
),
Container(
child: RawMaterialButton(
onPressed: () {},
child: Padding(
padding: const EdgeInsets.only(left: 3.0),
child: Icon(
Icons.send,
size: 27,
color: Colors.white,
),
),
elevation: 0,
shape: CircleBorder(),
constraints: BoxConstraints.tightFor(
width: 48.0,
height: 48.0,
),
),
decoration: BoxDecoration(
color: Color(0xFF25BBC2),
borderRadius: BorderRadius.circular(40.0),
),
),
],
),
That's the output:
and this is the output I would like to have:
Thank you :)
I have resolve it by adding:
crossAxisAlignment: CrossAxisAlignment.end,

how enable TextFormField input flutter

I'm starter in Flutter and Dart .I created TextFormField input , I would like to make it enable but i can't do that .As you see i tried to use some solutions but they couldn't help me , it's always disable . Ho i can fix it ? Any help please ?
My code :
body: Directionality(
textDirection: TextDirection.ltr,
child: Stack(
children: <Widget>[
Container(
color: Colors.white,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
Positioned(
bottom: 0,
child: Container(
height: 60,
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border:
Border(top: BorderSide(color: Colors.grey))),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.camera_enhance,
color: Colors.grey,
),
onPressed: () {}),
Container(
padding: EdgeInsets.symmetric(
horizontal: 5, vertical: 5),
width: MediaQuery.of(context).size.width - 50,
child: TextFormField(
// enabled: true,
// readOnly: false,
// enableInteractiveSelection: true,
controller: _addcomment,
decoration: InputDecoration(
hintText: 'Type something',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: addComment,
),
contentPadding: EdgeInsets.all(5),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
)),
],
),
)
],
),
)),
and this TextFormField Input
Here is Your Correct Code :
body: Directionality(
textDirection: TextDirection.ltr,
child: Stack(
children: <Widget>[
Container(
color: Colors.white,
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
),
Positioned(
bottom: 0,
child: Container(
height: 60,
width: MediaQuery.of(context).size.width,
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border:
Border(top: BorderSide(color: Colors.grey))),
child: Row(
children: <Widget>[
IconButton(
icon: Icon(
Icons.camera_enhance,
color: Colors.grey,
),
onPressed: () {}),
Container(
padding: EdgeInsets.symmetric(
horizontal: 5, vertical: 5),
width: MediaQuery.of(context).size.width - 50,
child: TextFormField(
autoFocus: true,
controller: _addcomment,
decoration: InputDecoration(
hintText: 'Type something',
filled: true,
fillColor: Colors.grey[200],
suffixIcon: IconButton(
icon: Icon(Icons.send),
onPressed: addComment,
),
contentPadding: EdgeInsets.all(5),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(60),
borderSide: BorderSide(
style: BorderStyle.none)),
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
)),
],
),
)
],
),
)),
add property autoFocus and set it's value as a true.

Textfield height is not decreasing in flutter | Flutter

Container(
height: 30,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
suffixIcon: Padding(
padding: const EdgeInsets.all(8.0),
child: IconButton(
icon: Icon(
Icons.search,
),
onPressed: () {},
),
),
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(30.0),
),
),
filled: true,
hintStyle: new TextStyle(
color: Colors.grey[500],
),
hintText: "Search Here",
fillColor: Colors.white70,
),
),
),
),
I want to reduce the textfield size, wrapping it with container and giving height is not working. is there any way to reduce the textfield size
Container(
width: 100.0,
child: TextField(
style: TextStyle(
fontSize: 30.0,
height: 2.0,
)
)
)