Skip to content

Instantly share code, notes, and snippets.

@nemethmik
Created January 18, 2019 20:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemethmik/b966abe9c86b49f2889478a5828615b8 to your computer and use it in GitHub Desktop.
Save nemethmik/b966abe9c86b49f2889478a5828615b8 to your computer and use it in GitHub Desktop.
Form.of Returning NULL Error Demonstration
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