How is Null Safety in this code
class EditProduct extends StatelessWidget {
final _formKey = GlobalKey<FormState>();
The line of code with the problem: _formKey.currentState!.validate()
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
updateProduct().then((value) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomePage()));
});
}
},
child: Text("save"))
3
Answers
to use form key you need to add the Form widget and into that widget, you need to pass formKey in the property key like this :
Have you assigned
_formkey
inside the form widget?Try the following code: