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

[Flutter] Writing to FireStore - how to show error when fails (if no network)

Discussão em 'Mobile' iniciado por Stack, Setembro 27, 2024 às 16:03.

  1. Stack

    Stack Membro Participativo

    I'm writing data to Firestore Using this function - which works perfectly

    Future<void> validateForm() async {
    try {
    await FirebaseFirestore.instance.collection('collectionPath').add({
    'full_name': 'John Doe',
    'company': 'Stokes and Sons',
    'age': '42',
    });
    ScaffoldMessenger.of(context).showSnackBar(successSnackBar);
    } catch (e) {
    print(e.toString());
    ScaffoldMessenger.of(context).showSnackBar(errorSnackBar);
    }
    }


    but I'm trying to display a SnackBar when data can't be written to FireStore

    • currently if I switch my simulator to Airplane Mode the successSnackBar does not show - which is what I want

    But I would also like the errorSnackBar to pop-up too which does not happen

    Continue reading...

Compartilhe esta Página