0

so I am trying to create collection with a document in firestore, from variables I collected in Form fiels, code goes:

onPressed:() async {
              await FirebaseFirestore.instance
                  .collection(_ICO).add({
                  "Company name": _compname,
              }).then((_){
                print("success!");
              });

and this is the error code I am getting:

F/crash_dump32(18407): crash_dump.cpp:474] failed to attach to thread 181: Permission denied I/e.firebase_com(17852): Thread[5,tid=17868,WaitingInMainSignalCatcherLoop,Thread=0xe1a8d210,peer=0x13240228,"Signal Catcher"]: reacting to signal 3 I/e.firebase_com(17852): I/e.firebase_com(17852): Wrote stack traces to tombstoned E/flutter (17852): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: NoSuchMethodError: The getter 'isNotEmpty' was called on null. E/flutter (17852): Receiver: null E/flutter (17852): Tried calling: isNotEmpty*

I should also mention that I am logged in with user account while trying to run this code.

Every help is appreciated.

  • Does this answer your question? [flutter: NoSuchMethodError: The getter 'isEmpty' was called on null](https://stackoverflow.com/questions/53777801/flutter-nosuchmethoderror-the-getter-isempty-was-called-on-null) – Martin Zeitler Apr 21 '21 at 00:45
  • if the answer below solved your question mark it accepted as answer ;) – Moaid ALRazhy Apr 21 '21 at 00:47
  • Neither of those solved my problem,was looking into that article already before, as I comented Moaid my rules were already true for everyone – MarkTheBeat Apr 21 '21 at 01:07
  • There's really not enough code to know what's going on, but investigating `_ICO` and `_compname` may reveal something. Please take a moment and review [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) – Jay Apr 21 '21 at 17:33

2 Answers2

1

You can change the rules so that the database is only readable/writeable by authenticated users:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

or

{ "rules": { ".read": true, ".write": true, } }

to be always available , remember to change it in production

Go to database, next go to rules of your database , Change rules to true.

Moaid ALRazhy
  • 1,604
  • 1
  • 3
  • 13
0

Okay so I finally found an answer to my question, it was really stupid mistake or rather 2...

1st:

Widget _buildICO(){
  return TextFormField(
    decoration: InputDecoration(labelText: 'ICO'),
    validator: (String value){
      if (value.isEmpty){
        return 'ICO je potrebné';
      }
    },
    onSaved: (String value){
      ICO = value;
    },
  );

}

Well as you may have already see I have "onSaved" function there which I do not call when pressing the button therefore sending null values.

2nd:

Haven't created proper variable with the right features for this :

Map<String , dynamic> data(){
    return{
   'compname': compname,
   'ICO': ICO,
    };
  }

My button now looks like:

onPressed:() async {
                  if(!_formKey.currentState.validate()){
                    return;
                  }
                  _formKey.currentState.save();
                  firestore
                      .collection(ICO)
                      .doc(compname)
                      .set(data());

I found what was the problem after I got back to it and tried just writing a document into an empty collection and found out that my values returned as null (since u can not create a null collection but you can save null values into document),

Hope my question helps somebody in the future.