in Education by
Im a beginer in Flutter and here is the problem- im trying to build a form with validation and 'Submit' button which must navigate to a new screen but there is 'NoSuchMethodError: The method 'validate' was called on null' in debuger when i press this button . Here is the code: class _SignInPage extends State { final scaffoldKey = GlobalKey(); final formKey = GlobalKey(); String _email; String _password; void _submit() { final form = formKey.currentState; if (form.validate()) { form.save(); _performLogin(); } } void _performLogin() { Navigator.push( context, MaterialPageRoute(builder: (context) => ConnectPage()), ); } @override Widget build(BuildContext context) { return Scaffold( key: scaffoldKey, body: new Container( margin: new EdgeInsets.symmetric(vertical: 200.0, horizontal: 35.0), padding: EdgeInsets.all(20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.center, key: formKey, children: [ TextFormField( keyboardType: TextInputType.emailAddress, autofocus: false, decoration: InputDecoration( contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), border: OutlineInputBorder( borderRadius: BorderRadius.circular(20.0)), labelText: 'Email'), validator: (val) => !val.contains('@') ? 'Not a valid email.' : null, onSaved: (val) => _email = val, ), TextFormField( autofocus: false, obscureText: true, decoration: InputDecoration( hintText: 'Password', contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0), border: OutlineInputBorder( borderRadius: BorderRadius.circular(20.0)), labelText: 'Password'), validator: (val) => val.length < 6 ? 'Password too short.' : null, onSaved: (val) => _password = val, ), Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ new Row(children: [ FlatButton( child: Text('Sign Up', style: TextStyle(color: Colors.black)), onPressed: () { Navigator.push( context, MaterialPageRoute(builder: (context) => SignUpPage()), ); }, ), FlatButton( child: Text('Sign In', style: TextStyle(color: Colors.black)), onPressed: () { // Navigate to second screen when tapped! }, ), ]), new Row(children: [ Radio( activeColor: Colors.blue, value: Colors.grey, onChanged: (activeColor) {}, ), Text( "Keep me signed in", style: new TextStyle(color: Colors.black), ) ]) ]), RaisedButton( color: Colors.blue, onPressed: _submit, child: new Text('Sign in'), ), ], )), ); } } How can i fix that? How to add space between two forms? JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You have to wrap your TextFormFields with the Form widget. As per docs, Each individual form field should be wrapped in a FormField widget, with the Form widget as a common ancestor of all of those*.

Related questions

0 votes
    Which is the function that is called to validate a data? (a) validate() (b) valid() (c) ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Oct 22, 2021 in Education by JackTerrance
0 votes
    On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    On destruction of a restful resource, I want to guarantee a few things before I allow a destroy operation ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    United Nations Conference on human environment was called at Stockholm from ........ (a) 5th to 16th June, 1972 (b) ... (d) 5th to 16th July 1971 Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    newbie question: how do i make my JSON output ignore null values? I don't want to necessarily set ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    newbie question: how do i make my JSON output ignore null values? I don't want to necessarily set ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    You are converting your HTML file into XHTML Strict. Which code snippet will validate without errors? asked Mar 10, 2023 in Technology by JackTerrance
0 votes
    Hash can be used to validate the input. A. True B. False...
asked Nov 30, 2022 in Education by JackTerrance
0 votes
    I'm using SafetyNet API for checking if device is rooted or not and using the below helpful code but ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 19, 2022 in Education by JackTerrance
0 votes
    I am learning about OAuth2 and OpenID Connect by experimenting with ASP.NET Core and IdentityServer4. So far ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 21, 2022 in Education by JackTerrance
0 votes
    I'm working with ASP.NET 3.5. I have a list box that users must add items to (I've written ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 12, 2022 in Education by JackTerrance
0 votes
    I am trying to pass a dataString to to an ajax call using JQuery. In the call, I construct the ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 11, 2022 in Education by JackTerrance
0 votes
    What was the 2nd stage in perceptron model called? (a) sensory units (b) summing unit (c) association unit (d) output unit Please answer the above question....
asked Sep 21, 2022 in Education by JackTerrance
0 votes
    The first Network was called ________ CNNET NSFNET ASAPNET ARPANET...
asked Jan 10, 2021 in Technology by JackTerrance
...