how enable TextFormField input flutter - 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.

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

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,

Attach two suffix icon with background on textfield in flutter?

I want the outcome to be like this,
but so far what I have achieved is
The 'From' tag is not an issue but the outline is.
here is code for my text field.
TextField(
enabled: false,
decoration: InputDecoration(
disabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: colorx.Colors.black, width: 0.7),
),
hintText: 'YYYY-MM-DD',
hintStyle: TextStyle(color: Colors.black12),
suffixIcon: Container(
height: 58,
width: 80,
decoration:
BoxDecoration(color: colorx.Colors.paleGreyTwo,),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// added line
mainAxisSize: MainAxisSize.min,
// added line
children: [
Image.asset(
"graphics/calender.png",
),
Image.asset(
"graphics/refresh_date.png",
),
],
),
),
),
style: TextStyle(color: Colors.black),
),
Try below code hope its help to you. just change my icons to your Images
TextField(
enabled: false,
decoration: InputDecoration(
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black, width: 0.7,),
),
hintText: 'YYYY-MM-DD',
hintStyle: TextStyle(color: Colors.black12,),
suffixIcon: Container(
margin: EdgeInsets.all(1),
height: 58,
width: 100,
decoration: BoxDecoration(
color: Colors.grey,
border: Border(
left: BorderSide(
color: Colors.black,
width: 1.0,
),
),),
child: IntrinsicHeight(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.date_range,),
VerticalDivider(
color: Colors.black,
thickness: 1,
),
Icon(Icons.close,),
],
),
),
),
),
style: TextStyle(
color: Colors.black,
),
),
Your result screen->

How to style this kind of Text Field

I want to style this kind of TextField.
The main problem that I'm facing is to design the US$ part in leading the TextField. This is my code so far.
/// My Place Bid Text Field
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: "Place Bid",
labelStyle: TextStyle(fontSize: 24)),
),
),
],
),
),
Which gives me output
I know this question is not that complicated, but I'm still relatively new to flutter so your help would be much appreciated.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample"),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[500],
),
borderRadius: BorderRadius.all(Radius.circular(8))),
width: double.infinity,
height: 50,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
color: Colors.grey.shade300,
height: 50,
child: Align(
alignment: Alignment.center,
child: Text(
"RS \u20B9",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
)),
SizedBox(
width: 10,
),
Expanded(
child: Container(
height: 50,
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Bid",
labelStyle: TextStyle(fontSize: 24)),
)))
],
),
),
));
}
Output
You can use the prefixIcon to add a widget at the beginning of the textfield:
Container(
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: Container(
padding: const EdgeInsets.all(13),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
border: const OutlineInputBorder(),
labelText: 'Hint Text',
),
),
),
],
),
)
example:
https://dartpad.dev/a89aff20d67e2cb31da6a07ba7c17910
Based on your solution.
Notice the "IntrinsicHeight" widget. It makes all the children inside the child the same size (depending on the biggest one). The "Center" widget inside the prefix makes the Container go max height + center the text inside of it. Just make sure not to use IntrinsicHeight too much, since the docs state that it's a bit resource heavy.
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: InputBorder.none,
labelText: "Place Bid",
),
),
),
],
),
),
),
The second code is almost the same, except there's no label after typing the text inside the TextField.
Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
border: InputBorder.none,
hintText: "Place Bid",
),
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border:Border.all(color:Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft:Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: new OutlineInputBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
bottomRight:
Radius.circular(4),
),
),
isDense: true,
labelText: "Place Bid",
labelStyle:
TextStyle(fontSize:24)),
),
),
],
),
),