0

I am trying to generate a response from my chatbot(using dialogflow)

void response(query) async {
    AuthGoogle authGoogle = await AuthGoogle(
        fileJson: "Assets/amigo-pyhyyy-e2d1db5e1ee9.json").build();
    Dialogflow dialogflow = await Dialogflow(
        authGoogle: authGoogle, language: Language.english);
    AIResponse aiResponse = await dialogflow.detectIntent(query);
    setState(() {
      messages.insert(0, {"data": 0,
        "message": aiResponse.getListMessage()[0]["text"]["text"][0].tostring()
      });
    });

I get this error: E/flutter ( 8166): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: NoSuchMethodError: Class 'String' has no instance method 'tostring'.

I tried adding dependencies in the pubspec.yaml: dependencies: to_string: ^1.2.1 dev_dependencies: to_string_generator: ^1.2.1

but instead of getting a reply from the bot on the app, I am still getting a reply on my console.

Please have a look.

OKAYYYYY! I did change all of the instances to .toString() , instead of .tostring() (That was so stupid of me...- __________-)

But now I have an error: ════════ Exception caught by widgets library ═══════════════════════════════════════════════════════ The following assertion was thrown building: type 'String' is not a subtype of type 'Widget'

1 Answers1

1

Looking at the error message, aiResponse.getListMessage()[0]["text"]["text"][0] already returns a String value, so you can remove tostring() Lik Almasfiza already mentioned, normally it's toString() with a capital S, but should not be needed to convert a String to a String.

Mr. Tekneurt
  • 91
  • 1
  • 3