flutter - 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,我感谢您的帮助。
解决方案
使用update()
方法而不是set()
.
推荐阅读
- reactjs - 清单第 1 行,第 1 列,推送到生产时的语法错误
- html - 使文本不超出页脚
- r - 有没有办法保护我在客户拥有的 AWS 账户上运行的 R 代码?
- sql - SQL 插入的时间复杂度和随数据库大小而降低的性能 - pyspark parquet 文件通过 pandas `to_sql()` 到 sql
- data-distribution-service - DDS Fast-RTPS HelloWorldExampleTCP 一个发布者到两个订阅者
- python - /users/login/ 处的 NoReverseMatch
- microsoft-graph-api - Microsoftgraph 要删除许可证的哪些 ID?
- c - 找到两个序列的连接点
- php - PHP 7.2.25 错误!= 错误?
- php - FPDF:在页面末尾添加一些文本