问题描述
builder 方法上的变更查询需要返回语句,我不确定在何处以及如何将其添加到以下代码中。我相信变异查询应该返回一个通过或失败的操作。
过去几天我一直在努力解决这个问题。我仍然不知道出了什么问题。
我有这个方法,当用户填写一次性代码时,它会在 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',但返回类型可能是不可为 null 的类型。 尝试在
处添加 return 或 throw 语句请在 graphq_Flutter 方面具有专业知识的人提供帮助。
谢谢。