I am trying put multiline support in one of the comment section of app and it is not accepting it.
the input which i put is
JavaScript
x
4
1
Hi
2
Hello
3
Hello
4
and it is showing this error
And this is the code i am writing for the inputfield
JavaScript
1
30
30
1
ListTile(
2
leading: CircleAvatar(
3
backgroundImage: AssetImage(UIData.pkImage),
4
),
5
title: Container(
6
constraints: BoxConstraints(
7
maxHeight: double.infinity,
8
minHeight: 20,
9
),
10
child: TextField(
11
keyboardType: TextInputType.multiline,
12
minLines: 1,//Normal textInputField will be displayed
13
maxLines: 10,// when user presses enter it will adapt to it
14
decoration: InputDecoration(
15
suffix: IconButton(
16
color: Colors.grey,
17
icon: Icon(Icons.send),
18
onPressed: () {
19
createComment();
20
},
21
),
22
hintText: 'Leave a Comment....',
23
border: OutlineInputBorder(
24
borderRadius: BorderRadius.circular(20.0),
25
borderSide: BorderSide(color: Colors.teal))),
26
controller: commentController,
27
),
28
),
29
),
30
The problem is with updating the graphQL query and initializing it with String block
JavaScript
1
16
16
1
String createComments(String postId, var text) {
2
return """
3
mutation{
4
createComment(postId: "$postId",
5
data:{
6
text: ""$text"",
7
}
8
){
9
_id
10
}
11
}
12
"""
13
;
14
}
15
16
Advertisement
Answer
I presume you are using flutter_graphql.
It is bad practice to generate mutation strings using interpolation. You should use graphql
variables for sending data with mutations (And, there is no problem in sending a multi-line string).
Sample:
JavaScript
1
24
24
1
String createComments(String postId, var text) {
2
const createCommentMutation = """
3
mutation createComment($postId: String, $comment:String) {
4
createComment(postId: $postId,
5
data:{
6
text: $comment,
7
}
8
){
9
_id
10
}
11
}
12
""";
13
14
dynamic _resp = await _graphClient
15
.mutate(MutationOptions(
16
document: gql(createCommentMutation),
17
variables: {
18
'postId': postId, //Add your variables here
19
'comment':text
20
},
21
));
22
23
}
24
The type of $postId
& $comment
should be same as that of in your graphql schema. I have declared them as String
on the very first line.
You can find the documentation of the same here