首页 > 解决方案 > Firebase_db_web_unofficial 依赖

问题描述

我正在尝试从 web flutter 将数据输入到 Firebase RealTime 数据库中,发现 Firebase_db_web_unofficial 依赖项适用于更新和删除,但是当我尝试添加新记录时我遇到了问题,我不知道如何添加注册表项,这样做会出现错误。

这是我正在使用的代码

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,
    });
  }

变量 _codeTMP 包含我要附加的信息的主键,也就是说,它还不存在,我正在与对象一起创建它

在此处输入图像描述

它抛出的错误如下。

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)

如果有人可以帮助我解决这个错误,或者有其他方法可以使用 Firebase Database RealTime 来处理 Web Flutter,我感谢您的帮助。

标签: flutterflutter-dependenciesflutter-web

解决方案


使用update()方法而不是set().


推荐阅读