Cannot change region of functions on flutter - firebase

Ive switched my functions regions from the US default and I cannot find a way to call them in flutter?
Is there a method of setting the region on the CloudFunctions instance or when you make the function calls
Thanks for the help.
I have managed to get this to work
CloudFunctions(app: FirebaseApp.instance, region: "europe-west2").getHttpsCallable(functionName: functionName);
But I am no longer using the singleton.
Is this a bad solution?

I don't see what's bad about it. You're doing exactly what you have to do. Just retain the result of CloudFunctions(app: FirebaseApp.instance, region: "europe-west2") in your own singleton if you want to reuse it.

I think the official solution is to use instanceFor:
final result =
await FirebaseFunctions.instanceFor(region: 'europe-west1').httpsCallable('addRental').call(jsonEncode(data));
worked for me, instead of
final result =
await FirebaseFunctions.instance.httpsCallable('addRental').call(jsonEncode(data));

Related

'getDocuments' is deprecated and shouldn't be used

VScode shows warning using getdocument and other functions from the firebase and Firestore. Can anyone please explain why it is showing.enter image description here
Don't worry , just use the function get() instead of getDocuments(). It basically means that the keyword get() is now preferred and supported over the getDocuments()keyword. Just use get() and it will work without any problem.

Wrap async usage with Meteor

I'm trying to wrap an async function inside my Meteor app.
To make it maximum simple I will try to make a basic example (because all I found was kinda more complex that i actly need).
In my app I am trying to do
console.log("1");
my_func(string_to_display);
console.log("2");
As node is async I get logs 1 and 2 before to see the string i sent to the function.
I tried to call it this way
var my_func_sync = Meteor.wrapAsync(my_fync);
var result = my_func_sync(string_to_display);
Most examples here are more complex, with URLs and calls between server/client/other services. I would like to know if there is a way to wrap a simple function that will only send my string to console. Could anyone give me a most basic example ever please? Would be highly appreciated!
I guess using async await can sort the issue.
async my_funct1(){
console.log("1");
await my_func(string_to_display);
console.log("2");
}
Note that you will need to use async with my_funct1() if you need to use await. This will typically wait for the call to return back from myfunc(string_to_display) to proceed to the next line.

Retrieve data from firebase in react native

enter image description hereHow to retrieve data from firebase database and how to assign that values to variables in react native
How can I get these two values into variables using simple way.
I think the firebase docs are pretty good and give a good explanation of how to use it.
https://firebase.google.com/docs/database/web/read-and-write
To be short:
once you have specified a reference, ex. let users = firebase.database().ref('users/' + userId), you can read the data either once using the .once() method or add a listener for changes in the data using on().
You receive a snapshot from either of these methods, and need to call snapshot.val() to retrieve the data.
Simply assign the snapshot.val() to a variable declared outside of the reading method, and you're good to go.
You can also reference a simple project I made using React-Native and firebase here: https://github.com/liplylie/rnChallenge

Could not invoke RNFirebaseFirestore.documentSet

Hi guys I add this error and I don't understand why... I'm using the starter project of react-native-firebase, and I'm trying to use firestore
Although there might be an issue with the library which needs investigating, your code is generally wrong. State in a React component should be data which when changed, causes a re-render. You do not need to assign your collection to state, this can be done as a class property. Also, using a constructor & componentWillMount is wrong as they're essentially the same thing - I don't know enough how it'd handle both cases internally though.
Your code would better work like so:
constructor() {
super();
this.ref = firebase.firestore().collection('users');
}
componentDidMount() {
this.ref.add({ name: 'moo' });
}
I have got same error. Please create the collection with the name 'users' and add a dummy document. Then try.

firebase ios gooffline remove observers

Simple question:
Will all obersvers automatically removed when I use goOffline (disconnect to firebase) ?
If not, is there another way to do it, because removeAllOberserves doesn't seem to work or must I keep an array of single handles?
UPDATE
I answer myself.
removeAllOberserves works well, if you call it with the reference you used to set the observer!
Example:
Firebase *userThreadRef;
userThreadRef = [userRef appendPathComponent: ThreadsPath];
[userThreadRef observeEventType: FEventTypeChildAdded withBlock: ^(FDataSnapshot *snapshot) {
...
}];
....
[userThreadRef removeAllObservers];
Do not use a new reference like this:
Firebase *newUserThreadRef = [userRef appendPathComponent: ThreadsPath];
[newUserThreadRef removeAllObservers];
Will all observers automatically removed when I use goOffline (disconnect to firebase) ?
No. Calling goOffline() will not automatically remove observers/listeners.
is there another way to do it, because removeAllOberserves doesn't seem to work or must I keep an array of single handles?
It's hard to say without seeing your code, but likely your expectations are just wrong.
You'll need to call removeAllObservers() on each reference. The All in the method name is for the fact that it removes the observers for all event types, not for all references.

Resources