gpt4 book ai didi

firebase - Flutter FirebaseDatabase 运行事务崩溃

转载 作者:IT王子 更新时间:2023-10-29 06:38:00 24 4
gpt4 key购买 nike

我正在尝试使用 Flutter 在 firebase 数据库中运行事务,但出现错误,有人可以帮我解决这个问题吗?

代码:

ref.runTransaction((MutableData transaction) async {
transaction.value = (transaction.value ?? 0) + 1;
return transaction;
});

错误:

E/RepoOperation(16416): Caught Throwable.
E/RepoOperation(16416): java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: FirebaseDatabaseWorker
E/RepoOperation(16416): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605)
E/RepoOperation(16416): at io.flutter.embedding.engine.FlutterJNI.dispatchPlatformMessage(FlutterJNI.java:515)
E/RepoOperation(16416): at io.flutter.embedding.engine.dart.DartMessenger.send(DartMessenger.java:76)
E/RepoOperation(16416): at io.flutter.embedding.engine.dart.DartExecutor.send(DartExecutor.java:166)
E/RepoOperation(16416): at io.flutter.view.FlutterNativeView.send(FlutterNativeView.java:155)
E/RepoOperation(16416): at io.flutter.plugin.common.MethodChannel.invokeMethod(MethodChannel.java:98)
E/RepoOperation(16416): at io.flutter.plugins.firebase.database.FirebaseDatabasePlugin$1.doTransaction(FirebaseDatabasePlugin.java:345)
E/RepoOperation(16416): at com.google.firebase.database.core.Repo.startTransaction(com.google.firebase:firebase-database@@17.0.0:831)
E/RepoOperation(16416): at com.google.firebase.database.DatabaseReference$4.run(com.google.firebase:firebase-database@@17.0.0:511)
E/RepoOperation(16416): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:458)
E/RepoOperation(16416): at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/RepoOperation(16416): at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
E/RepoOperation(16416): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/RepoOperation(16416): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/RepoOperation(16416): at java.lang.Thread.run(Thread.java:764)

提前致谢。

最佳答案

我在使用 flutter dev channel 时遇到了同样的错误。转到 stable channel 为我修复了它。要检查你在哪个 channel ,请执行 flutter channel

要切换到稳定 channel ,请执行以下操作:

flutter channel stable
flutter upgrade

关于firebase - Flutter FirebaseDatabase 运行事务崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56209091/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com