【发布时间】:2021-05-02 06:24:16
【问题描述】:
我创建并测试了 2 个 GraphQL 突变。我在 Flutter 中使用它们,这样当我点击一个按钮时,它会触发两个突变。当我只将其中一个放在 onPressed 中时没关系,只有一个可以工作。那么如何在 onPressed 中同时调用呢?
我尝试创建类似 function1() 和 function2() 来保存每个突变,但 onPressed 似乎没有执行这些函数。
感谢任何帮助。谢谢。
这部分称为第一个将项目附加到列表的突变。我打电话给addToVol(),但它不会触发第二次突变。
Padding(
padding: EdgeInsets.all(16),
child: GraphQLProvider(
client: graphQLConfiguration.client,
child: CacheProvider(
child: Mutation(
options: MutationOptions(
documentNode: gql(addToSession),
update: (Cache cache, QueryResult result) {
return cache;
},
onCompleted: (dynamic resultData) {
print(resultData);
},
),
builder: (RunMutation runMutation, QueryResult result) {
if (result.hasException) {
print(result.exception.toString());
}
return FlatButton(
onPressed: () async {
if (snapshot.hasData) {
if (_isAuthenticated) {
if (!haveSession) {
runMutation({
'org': activity.org,
'sessionId': activity.id,
'volId': savedOrgValue,
});
// addToVol();
} else {
}
} else {
Navigator.push(
context,
PageRouteBuilder(
pageBuilder: (context, animation1, animation2) => Login(),
transitionDuration: Duration(seconds: 0),
),
);
}
}
},
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(80.0)),
padding: EdgeInsets.all(16),
textColor: Colors.white,
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(80.0)),
),
child: Container(
child: Text('Sign Up for Activity'),
),
),
);
}
)
)
),
),
我在底部有addToVol()。
addToVol() {
GraphQLProvider(
client: graphQLConfiguration.client,
child: CacheProvider(
child: Mutation(
options: MutationOptions(
documentNode: gql(registerSessionToVol),
update: (Cache cache, QueryResult result) {
return cache;
},
onCompleted: (dynamic resultData) {
print(resultData);
},
),
builder: (RunMutation runMutation, QueryResult result) {
if (result.hasException) {
print(result.exception.toString());
}
runMutation({
'org': activity.org,
'sessionId': activity.vid,
'volId': savedOrgValue,
});
return;
}
)
)
);
}
【问题讨论】:
-
能否也添加与您的问题相关的代码?
-
@AliAlizadeh 我已经添加了部分代码,希望它能澄清谢谢