1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Firestore saves data locally on device but does not push to Firebase Console

Discussão em 'Mobile' iniciado por Stack, Novembro 7, 2024 às 20:22.

  1. Stack

    Stack Membro Participativo

    I'm working on a Flutter app where I want to save entries into Firebase Firestore under a user-specific subcollection. The data seems to be added successfully on the device, but it never appears in the Firestore Console. Instead, it looks like the data is only cached locally on the device, and I keep seeing the following message in the logs:

    [WatchStream]: (be43146) Stream closed with status: Status{code=NOT_FOUND, description=The database (default) does not exist for project <project_name> Please visit https://console.cloud.google.com/datastore/setup?project=<project_name> to add a Cloud Datastore or Cloud Firestore database. , cause=null}.


    Here’s what I’ve tried:

    1. Firestore Database Setup: I’ve set up Firestore in my Firebase Console and confirmed that I’m using the correct project configuration files (google-services.json for Android).
    2. Firebase Initialization: Firebase is successfully initialized in my app using Firebase.initializeApp().
    3. Permissions and Rules: I've checked the Firestore rules, and they currently allow both read and write operations for authenticated users:

    service cloud.firestore {
    match /databases/{database}/documents {
    match /{document=**} {
    allow read, write: if request.auth != null;
    }
    }
    }


    Here’s the function I use to add data to Firestore:

    void addUrl() async {
    if (urlController.text.isNotEmpty) {
    final currentUser = auth.currentUser;

    if (currentUser != null) {
    await firestore
    .collection('users')
    .doc(currentUser.uid)
    .collection('urls')
    .add({
    'url': urlController.text,
    'timestamp': FieldValue.serverTimestamp(),
    });

    // Clear the text field after adding to Firestore
    urlController.clear();
    } else {
    developer.log("User is not signed in");
    }
    }
    }


    Despite successfully calling this function and clearing the text field, the data only appears to be cached locally on the device. The Firestore Console remains empty.

    Continue reading...

Compartilhe esta Página