Keyboard appears when click on help icon inside textfield - flutter

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

Related

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

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

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.

How to visible/hide password in flutter?

I have created a login screen for my app but in password field I want a functionality like when I type password its been in * format and in right side a icon on when user click on it, password will be visible, I created a code for it but when I click on password field that icon getting invisible and when password field loose focus that icon appearing again, then how to always show that icon even password field is in focus?
I have provided a snapshot to easily understand the problem.
Here are my login screen code....
import 'package:flutter/material.dart';
import 'package:email_validator/email_validator.dart';
import 'package:secret_keeper/screens/home_screen/Home.dart';
import 'package:secret_keeper/screens/home_screen/passwords/PasswordsNavigation.dart';
import 'package:secret_keeper/screens/signup_page/SignupPage.dart';
class LoginPage extends StatefulWidget{
#override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
String _emailID, _password = "",_email = "abc#gmail.com", _pass = "Try.t.r.y#1";
bool _obscureText = true;
final _formKey = GlobalKey<FormState>();
void _toggle(){
setState(() {
_obscureText = !_obscureText;
});
}
void validateLogin(){
if(_formKey.currentState.validate()){
_formKey.currentState.save();
if(_emailID == _email && _password == _pass){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => Home()));
}
}
}
Widget emailInput(){
return TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
labelText: "Email ID",
labelStyle: TextStyle(fontSize: 14,color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
)
),
),
validator: (email) {
if (email.isEmpty)
return 'Please Enter email ID';
else if (!EmailValidator.validate(email))
return 'Enter valid email address';
else
return null;
},
onSaved: (email)=> _emailID = email,
textInputAction: TextInputAction.next,
);
}
Widget passInput(){
return TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Password",
labelStyle: TextStyle(fontSize: 14,color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
)
),
suffixIcon: IconButton(
icon: Icon(
_obscureText ? Icons.visibility : Icons.visibility_off,
),
onPressed: _toggle,
),
),
validator: (password){
Pattern pattern =
r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!##\$&*~]).{8,}$';
RegExp regex = new RegExp(pattern);
if (password.isEmpty){
return 'Please Enter Password';
}else if (!regex.hasMatch(password))
return 'Enter valid password';
else
return null;
},
onSaved: (password)=> _password = password,
textInputAction: TextInputAction.done,
obscureText: _obscureText,
);
}
#override
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomPadding: false,
backgroundColor: Colors.white,
body: SafeArea(
child: Container(
padding: EdgeInsets.only(left: 16,right: 16),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 50,),
Text("Welcome,",style: TextStyle(fontSize: 26,fontWeight: FontWeight.bold),),
SizedBox(height: 6,),
Text("Sign in to continue!",style: TextStyle(fontSize: 20,color: Colors.grey.shade400),),
],
),
Column(
children: <Widget>[
emailInput(),
SizedBox(height: 16,),
passInput(),
SizedBox(height: 12,),
Align(
alignment: Alignment.topRight,
child: Text("Forgot Password ?",style: TextStyle(fontSize: 14,fontWeight: FontWeight.w600),),
),
SizedBox(height: 30,),
Container(
height: 50,
width: double.infinity,
child: FlatButton(
onPressed: validateLogin,
padding: EdgeInsets.all(0),
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(6),
gradient: LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: [
Color(0xffff5f6d),
Color(0xffff5f6d),
Color(0xffffc371),
],
),
),
child: Container(
alignment: Alignment.center,
constraints: BoxConstraints(maxWidth: double.infinity,minHeight: 50),
child: Text("Login",style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),textAlign: TextAlign.center,),
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
),
),
SizedBox(height: 16,),
Container(
height: 50,
width: double.infinity,
child: FlatButton(
onPressed: (){},
color: Colors.indigo.shade50,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset("assets/images/facebook.png",height: 18,width: 18,),
SizedBox(width: 10,),
Text("Connect with Facebook",style: TextStyle(color: Colors.indigo,fontWeight: FontWeight.bold),),
],
),
),
),
SizedBox(height: 16,),
Container(
height: 50,
width: double.infinity,
child: FlatButton(
onPressed: (){},
color: Colors.indigo.shade50,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(6),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Image.asset("assets/images/facebook.png",height: 18,width: 18,),
SizedBox(width: 10,),
Text("Connect with Facebook",style: TextStyle(color: Colors.indigo,fontWeight: FontWeight.bold),),
],
),
),
),
],
),
Padding(
padding: EdgeInsets.only(bottom: 10),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text("Don't have an account?",style: TextStyle(fontWeight: FontWeight.bold),),
SizedBox(width: 5,),
GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context){
return SignupPage();
}));
},
child: Text("Sign up",style: TextStyle(fontWeight: FontWeight.bold,color: Colors.red),),
)
],
),
)
],
),
),
),
),
);
}
}
Full Example.main login here is:
take a boolean param for detecting if text is obscure or not
change suffix icon based on that boolean value
change the boolean value on suffix item click
below i gave a full example for the task.
bool _passwordInVisible = true; //a boolean value
TextFormField buildPasswordFormField() {
return TextFormField(
obscureText: _passwordInVisible,
onSaved: (newValue) => registerRequestModel.password = newValue,
onChanged: (value) {
if (value.isNotEmpty) {
removeError(error: kPassNullError);
} else if (value.length >= 8) {
removeError(error: kShortPassError);
}
return null;
},
validator: (value) {
if (value.isEmpty) {
addError(error: kPassNullError);
return "";
} else if (value.length < 8) {
addError(error: kShortPassError);
return "";
}
return null;
},
textInputAction: TextInputAction.next,
decoration: InputDecoration(
border: OutlineInputBorder(),
labelText: "Password",
hintText: "Enter your password",
contentPadding: new EdgeInsets.symmetric(vertical: 5.0, horizontal: 15.0),
floatingLabelBehavior: FloatingLabelBehavior.always,
suffixIcon: IconButton(
icon: Icon(
_passwordInVisible ? Icons.visibility_off : Icons.visibility, //change icon based on boolean value
color: Theme.of(context).primaryColorDark,
),
onPressed: () {
setState(() {
_passwordInVisible = !_passwordInVisible; //change boolean value
});
},
),
),
);
}
Here two scenarios come
If you want your suffix icon color constant like always grey, you can give color property of icon, like :
button for password show hide
var passShowButton = GestureDetector(
onLongPressEnd: outContact,
onTapDown: inContact, //call this method when incontact
onTapUp:
outContact, //call this method when contact with screen is removed
child: Icon(
getXHelper.isEmailPasswordUpdate.isTrue
? AppIcons.hidePassword
: AppIcons.hidePassword,
size: 18,
color:Colors.grey
),
);
TextField
TextField(
obscureText: getXHelper.isPassInvisible ,
autocorrect: false,
textAlignVertical: TextAlignVertical.bottom,
decoration: InputDecoration(
enabled: true,
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
border: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
fillColor: Colors.white,
filled: true,
isDense: true,
prefixIconConstraints: BoxConstraints(maxHeight: 18, minHeight: 18),
hintText: "Password",
prefixIcon: Padding(
padding: const EdgeInsets.only(top: 0, right: 12, bottom: 0),
child: Icon(Icons.lock, size: 18, color: Colors.grey),
),
suffixIcon: passShowButton,
),
cursorColor: Colors.black,
style: TextStyle(
color: Colors.black, fontFamily: AppFontFamily.fontFamily),
)
If you want your suffix icon color of your app-Primary Color, will change color when textfield focus, like :
Password show hide button
var passShowButton = GestureDetector(
onLongPressEnd: outContact,
onTapDown: inContact, //call this method when incontact
onTapUp:
outContact, //call this method when contact with screen is removed
child: Icon(
getXHelper.isEmailPasswordUpdate.isTrue
? AppIcons.hidePassword
: AppIcons.hidePassword,
size: 18,
),
);
TextField(
obscureText: getXHelper.isPassInvisible ,
autocorrect: false,
textAlignVertical: TextAlignVertical.bottom,
decoration: InputDecoration(
enabled: true,
errorBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
border: UnderlineInputBorder(
borderSide: BorderSide(color: AppColors.primary)),
fillColor: Colors.white,
filled: true,
isDense: true,
prefixIconConstraints: BoxConstraints(maxHeight: 18, minHeight: 18),
hintText: "Password",
prefixIcon: Padding(
padding: const EdgeInsets.only(top: 0, right: 12, bottom: 0),
child: Icon(Icons.lock, size: 18),
),
suffixIcon: passShowButton,
),
cursorColor: Colors.black,
style: TextStyle(
color: Colors.black, fontFamily: AppFontFamily.fontFamily),
)
you can put text field and icon button in a stack
replace this code with your password textfield.
you can change icon button position to what you want.
Stack(
children: [
TextFormField(
keyboardType: TextInputType.text,
decoration: InputDecoration(
labelText: "Password",
labelStyle:
TextStyle(fontSize: 14, color: Colors.grey.shade400),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.grey.shade300,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.red,
)),
),
validator: (password) {
Pattern pattern =
r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!##\$&*~]).{8,}$';
RegExp regex = new RegExp(pattern);
if (password.isEmpty) {
return 'Please Enter Password';
} else if (!regex.hasMatch(password))
return 'Enter valid password';
else
return null;
},
onSaved: (password) => _password = password,
textInputAction: TextInputAction.done,
obscureText: _obscureText,
),
Positioned(
top: 2,
right: 10,
child: IconButton(
icon: Icon(
_obscureText ? Icons.visibility : Icons.visibility_off,
),
onPressed: () {
setState(() {
_obscureText = !_obscureText;
});
}),
),
],
),
I just copied and run your code and it works just fine. The icon was visible when the password field had focus. You should maybe check your flutter version or it might probably be your emulator device.
flutter --version
Flutter 1.22.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 8874f21e79 (2 weeks ago) • 2020-10-29 14:14:35 -0700
Engine • revision a1440ca392
Tools • Dart 2.10.3
Actually, the suffix icon is visible but when i click on TextFormField then the icon color is changing to white so simply in icon field i added a color property and give a black color to icon so even textfield is in focus its color remain black.

How to hide the things behind the textfield border?

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