I'm a beginner in Flutter and I want to connect my Flutter Web App to Firbase Realtime Database. My goal is to add some sample data inside the database when I click a button.
At this moment I have added inside the web/index.html file the following
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.20.0/firebase-firestore.js"></script>
<script>
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "...",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
In my pubspec.yaml file I have added the following dependencies:
firebase: ^7.3.2
firebase_core: ^0.5.2
firebase_database: ^4.3.0
My main.dart file contains a simple main() function like below
void main() {
runApp(MyApp());
}
And the MyApp() stateless widget.
Do I have to use the .initializeApp() and pass inside it the project's constraints (apiKey, authDomain etc.)?
Can someone give me some hints because i have no idea what to do, i'm pretty much confused at this moment.
Thank you for your time
If you look at the platform support table on firebase.flutter.dev, you'll see that the FlutterFire libraries don't support accessing Realtime Database in web apps yet. Work to add support is under way, but there's no estimate on when it will be released.
For the moment, if you want to use the Firebase Realtime Database in a Flutter web app, you'll have to use the firebase-dart library.
Related
This part
const serviceAccount = require('./firestore-reactdb-027d52fa212f.json');
Results in an error:
Module not found: Error: Can't resolve './firestore-reactdb-027d52fa212f.json' in (...)
I downloaded the json file from IAM & admin > Service accounts in the Cloud Platform Console (as instructed here under "initialize on your own server"). I tried also to download the credentials from the console in firebase (project settings -> service account -> generate new private key).
PS: it's in a react app
Those credentials are needed when you make your own service. React app is not a service read about what service is. If you want to use firebase in react app you don't need those secrets. You need firebase config object and you no need to wory about to sharing it. This config object is necesery for firebase to know where he can send requests etc.
Example object with configurations for firebase.
const firebaseConfig = {
apiKey: "...",
authDomain: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
Error Stack
Possible Related Warning
When using expo with react my project runs fine on web and will access Firestore properly but when using iOS or iOS Simulators it will access firebase.auth() and use that correctly but says is unable to connect to Firestore.
Config File
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
const firebaseConfig = {
apiKey: "XXXXX",
authDomain: "XXXXX",
databaseURL: "XXXXX",
projectId: "XXXX",
storageBucket: "XXXX",
messagingSenderId: "XXXXX",
appId: "1:XXXXXX:web:XXXXXXX"
};
Might have something to do with appId being something: web: something
If more code is needed I can make a repository just thought since it works perfect on web it doesn't have to do with anything except firebase config.
I would like to get data from Firebase. I found some tutorials, but all is using Google Credential ServiceAccount to initialize firebase app. this's is tutorial that i found :
https://medium.com/techwasti/spring-boot-firebase-crud-b0afab27b26e , and else tutorial i found, almost like that too, is using ServiceAccount.
But the problem is i cannot get the ServiceAccount from this firebase because it's from third party. that's mean the owner of firebase don't want to give ServiceAccount.json to me, but they give me firebase config to me, like this :
const firebaseConfig = {
apiKey: "apkey",
authDomain: authdomain",
databaseURL: "databaseurl",
projectId: "projectid",
storageBucket: "storragebucket",
messagingSenderId: "messagesenderid",
appId: "appid",
measurementId: "measurementid"
};
So, how can i initialize this firebase using kotlin in my java springboot aplication?
i had try to find the solution, but not found anything,
I would be glad for any help.
If you want to initialize the Firebase Admin SDK, you will need a service account. There are no alternatives for this.
The config for the front end web app that you're showing here will not work at all. That config is only used for frontend apps that are acting as clients on behalf of the end user.
I have firebase realtime database up and running with my expo app. I'm using the web SDL with the following code in my index.js file.
import * as firebase from 'firebase'
const firebaseConfig = {
apiKey: "XXXXXXXXXX",
authDomain: "XXXXXXXXXX",
databaseURL: "XXXXXXXXXX",
projectId: "XXXXXXXXXX",
storageBucket: "XXXXXXXXXX",
messagingSenderId: "XXXXXXXXXX",
}
firebase.initializeApp(firebaseConfig)
However no information is appearing in the analytics section of my firebase console dashboard. It says,
'Your Analytics data will appear here soon
We're ready to start collecting your Analytics data. Integrate the SDK, and within 24 hours you'll see your first reports.'
But have I not already integrated the SDK in my app with the code above? What am I missing here, is there some other link I need to make between the app and the dashboard?
I want to write a mobile app using react native. And I want to use firebase because it saves me a lot of time. I used firebase before for my web app and it worked pretty well. Now that react native is actually a real native app, I am thinking if I can use firebase features for my app. For example, third-party authentication, deep link, etc. I know that even though all written in Javascript, react native is not web app at all. There are specifically several features I want to use. Google Auth, Cloud Messaging, and some Analytics features. Is there any way I can put them in my app as if I am writing my app in Swift or Java?
First of all you might need to add firebase under dependencies in package.json file
"dependencies": {
"firebase": "^3.9.0",
"react": "^16.0.0-alpha.6",
"react-native": "0.44.0",
},
After that Import firebase
import * as firebase from 'firebase';
Then do the usual firebase initialization
const config = {
apiKey: "xxxxxxxxxx-xxxxxxxxxxxxx",
authDomain: "xxxxxxxxxxx.firebaseapp.com",
databaseURL: "https://xxxxxxxxxx.firebaseio.com",
projectId: "xxxxxxxxxx",
storageBucket: "xxxxxxxxxx.appspot.com",
messagingSenderId: "xxxxxxxxxx"
};
const firebaseApp = firebase.initializeApp(config);
Now that have connected firebase to your react-native app, you can retrieve the contents from the database like this
firebaseApp.database().ref("xxxxxx").on('value', (snap) => {
console.log(snap.val());
});
The remaining can be easily figured out similarly
If you still need more help you can check out the following link : https://firebase.googleblog.com/2016/01/the-beginners-guide-to-react-native-and_84.html