Created
January 19, 2019 07:19
-
-
Save nemethmik/8df3743c8eea3c6518b036a38db430e4 to your computer and use it in GitHub Desktop.
A self-contained runnable Flutter example of using StatefulBuilder to make a wrapper context for Form.of (line 21) to return the parent form (line 11)
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"; | |
//https://github.com/flutter/flutter/issues/26772#issuecomment-455674193 | |
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: StatefulBuilder( | |
builder: (context,setState){return | |
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