简体   繁体   中英

How can i overwrite data in Firebase as a authenticated User with Flutter?

I am working on a mobile App with Flutter and Firebase. My authentication is working fine.

Now, the user should send his name to the firebase. This is also working fine, however if he wants to update his name a new entry is generated instead of overwriting his name.

I tried http.put and http.patch, but in both cases a new entry is generated and the userID is lost.

Here is my Code:

void setName(String name) {
  const url =
      'https://name.europe-west1.firebasedatabase.app/profiles.json';
  http.post(url, body: json.encode({'title': name, 'description': name}));
}

And my change name method

void changeName(String name) {
  const url =
      'https://name.europe-west1.firebasedatabase.app/profiles.json';
  http.put(url, body: json.encode({'title': 'Ein Titel', 'description': name}));
}

This should've been a comment but i think http.patch would do just fine.

See the Firebase documentation for its REST API on updating data for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM