问题描述
我正在尝试将我的 TextFormField
逻辑移至钩子,但我正在尝试的似乎不起作用。
我的自定义钩子,
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
enum Index { email,password }
TextFormField useTextFormField(Index index) {
return use(_CustomHook(index: index));
}
class _CustomHook extends Hook<TextFormField> {
final Index index;
_CustomHook({@required this.index});
@override
_CustomHookState createState() => _CustomHookState();
}
class _CustomHookState extends HookState<TextFormField,_CustomHook> {
Index index;
@override
TextFormField build(BuildContext context) {
final visible = useState(false);
// useEffect((){
// print('in');
//visible.value=!visible.value;
// print(visible.value.toString());
// return;
// },const []);
return TextFormField(
decoration: InputDecoration(
hintText: 'some help',suffixIcon: IconButton(
onPressed: () {
visible.value = !visible.value;},//<--- here
icon: Icon(visible.value ? Icons.visibility : Icons.visibility_off),)),validator: (text) {
if (text.isEmpty) return 'enter something';
return null;
},obscureText: index == Index.email ? visible.value : true,);
}
}
我是钩子的新手,我不知道我可以使用 useState()
和 useEffect()
,如果有人可以提供帮助
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)