I have 8 TextFiled and for each I want to prescribe a focus so that the color changes. But I have an error - The getter 'hasFocus' was called on null. How can I fixed that?
class _EditAccountScreenState extends State<EditAccountScreen> {
FocusNode _focusNodeFio;
FocusNode _focusNodeCompany;
...
@override
void initState() {
super.initState();
_focusNodeFio = FocusNode();
_focusNodeCompany = FocusNode();
...
}
@override
void dispose() {
_focusNodeFio.dispose();
_focusNodeCompany.dispose();
...
super.dispose();
}
@override
Widget build(BuildContext context) {
.......
Padding(
child: TextField(
focusNode: _focusNodeFio,
onTap: () {
setState(() {
FocusScope.of(context).requestFocus(_focusNodeFio);
});
},
decoration: InputDecoration(
labelText: 'Contacts',
labelStyle: TextStyle(
color: _focusNodeFio.hasFocus ? Colors.teal[300] : Colors.grey
),
contentPadding: