Here I am getting this error in _formKey.currentState.;save();this code please help me to resolve
I am new to flutter and I dont have an idea about this
Your code _formKey.currentState!
is telling the system _formKey.currentState
is not null but when it is called, _formKey.currentState
is null. That's why you got the error.
Make you have declared _formKey
in your class and assigned it to a Form
widget before you call _formKey.currentState!
import 'package:flutter/material.dart';
class MyCustomForm extends StatefulWidget {
const MyCustomForm({super.key});
@override
MyCustomFormState createState() {
return MyCustomFormState();
}
}
class MyCustomFormState extends State<MyCustomForm> {
final _formKey = GlobalKey<FormState>(); // Declare _formKey
@override
Widget build(BuildContext context) {
return Form(
key: _formKey, // Assign to Form widget
child: Column(
children: <Widget>[
Text('your other widget'),
],
),
);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.