gpt4 book ai didi

javascript - 如何从 flutter 的graphQL发送多行字符串?

转载 作者:行者123 更新时间:2023-12-03 13:29:09 28 4
gpt4 key购买 nike

我正在尝试将多行支持放在应用程序的评论部分之一,但它不接受它。
我输入的是

Hi
Hello
Hello
它显示了这个错误
this is the error i am getting while putting the above input in the textfield
这是我为输入字段编写的代码
             ListTile(
leading: CircleAvatar(
backgroundImage: AssetImage(UIData.pkImage),
),
title: Container(
constraints: BoxConstraints(
maxHeight: double.infinity,
minHeight: 20,
),
child: TextField(
keyboardType: TextInputType.multiline,
minLines: 1,//Normal textInputField will be displayed
maxLines: 10,// when user presses enter it will adapt to it
decoration: InputDecoration(
suffix: IconButton(
color: Colors.grey,
icon: Icon(Icons.send),
onPressed: () {
createComment();
},
),
hintText: 'Leave a Comment....',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(20.0),
borderSide: BorderSide(color: Colors.teal))),
controller: commentController,
),
),
),
问题在于更新 graphQL 查询并使用 String block 对其进行初始化
String createComments(String postId, var text) {
return """
mutation{
createComment(postId: "$postId",
data:{
text: ""$text"",
}
){
_id
}
}
"""
;
}

最佳答案

我想你正在使用 flutter_graphql .
使用插值生成突变字符串是不好的做法。您应该使用 graphql用于发送带有突变的数据的变量(并且,发送多行字符串没有问题)。
样本:

String createComments(String postId, var text) {
const createCommentMutation = """
mutation createComment(\$postId: String, \$comment:String) {
createComment(postId: \$postId,
data:{
text: \$comment,
}
){
_id
}
}
""";

dynamic _resp = await _graphClient
.mutate(MutationOptions(
document: gql(createCommentMutation),
variables: {
'postId': postId, //Add your variables here
'comment':text
},
));

}
\$postId的类型& \$comment应该与您的 graphql 模式中的相同。我已将它们声明为 String在第一行。
您可以找到相同的文档 here

关于javascript - 如何从 flutter 的graphQL发送多行字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66680731/

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