0

I'm completely new to Flutter and trying to call an asynchronous function. I keep getting

Error: The argument type 'Future<String> Function()'can't be assigned to the parameter type 'String'.

When I try to await the function inside an asynchronous function, it also doesn't work for me. How do I fix this?

 messages.add(ChatMessage(
    messageContent: getCompletionOpenAi(myController.text),
    messageType: "receiver",
));
2
  • messageContent is String? Commented Jun 19, 2022 at 6:14
  • Yes, that's right. Nice name. Commented Jun 19, 2022 at 6:17

1 Answer 1

1

First get the message using await keyword which wait for async mesaage, also mark function as async.

String msg = await getCompletionOpenAi(myController.text)

 messages.add(ChatMessage(
    messageContent: msg,
    messageType: "receiver",
));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.