我正在使用flutter v1.7.8 + hotfix.3。我正在创建新用户并将其详细信息添加到firestore数据库中。当我第一次添加用户时,它可以正常工作。当我尝试添加另一个新用户时,出现以下错误,应用崩溃:
E / CloudFirestorePlugin(11070):等待任务超时 E / CloudFirestorePlugin(11070):java.util.concurrent.TimeoutException: 等待任务E / CloudFirestorePlugin(11070)超时:位于
com.google.android.gms.tasks.Tasks.await(未知来源:32)E / CloudFirestorePlugin(11070):在 io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin $ 4.apply(Cl> oudFirestorePlugin.java:409) E / CloudFirestorePlugin(11070):在 io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin $ 4.apply(Cl> oudFirestorePlugin.java:361) E / CloudFirestorePlugin(11070):在 com.google.firebase.firestore.FirebaseFirestore.lambda $ runTransaction $ 1(co> m.google.firebase:firebase-firestore @@ 19.0.0:283) E / CloudFirestorePlugin(11070):在 com.google.firebase.firestore.FirebaseFirestore $$ Lambda $ 3.call(未知 来源:6)E / CloudFirestorePlugin(11070):位于> com.google.android.gms.tasks.zzv.run(未知来源:2)E / CloudFirestorePlugin(11070):位于 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:> 1167) E / CloudFirestorePlugin(11070):在 java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java>:641) E / CloudFirestorePlugin(11070):在 java.lang.Thread.run(Thread.java:764)D / AndroidRuntime(11070):关闭VM E / AndroidRuntime(11070):致命异常:main E / AndroidRuntime(11070):进程:com.example.task_manager,PID:11070 E / AndroidRuntime(11070):java.lang.IllegalStateException:回复 已>已提交E / AndroidRuntime(11070): io.flutter.embedding.engine.dart.DartMessenger $ Reply.reply(DartMessenger.j> ava:135) E / AndroidRuntime(11070):在 io.flutter.plugin.common.MethodChannel $ IncomingMethodCallHandler $ 1.error(M> ethodChannel.java:230) E / AndroidRuntime(11070):在 io.flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin $ 3.onComple> te(CloudFirestorePlugin.java:427) E / AndroidRuntime(11070):在 com.google.android.gms.tasks.zzj.run(未知来源:4)E / AndroidRuntime(11070):在 android.os.Handler.handleCallback(Handler.java:873)E / AndroidRuntime(11070):at android.os.Handler.dispatchMessage(Handler.java:99)E / AndroidRuntime(11070):位于android.os.Looper.loop(Looper.java:193) E / AndroidRuntime(11070):在 android.app.ActivityThread.main(ActivityThread.java:6669)E / AndroidRuntime(11070):位于java.lang.reflect.Method.invoke(本机 方法)E / AndroidRuntime(11070):at> com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.ja> va:493) E / AndroidRuntime(11070):在 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)I / Process(11070):正在发送信号。 PID:11070 SIG:9应用 完成。
我正在使用以下代码添加新用户:
_sendToServer() {
if (_formKey.currentState.validate()) {
//No error in validator
_formKey.currentState.save();
Firestore.instance.runTransaction((Transaction transaction) async {
DocumentReference reference =
Firestore.instance.collection('Users').document(_name);
await transaction.get(reference);
await reference.setData({
"Name": "$_name",
"Email": "$_email",
"Password": "$_password",
"status": "new",
"clientName": widget.title
});
});
registerUser();
}
}
registerUser() async {
String userId =
await widget.auth.createUserWithEmailAndPassword(_email, _password);
if (_formKey.currentState.validate()) {
//No error in validator
_formKey.currentState.save();
Firestore.instance.runTransaction((Transaction transaction) async {
DocumentReference reference =
Firestore.instance.collection('UserRoles').document(_name);
await transaction.get(reference);
await reference
.setData({"userid": "$userId", "role": "user", "status": "new"});
});
Navigator.pop(context);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => AdminPage(
auth: widget.auth,
onSignedOut: widget.onSignedOut,
title: widget.title,
)));
}
}
我尝试使用颤动清洁。但是它只能工作一次。
任何帮助将不胜感激!