how to add bottom TextFormField in flutter like send comment buttton - flutter

child: Row(
children: [
// First child is enter comment text input
TextFormField(
controller: commentController,
autocorrect: false,
decoration: new InputDecoration(
labelText: "Some Text",
hintText: "Write a comment",
labelStyle:
TextStyle(fontSize: 20.0, color: Colors.white),
fillColor: Colors.blue,
border: OutlineInputBorder(
// borderRadius:`your text`
// BorderRadius.all(Radius.zero(5.0)),
borderSide:
BorderSide(color: Colors.purpleAccent)),
),
),
// Second child is button
IconButton(
icon: Icon(Icons.send),
iconSize: 20.0,
onPressed: () {
},
)
]
)

Try below code and use suffixIcon widget is best for your design
TextFormField(
autocorrect: false,
decoration: InputDecoration(
suffixIcon: IconButton(
icon: Icon(Icons.send),
iconSize: 20.0,
onPressed: () {},
),
labelText: "Some Text",
hintText: "Write a comment",
fillColor: Colors.blue,
border: const OutlineInputBorder(
borderSide: BorderSide(color: Colors.purpleAccent),
),
),
),
Your code result->
My above code result->

Related

how to align items inside textformfields?

How do I properly align the prefix icon, the hintText, the actual value that the user has typed in and the suffix icon? I am using textformfield for this one.
Widget yourNameWidget(yourNameCtrlr) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 0.0),
child: TextFormField(
style: const TextStyle(fontFamily: 'Poppins', fontSize: 12),
controller: yourNameCtrlr,
keyboardType: TextInputType.text,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(18),
isDense: true,
prefixIcon: const Icon(Icons.person),
enabledBorder: OutlineInputBorder(
borderSide: const BorderSide(color: Color(0xFFCECECE)),
borderRadius: BorderRadius.circular(12),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Color(0xFFCECECE)),
),
// this does not align with the prefix and the hint text
suffix: GestureDetector(
onTap: () {
yourNameCtrlr.clear();
},
child: const Icon(
Icons.clear,
size: 16,
),
),
hintText: 'Your Name',
fillColor: const Color(0xFFFEFEFE),
filled: true,
),
validator: (value) {
if (value!.isEmpty || !RegExp(r'^[a-z A-Z]+$').hasMatch(value)) {
return "Please enter a valid name.";
} else {
return null;
}
},
onChanged: (value) {},
),
);
}
I want the three of it (prefix,hint text, suffix) should be aligned.
Here is the image for the preview of the textformfield
https://prnt.sc/BxYxnZx1G5od
I was used this type of textformfield please see the reference below:
TextFormField(
controller: textEditingController,
cursorColor: AppTheme.secondaryColor,
autofocus: true,
onChanged: (txt) {
},
style: const TextStyle(
fontSize: 16.0, color:
Color.fromARGB(255,4,4,4)),
decoration: InputDecoration(
border: InputBorder.none,
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: AppTheme.secondaryColor_30,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: const BorderSide(
color: AppTheme.secondaryColor_30,
),
),
hintText:
StringConstants.searchForAGroupOrFriend,
hintStyle: Theme.of(context)
.textTheme
.caption!
.copyWith(color: AppTheme.grey2),
fillColor: AppTheme.secondaryColor_10,
contentPadding: const EdgeInsets.only(top: 10),
filled: true,
prefixIcon: GestureDetector(
onTap: () {
},
child: Image.asset(
Assets.icBackRound,
scale: 3.5,
color: AppTheme.backDarkGrey,
),
),
suffixIcon: GestureDetector(
child: Image.asset(
Assets.searchIcon,
color: AppTheme.secondaryColor,
scale: 3.5,
),
onTap: () {
},
),
),
),

How to show/hide password in TextField? FLUTTER

TextField(
keyboard Type: TextInputType.emailAddress,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none),
filled: true,
hintText: "Mot de passe",
prefixIcon: Icon(
Icons.lock,
color: Color(0xfff28800),
),
),
),
this is my code and I want to add the icon that control the show/hide password in flutter
Live demo on dartpad
// define value
bool _isObscure = true;
...
//then in your form use like this
TextField(
obscureText: _isObscure,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none),
filled: true,
hintText: "Mot de passe",
prefixIcon: Icon(
Icons.lock,
color: Color(0xfff28800),
),
suffix: IconButton(
padding: const EdgeInsets.all(0),
iconSize: 20.0,
icon: _isObscure
? const Icon(
Icons.visibility_off,
color: Colors.grey,
)
: const Icon(
Icons.visibility,
color: Colors.black,
),
onPressed: () {
setState(() {
_isObscure = !_isObscure;
});
},
),
),
try this
bool obscurePassword = true;
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: true,
appBar: AppBar(),
body: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
TextField(
keyboardType: TextInputType.emailAddress,
obscureText: obscurePassword,
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8.0),
borderSide: BorderSide.none),
filled: true,
hintText: "Mot de passe",
prefixIcon: InkWell(
onTap: () {
obscurePassword = !obscurePassword;
setState(() {});
},
child: Icon(
obscurePassword ? Icons.lock : Icons.lock_open,
color: Color(0xfff28800),
),
),
),
),
],
),
);

how do i make the flutter textfield shorter and not goes behind the clear button?

how do i make the textfield shorter and not goes behind the clear button?
Stack(
alignment: AlignmentDirectional.centerEnd,
children: [
TextField(
textInputAction: TextInputAction.search,
controller: controller,
focusNode: focusNode,
autofocus: true,
onChanged: (text) {
text.length >= 4
? provider.fetchBySearchName(text)
: buildNoData();
},
decoration: InputDecoration(
labelText: 'Search',
labelStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
)
),
),
IconButton(
onPressed: clearText,
color: Theme.of(context).primaryColor,
icon: Icon(Icons.cancel_outlined)
)
],
),
Try below code and use suffixIcon for text overlapping issue
TextFormField(
decoration: InputDecoration(
labelText: 'Search',
hintText: 'Search Here',
suffixIcon: IconButton(
onPressed: () {
print('Button Pressed');
//put your clear function here
},
icon: Icon(
Icons.cancel_outlined,
),
),
/*suffixIcon: InkWell(
onTap: () {
print('Button Pressed');
//put your clear function here
},
child: Icon(
Icons.cancel_outlined,
),
),*/
border: OutlineInputBorder(),
),
),
Result
put IconButton on suffixIcon.
TextField(
textInputAction: TextInputAction.search,
controller: controller,
focusNode: focusNode,
autofocus: true,
onChanged: (text) {
text.length >= 4
? provider.fetchBySearchName(text)
: buildNoData();
},
decoration: InputDecoration(
suffixIcon: IconButton(
onPressed: clearText,
color: Theme.of(context).primaryColor,
icon: Icon(Icons.cancel_outlined)
),
labelText: 'Search',
labelStyle: TextStyle(color: Colors.white),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(width: 2, color: Theme.of(context).primaryColor),
// borderRadius: BorderRadius.circular(10),
)
),
),

Flutter "Hint Text" Animation

i would like to animtate "Hint text" in "InputDecoration". I found "Animated_text_kit" which alove to animate text, but i don't know how to implement this in inputDecoration - Hint text
Here is my InputDecoration Code:
decoration: InputDecoration(
enabledBorder: inputBorderDecoration,
alignLabelWithHint: true,
focusedBorder: focusedBorder,
suffixIcon: isWriting
? null
: IconButton(
icon: Image.asset('assets/images/microphone.png'),
color: Colors.black,
onPressed: () {
print('microphone taped');
}),
hintText: "Message...",
hintStyle: TextStyle(color: AppColor.darkGrey, fontSize: 18),
border: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.red.withOpacity(0.2),
),
borderRadius: BorderRadius.circular(15),
),
contentPadding:
EdgeInsets.symmetric(horizontal: 10, vertical: 0),
filled: true,
fillColor: Colors.white.withOpacity(0.3),
),

How to add search icon to TextField in Flutter?

Is it possible to display hint in the TextField as in the image below?
Try below code hope its helpful to you. Used prefixIcon for that.
TextField(
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(),
hintText: 'Search Tech Talk',
),
),
Your result screen->
there is no proper way to add icon in hint, but you can try this alternative, use rich text on textfield as hint text, hide when tap on textfield and show with condition when textfield is empty and keyboard is hide:
Stack(
alignment: AlignmentDirectional.center,
children: [
Offstage(
offstage: _isHide,
child: IgnorePointer(
ignoring: true,
child: Text.rich(
TextSpan(
children: [
WidgetSpan(
child: Icon(
Icons.search,
color: Colors.grey,
),
),
TextSpan(
text: "blablablablabla",
style: TextStyle(color: Colors.grey),
),
],
),
),
),
),
TextField(onTap: () {
_isHide = true;
setState(() {});
}),
],
),
TextField(
onChanged: (value){
searchData(st = value.trim().toLowerCase());
// Method For Searching
},
decoration: InputDecoration(
hintText: "Search Data",
prefixIcon: Icon(Icons.search),
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(7.0)),
),
),
),
RESULT
Make use of the Prefix icon property and content padding in the textfield widget
SizedBox(
height: 40.h,
child: TextField(
decoration: InputDecoration(
fillColor: ColorUtils.COLOR_GRAY_AAAAAA[12],
filled: true,
contentPadding: EdgeInsets.symmetric(vertical: 6.h, horizontal: 12.w),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.r)),
borderSide: BorderSide.none,
),
hintText: 'input_order_code'.tr,
hintStyle: TextStyleUtils.sizeText15Weight400().copyWith(color: ColorUtils.COLOR_GRAY_AAAAAA),
prefixIcon: Icon(Icons.search),
),
style: TextStyleUtils.sizeText15Weight400().copyWith(color: ColorUtils.COLOR_GRAY_363636),
),
),
SizedBox(
height: 50,
child: TextField(
cursorHeight: 25,
decoration: InputDecoration(
prefixIcon: Icon(Icons.search),
fillColor: Colors.white,
filled: true,
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(20)),
),
hintText: 'Search Here...'),
),
)