visit
2. Complete platform specific configuration
iOS
Android
2. Open ios/Runner.xcworkspace. Keep same Bundle Identifier in xcode project as defined on the firebase console and save GoogleService-info.plist in Runner folder
3. In your IDE or editor, open the file pubspec.yaml. Add dependency for firebase_database and save the file.
dependencies:
flutter:
sdk: flutter
firebase_database: 1.0.3
4. In your IDE or command line with its current directory set to your Flutter app directory, run the following command.
flutter packages get
final databaseReference = FirebaseDatabase.instance.reference();
3. Create a screen with 4 buttons.
RaisedButton(
child: Text('Create Record'),
onPressed: () {
createRecord();
},
),
2. In createRecord(), we create two demo records in database.
void createRecord(){
databaseReference.child("1").set({
'title': 'Mastering EJB',
'description': 'Programming Guide for J2EE'
});
databaseReference.child("2").set({
'title': 'Flutter in Action',
'description': 'Complete Programming Guide to learn Flutter'
});
}
void getData(){
databaseReference.once().then((DataSnapshot snapshot) {
print('Data : ${snapshot.value}');
});
}
3. They are printed on console
Data : [{title: Mastering EJB, description: Programming Guide for J2EE}, {title: Flutter in Action, description: Complete Programming Guide to learn Flutter}]
2. It updates description of title ‘Mastering EJB’ from ‘Programming Guide for J2EE’ to ‘J2EE complete Reference’
import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
class FirebaseDemoScreen extends StatelessWidget {
final databaseReference = FirebaseDatabase.instance.reference();
@override
Widget build(BuildContext context) {
getData();
return Scaffold(
appBar: AppBar(
title: Text('Firebase Connect'),
),
body: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RaisedButton(
child: Text('Create Record'),
onPressed: () {
createRecord();
},
),
RaisedButton(
child: Text('View Record'),
onPressed: () {
getData();
},
),
RaisedButton(
child: Text('Udate Record'),
onPressed: () {
updateData();
},
),
RaisedButton(
child: Text('Delete Record'),
onPressed: () {
deleteData();
},
),
],
)
), //center
);
}
void createRecord(){
databaseReference.child("1").set({
'title': 'Mastering EJB',
'description': 'Programming Guide for J2EE'
});
databaseReference.child("2").set({
'title': 'Flutter in Action',
'description': 'Complete Programming Guide to learn Flutter'
});
}
void getData(){
databaseReference.once().then((DataSnapshot snapshot) {
print('Data : ${snapshot.value}');
});
}
void updateData(){
databaseReference.child('1').update({
'description': 'J2EE complete Reference'
});
}
void deleteData(){
databaseReference.child('1').remove();
}
}
Thanks for reading. If you enjoyed this article, feel free to hit that clap button 👏 to help others find it.
This article is a part of the series of articles related to mobile technology. If you are looking for a Mobile app development team to build your solution, please contact us at .