How to retrieve response of INSERT in supabase without execute - flutter

I tried to use the new system in my flutter application using the supabase_flutter: ^1.4.0 package
It works but I have no response about the insertion
final response = await supabase
.from('order')
.insert(tmp)
;
the response is always null.
For example how can I get the progressive id of my insertion in table order?

I feel so dumb...
Simply adding the
.select()
clause we will get the resoult from insert
So the complete code look like this
final List<Map<String, dynamic>> response = await supabase
.from('order')
.insert(tmp)
.select();

Related

is it possible to use to where in firebase with flutter

Im trying to retrieve from firebase based on two conditions
`
final medResult = await userMedDB.userMedCollection
.where('userID', isEqualTo: Auth().uID)
.where('name', isEqualTo: medName)
.get();
`
is that code correct??
If you're trying to query google-cloud-firestore (you tagged with firebase-realtime-database, which is a different database) the code is correct.
If your query doesn't work when you add the second condition, you may be missing a composite index that is needed for this query. In that case, can any errors that may happen, log them to the console, and find the link in the error message. This link takes you directly to the Firebase console with all values filled in to create the correct index at the click of a button.

How to save specific field value from Firestore to Flutter

So my problem is that I know how to write in Firebase, update it, and read data... but now I need to get a specific field from a document and save it in some variable or string, and I am stuck there.
Picture of what I need
Here is a field I need to get.
Here is where I need to save it
So I need it to be saved so I can use it in code, specifically as an isEqual value. Because my goal is to display Players that play in that club. And every game its another club.
I found solution:
String? valueFromFirebase;
Future<String?> getData() async{
var a = await clubData.doc('Home').get();
setState(() {
valueFromFirebase= a['homeClubName'];
});
}
So when I need value from field ( in my case homeClubName) I just call string valueFromFirebase where I need it.
firstly you have link you app with firebase then you need to import 3 plugin firebase core plugin firebase Firestore and cloud firebase then you need to in your Main.dart here first you create a Class Then you control it by TextController then you'll post you data After the data will successfully post on firebase then you will get response from firebase.. Actually I'll work on Firebase you can say rule Put Get Update Delete & fetch in other word these are the Queries.

How to get total likes count of a post from supabase backend?

I have two tables one for post and one for likes.
Post table stores all the post information.
Likes table has 3 columns
id,
post_id
user_id
Now I need help to figure out how to get total number of likes of each post through supabase query. I am using react for frontend.
const { data, error } = await supabase
.from('feedback')
.select()
.order('created_on', { ascending: false });
Have you created a supabase client for your project?
if not follow this Doc
https://github.com/supabase/supabase-js
Then import the client into the file you want to retrieve data.
you have left .select() empty. select can be combined with modifiers
for example, you can...
const { data, error } = await supabase
.from('feedback')
.select(`post_id`)`
DOCs for reference: https://supabase.com/docs/reference/javascript/select
You may want to have your likes and post ids on the same table to save yourself from issues. Maybe add another column.
id, post_id user_id, post_likes
however your question is very broad hope this can point you in some of the right directions.

How can I retrieve all row of one column in firebase flutter

I am trying to make a firebase database call to retrieve all row of one particular column in the firebase database of my app and display it in a textbox in my flutter app.
That is, to retrieve all phone numbers in the Users table.
For instance, in SQL we can do like this:
SELECT (PhoneNumers) FROM Users
I am new in flutter/dart, I need some help.
Its really easy.
First of all, setup and initialize firebase in you project. Then make a function and create an instance of firestore like this
FirebaseFirestore firestore = FirebaseFirestore.instance;
Then make something called Collection reference:
CollectionReference users = await firestore.collection("users").get().then((querySnapshot) {
querySnapshot.docs.forEach((doc) {
print(doc["PhoneNumber"].toString())
});
This will grab every collection from Users, loop over them and then print out the document PhoneNumber to console. There is no way to just get a single document field from firestore. It might seem weird, but its quite useful at times. Right now, you have access to every document field of every user of your app.

How do I read data from the Flutter Firebase Real-Time Database?

I've used the Real-Time Database with this setup:
->users
->uid
->name
->email
->other info
If I wanted to save the user data I would use my User class and then set the object in the database like this:
final FirebaseUser user = await FirebaseAuth.instance.currentUser();
FirebaseDatabase.instance.reference().child("kullanıcılar").child(user.uid).child("takip").set({"uid":"uid"});
I tried it and it works fine.
But how can I retrieve these values from the database? For instance, once I set a User object as shown above, I may want to retrieve the user's email. I don't mean getting the email through the sign-in provider. I want the email through the real-time database. I've tried working this out for a while now but the documentation isn't helping much. All it shows is to setup listeners in order to wait for changes to the data. But I'm not waiting for changes, I don't want a listener. I want to directly get the values in the database by using the keys in the JSON tree. Is this possible via the real-time database? If so, how can it be done because either the documentation doesn't explain it or I'm just not understanding it.Thanks.
You can retrieve the value once using .once(). Here's an example: https://github.com/flutter/plugins/blob/master/packages/firebase_database/example/lib/main.dart#L62
or better, with async/await:
Future<String> getEmail() async {
String result = (await FirebaseDatabase.instance.reference().child("path/to/user/record/email").once()).value;
print(result);
return result;
}
You can't retrieve the single value from firebase, it always return the DocumentSnapshot of the whole record. You can get a single record from user table by using user id like this:
getData() async {
final FirebaseUser user = await _firebaseAuth.currentUser();
return await FirebaseDatabase.instance.reference().child('user').equalTo(user.uid);
}
Get it like this:
getData().then((val){
print(val.email);
});