builder 方法上的突变查询需要一个 return 语句,我不确定在哪里以及如何添加到下面的代码中。我相信突变查询应该返回操作的通过或失败。
在过去的几天里,我一直试图弄清楚这一点。我仍然不知道出了什么问题。
我有这个方法,当用户填写一次性代码时,它会在 onCompleted 回调上调用。
createUser 变异查询 -
class GraphQlMutations {
final String createUser = r'''
mutation createUser($uid: ID!, $fullname: String!, $phone: String!, $photourl: String, $createdtime: String){
createUser(uid: $uid, fullname: $fullname, phone: $phone, photourl: $photourl, createdtime: $createdtime){
uid
fullname
phone
photourl
createdtime
}
}
''';
}
void signInWithPhoneAuthCredential(
PhoneAuthCredential phoneAuthCredential) async {
setState(() {
showLoading = true;
});
try {
setState(() {
showLoading = false;
});
final authCredential =
await _auth.signInWithCredential(phoneAuthCredential);
User? user = authCredential.user;
print(user);
if (authCredential.user != null) {
Mutation(
options: MutationOptions(
document: gql(GraphQlMutations().createUser),
onCompleted: (dynamic resultData) {
ScaffoldMessenger.of(context)
.showSnackBar(SnackBar(content: Text('New user added')));
}),
builder: (RunMutation createUser, QueryResult? result) {
if (user != null) {
final DateTime? createdTime = user.metadata.creationTime;
final DateFormat formatter = DateFormat('yyyy-MM-dd');
final String userCreatedTime = formatter.format(createdTime!);
try {
createUser({
'uid': user.uid,
'fullname': _fullname.text,
'phone': user.phoneNumber,
'photourl': 'https://www.bol.com',
'createdtime': userCreatedTime,
});
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => Conversations()));
} catch (e) {}
}
},
);
}
}
}
Vscode 在 builder 方法上指出了一个错误,它准确地说 -
主体可能正常完成,导致返回“null”,但返回类型可能是不可为空的类型。尝试在
请具有 graphq_flutter 专业知识的人提供帮助。
谢谢。