gpt4 book ai didi

Flutter - 在事件模式下更改 TextFormField 背景(打字)

转载 作者:行者123 更新时间:2023-12-02 18:20:35 32 4
gpt4 key购买 nike

我想实现这个。

enter image description here

当文本表单字段处于非事件状态时,其背景和填充颜色将为灰色。但是当我打字或它处于事件模式时,它的背景颜色将为白色。

如何实现这种行为?

最佳答案

试试这个:

class CustomTextFiled extends StatefulWidget {
const CustomTextFiled({
Key? key,
this.focusNode,
required this.fillColor,
required this.focusColor,
// add whaterver properties that your textfield needs. like controller and ..
}) : super(key: key);

final FocusNode? focusNode;
final Color focusColor;
final Color fillColor;

@override
_CustomTextFiledState createState() => _CustomTextFiledState();
}

class _CustomTextFiledState extends State<CustomTextFiled> {
late FocusNode focusNode;

@override
void initState() {
focusNode = widget.focusNode ?? FocusNode();
focusNode.addListener(() {
setState(() {});
});
super.initState();
}

@override
Widget build(BuildContext context) {
return TextField(
focusNode: focusNode,
decoration: InputDecoration(
filled: true,
fillColor: focusNode.hasFocus ? widget.focusColor : widget.fillColor,
),
);
}
}

关于Flutter - 在事件模式下更改 TextFormField 背景(打字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70941016/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com