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

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

Related

How to add search button?

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),
),
),
)

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,

Hidden list with searcher - flutter

The searcher bar is not working, where did i get an error?
I get this error in the terminal when I added expanded:
RenderFlex children have non-zero flex but incoming height constraints are unbounded.
I would like the hints from lost when searching to appear.Is everything logically arranged? I am new in flutter and not everything is clear to me.
Widget _profilePage(BuildContext context) {
(context, state) {
return SafeArea(
child: Align(
alignment: const Alignment(0, -1 / 1.6),
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
_buildSearchBar(),
],
),
),
),
);
}
List<String> newAllBreed = List.from(allBreed);
static List<String> allBreed =
["Affenpinscher",
"Afghan Hound",
"Aidi",
"Airedale Terrier",
"Akbash Dog",
"Akita"];
void search(String value) {
setState(() {
newAllBreed = allBreed
.where((string) =>
string.toLowerCase().contains(value.toLowerCase()))
.toList();
});
}
Widget _buildSearchBar() {
return Column(children: [
ConstrainedBox(
constraints: const BoxConstraints.tightFor(width: 350),
child: TextFormField(
controller: controller,
onFieldSubmitted: search,
decoration: InputDecoration(
labelText: 'Search',
hintText: 'Search',
fillColor: Colors.white,
filled: true,
isDense: true,
suffixIcon: GestureDetector(
onTap: () {
controller.clear();
},
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
child: Icon(
Icons.clear,
size: 30,
),
),
),
prefixIcon: GestureDetector(
onTap: () {
search(controller.text);
},
/// widget isntead of normal button
// cancellationWidget: Text("Cancel"),
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
child: Icon(
Icons.search_outlined,
size: 30,
),
),
),
focusedBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30),
),
borderSide: BorderSide(
width: 2,
color: Colors.teal,
),
),
disabledBorder: InputBorder.none,
border: InputBorder.none,
enabledBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30),
),
borderSide: BorderSide(
width: 2,
color: Colors.grey,
),
),
errorBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
borderSide: BorderSide(
width: 2,
color: Colors.red,
),
),
),
),
),
Expanded(
child: ListView(
padding: EdgeInsets.all(12.0),
children: newAllBreed.map((data) {
return ListTile(
title: Text(data),
onTap: ()=> print(data),);
}).toList(),
),
)
]);
}
Flutter is cool and you don't need to nest the Widgets unnecessarily. Since you are designing a typical search with list you can use Column widget instead of SingleChildScrollView. Simplified approach will be as below.
Column(children: [
TextFormField( .. ), // => Your search text box
Expanded(child: ListView( .. )) // => Search result
])
Full Snippet : For your understanding
Column(children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
controller: controller,
onFieldSubmitted: search,
decoration: InputDecoration(
labelText: 'Search',
hintText: 'Search',
fillColor: Colors.white,
filled: true,
isDense: true,
suffixIcon: GestureDetector(
onTap: () {
controller.clear();
},
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
child: Icon(
Icons.clear,
size: 30,
),
),
),
prefixIcon: GestureDetector(
onTap: () {
search(controller.text);
},
/// widget isntead of normal button
// cancellationWidget: Text("Cancel"),
child: const Padding(
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 10,
),
child: Icon(
Icons.search_outlined,
size: 30,
),
),
),
focusedBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30),
),
borderSide: BorderSide(
width: 2,
color: Colors.teal,
),
),
disabledBorder: InputBorder.none,
border: InputBorder.none,
enabledBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(30),
),
borderSide: BorderSide(
width: 2,
color: Colors.grey,
),
),
errorBorder: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(5),
),
borderSide: BorderSide(
width: 2,
color: Colors.red,
),
),
),
),
),
Expanded(
child: ListView(
padding: EdgeInsets.all(12.0),
semanticChildCount: newAllBreed.length,
children: newAllBreed.map((data) {
return ListTile(
title: Text(data),
onTap: () => print(data),);
}).toList(),
),
)
]);

Keyboard appears when click on help icon inside textfield

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),),
),
),
],
),

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.