Created
January 18, 2019 20:12
-
-
Save nemethmik/b966abe9c86b49f2889478a5828615b8 to your computer and use it in GitHub Desktop.
Form.of Returning NULL Error Demonstration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import "package:flutter/material.dart"; | |
main() {runApp(MaterialApp(home:HomeScreen()));} | |
class HomeScreen extends StatefulWidget {@override createState() {return _HomeScreen();}} | |
class _HomeScreen extends State<StatefulWidget> { | |
String data; | |
final GlobalKey<FormState> formKey = GlobalKey<FormState>(); | |
@override Widget build(BuildContext context) { | |
return Scaffold( | |
appBar: AppBar(title: Text("Home")), | |
body:Form(key:this.formKey, | |
child:ListView( | |
children: <Widget>[ | |
TextFormField(onSaved: (v){this.data = v;}), | |
RaisedButton(child: Text('Logout'), | |
onPressed: () { | |
//formKey.currentState.save(); | |
Form.of(context).save(); | |
print("********** Data=" + this.data); | |
},), | |
] | |
) | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment