英文:
How to show/hide password in Widget?
问题
我是中文翻译,以下是您要翻译的内容:
i'm new to flutter and I want a button like interaction which will make password visible and invisible.Can I do it inside TextFormField?
child:TextField(
obscureText: true,
style: TextStyle(
color:Colors.black87
),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top:14),
prefixIcon: Icon(
Icons.lock,
color:Color(0xff992a32)
),
hintText: 'Şifre giriniz.',
hintStyle: TextStyle(
color:Colors.black38
)
),
)
这段代码中,您想要实现在TextField内部点击按钮以显示或隐藏密码的交互效果。可以尝试使用obscureText
属性来实现密码的可见和不可见切换。
英文:
i'm new to flutter and I want a button like interaction which will make password visible and invisible.Can I do it inside TextFormField?
child:TextField(
obscureText: true,
style: TextStyle(
color:Colors.black87
),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.only(top:14),
prefixIcon: Icon(
Icons.lock,
color:Color(0xff992a32)
),
hintText: 'Şifre giriniz.',
hintStyle: TextStyle(
color:Colors.black38
)
),
)
答案1
得分: 0
创建布尔变量isVisible
:
bool isVisible = false;
设置TextFormField
如下所示:
TextFormField(
obscureText: isVisible,
style: const TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding: const EdgeInsets.only(top: 14),
prefixIcon: const Icon(Icons.lock, color: Color(0xff992a32)),
suffixIcon: IconButton(
onPressed: () {
setState(() {
isVisible = !isVisible;
});
},
icon: Icon(
!isVisible ? Icons.visibility : Icons.visibility_off,
color: Theme.of(context).primaryColorDark,
),
),
),
)
英文:
Create bool variable isVisible
:
bool isVisible = false;
setup TextFormField
like this:
TextFormField(
obscureText: isVisible ,
style: const TextStyle(color: Colors.black87),
decoration: InputDecoration(
border: InputBorder.none,
contentPadding:const EdgeInsets.only(top: 14),
prefixIcon:const Icon(Icons.lock, color: Color(0xff992a32)),
suffixIcon: IconButton(
onPressed: () {
setState(() {
isVisible = !isVisible;
});
},
icon: Icon(
!isVisible ? Icons.visibility : Icons.visibility_off,
color: Theme.of(context).primaryColorDark,
),
),
),
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论