Gustavo Barrios
Gustavo Barrios

Reputation: 73

Firebase_db_web_unofficial dependency

I am trying to enter data into a Firebase RealTime database from web flutter and found that the Firebase_db_web_unofficial dependency works fine for update and delete, but when I try to add a new record I am having trouble and I don't know how to add the registry key, to doing so presents an error.

This is the code I am using

void save() {
    String _codeTMP = _codeController.text;
    FirebaseDatabaseWeb.instance
        .reference()
        .child("Admin")
        .child("Country")
        .child('$_codeTMP')
        .set({
      "name": _nameController.text,
      "currency_code": _currencyController.text,
      "base_fare": _baseFareController.text,
      "per_km": _perKmController.text,
      "per_minute": _perMinuteController.text,
    });
  }

The variable _codeTMP contains the main key of the information that I am appending, that is, it does not exist yet and I am creating it together with the object

enter image description here

the error it throws is the following.

NoSuchMethodError: method not found: 'a' on null
js_primitives.dart:47     at a9E.$0 (http://localhost:56272/main.dart.js:67183:17)
js_primitives.dart:47     at zj.Hk (http://localhost:56272/main.dart.js:39769:16)
js_primitives.dart:47     at Object.eval (eval at akO (http://localhost:56272/main.dart.js:3127:8), <anonymous>:3:55)
js_primitives.dart:47     at fo.MU (http://localhost:56272/main.dart.js:38004:9)
js_primitives.dart:47     at fo.ew (http://localhost:56272/main.dart.js:38009:30)
js_primitives.dart:47     at fo.MH (http://localhost:56272/main.dart.js:38160:14)
js_primitives.dart:47     at fo.FC (http://localhost:56272/main.dart.js:38136:3)
js_primitives.dart:47     at fo.MF (http://localhost:56272/main.dart.js:38099:3)
js_primitives.dart:47     at fo.j7 (http://localhost:56272/main.dart.js:38064:16)
js_primitives.dart:47     at Object.eval (eval at akO (http://localhost:56272/main.dart.js:3131:8), <anonymous>:3:37)

If anyone can help me with this error or has some other way to work web flutter with Firebase Database RealTime I appreciate your help.

Upvotes: 2

Views: 159

Answers (1)

Zeref
Zeref

Reputation: 26

Use the update() method instead of set().

Upvotes: 1

Related Questions