This file contains hidden or 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
| class _MyHomePageState extends State<MyHomePage> { | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| appBar: AppBar( | |
| title: Text(widget.title), | |
| ), | |
| body: Center( | |
| child: SingleChildScrollView(child: Column( | |
| mainAxisAlignment: MainAxisAlignment.center, |
This file contains hidden or 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
| class _RegisterPetState extends State<RegisterPet> { | |
| final _formKey = GlobalKey<FormState>(); | |
| final listOfPets = ["Cats", "Dogs", "Rabbits"]; | |
| String dropdownValue = 'Cats'; | |
| final nameController = TextEditingController(); | |
| final ageController = TextEditingController(); | |
| final dbRef = FirebaseDatabase.instance.reference().child("pets"); |
This file contains hidden or 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
| child: TextFormField( | |
| controller: nameController, | |
| decoration: InputDecoration( | |
| labelText: "Enter Pet Name", | |
| enabledBorder: OutlineInputBorder( | |
| borderRadius: BorderRadius.circular(10.0), | |
| ), | |
| ), | |
| // The validator receives the text that the user has entered. | |
| validator: (value) { |
This file contains hidden or 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:firebase_core/firebase_core.dart'; | |
| import 'package:firebase_database/firebase_database.dart'; | |
| import 'package:firebase_database_tutorial/home.dart'; | |
| import 'package:flutter/material.dart'; | |
| void main() async { | |
| WidgetsFlutterBinding.ensureInitialized(); | |
| await Firebase.initializeApp(); | |
| runApp(MyApp()); | |
| } |
This file contains hidden or 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
| if (_formKey.currentState.validate()) { | |
| dbRef.push().set({ | |
| "name": nameController.text, | |
| "age": ageController.text, | |
| "type": dropdownValue | |
| }).then((_) { | |
| ScaffoldMessenger.of(context).showSnackBar( | |
| SnackBar(content: Text('Successfully Added'))); | |
| ageController.clear(); | |
| nameController.clear(); |
This file contains hidden or 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
| FutureBuilder( | |
| future: dbRef.once(), | |
| builder: (context, AsyncSnapshot<DataSnapshot> snapshot) { | |
| if (snapshot.hasData) { | |
| lists.clear(); | |
| Map<dynamic, dynamic> values = snapshot.data.value; | |
| values.forEach((key, values) { | |
| lists.add(values); | |
| }); | |
| return new ListView.builder( |
This file contains hidden or 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
| body: StreamBuilder( | |
| stream: dbRef.onValue, | |
| builder: (context, AsyncSnapshot<Event> snapshot) { | |
| if (snapshot.hasData) { | |
| lists.clear(); | |
| DataSnapshot dataValues = snapshot.data.snapshot; | |
| Map<dynamic, dynamic> values = dataValues.value; | |
| values.forEach((key, values) { | |
| lists.add(values); | |
| }); |
This file contains hidden or 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
| "-M0FJ-WJXYDS-TPehYzV" : { | |
| "age" : "4", | |
| "name" : "shadow", | |
| "type" : "Cats" | |
| }, |
This file contains hidden or 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
| "-M0FJHoCBd304XwLc_c-" : { | |
| "age" : "4", | |
| "name" : "bun", | |
| "type" : "Rabbits" | |
| }, |
This file contains hidden or 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
| "-M0FIuRBi5NT1VKsTbQt" : { | |
| "age" : "1", | |
| "name" : "kitty", | |
| "type" : "Cats" | |
| }, | |
| "-M0FJHoCBd304XwLc_c-" : { | |
| "age" : "4", | |
| "name" : "bun", | |
| "type" : "Rabbits" | |
| }, |