【问题标题】:How to send multiline string from graphQL from flutter?如何从颤动的graphQL发送多行字符串?
【发布时间】:2021-06-15 05:48:56
【问题描述】:

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

我输入的是

Hi
Hello
Hello

显示这个错误

这是我为输入框编写的代码

             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 createComments(String postId, var text) {
    return """
mutation{
  createComment(postId: "$postId", 
  data:{
    text: ""$text"",
  }
  ){
    _id
  }
}
"""
;
  }
              

【问题讨论】:

  • 您能否编辑您的代码以添加您提供该字符串的位置?
  • 确定我要添加它@MikiMints
  • 你也可以提供一个样本comments对象吗?
  • 它是字符串类型
  • 您可以使用 AutoSize 文本小部件并设置最大行数

标签: javascript flutter dart graphql


【解决方案1】:

我们也可以使用额外的空间放置

【讨论】:

    【解决方案2】:

    我猜你正在使用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的文档

    【讨论】:

    • 它表明_resp 没有在任何地方使用,第二个字符串不能分配给文档
    • 我认为文档应该是文档节点
    • 它是说未来不能被映射到地图
    • @YasharthDubey 您可能使用的是旧版本的flutter_graphql。他们贬低了documentNode,转而支持document
    猜你喜欢
    • 2020-06-07
    • 1970-01-01
    • 2019-10-27
    • 1970-01-01
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-27
    相关资源
    最近更新 更多