Skip to content

Instantly share code, notes, and snippets.

@PeterHdd
Last active April 11, 2021 11:40
Show Gist options
  • Save PeterHdd/7700b230e2c923df3dec5f3aec6b30a2 to your computer and use it in GitHub Desktop.
Save PeterHdd/7700b230e2c923df3dec5f3aec6b30a2 to your computer and use it in GitHub Desktop.
class _MyHomePageState extends State<MyHomePage> {
final fb = FirebaseDatabase.instance;
final myController = TextEditingController();
final name = "Name";
@override
Widget build(BuildContext context) {
final ref = fb.reference();
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Container(
child: Column(
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(name),
SizedBox(width: 20),
Expanded(child: TextField(controller: myController)),
],
),
ElevatedButton(
onPressed: () {
ref.child(name).set(myController.text);
},
child: Text("Submit"),
),
],
)));
}
@override
void dispose() {
// Clean up the controller when the widget is disposed.
myController.dispose();
super.dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment