flutter_dialogflow icon indicating copy to clipboard operation
flutter_dialogflow copied to clipboard

ERROR: Tried calling: []("queryText")

Open abbas-25 opened this issue 5 years ago • 24 comments

import 'package:flutter/material.dart';
import 'package:flutter_dialogflow/dialogflow_v2.dart';

class Home extends StatefulWidget {
  Home({Key key}) : super(key: key);

  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {

  String query = "hi";

  void _sendQuery() async {
    try {
    AuthGoogle authGoogle = await AuthGoogle(fileJson: "assets/dependencies/dialogflow.json").build();
    Dialogflow dialogflow = Dialogflow(authGoogle: authGoogle,language: Language.ENGLISH);
    print(dialogflow.toString());
    AIResponse response = await dialogflow.detectIntent(query);
    print(response.getMessage());


    } catch(e) {
      print('------------------------------${e.toString()}');
    }
  
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
       appBar: AppBar(
         title: Text('Ask Now'),
       ),
       body: RaisedButton(
         onPressed: _sendQuery,
         color: Colors.black87,
         child: Text('Send Query', style: TextStyle(color: Colors.white)),
       ),
    );
  }
}

ERROR LOG -

I/flutter ( 9861): Instance of 'Dialogflow'
I/flutter ( 9861): ------------------------------NoSuchMethodError: The method '[]' was called on null.
I/flutter ( 9861): Receiver: null
I/flutter ( 9861): Tried calling: []("queryText")

I've taken all the necessary steps in my view. Is there anything missing out? in the code or in the process of GCP Json file downloading. I've not verified the OAuth screen though. And my GCP account is NOT payment verified.

abbas-25 avatar Jan 31 '20 08:01 abbas-25

same here. I found that whenever I type the query string with " ' " single quote that will trigger this error.

EvanFung avatar Feb 01 '20 19:02 EvanFung

same here. I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

abbas-25 avatar Feb 01 '20 20:02 abbas-25

same here. I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

EvanFung avatar Feb 01 '20 20:02 EvanFung

same here. I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

Oh alright. I get it. However, my query string doesn't have any apostrophe or single quotes. Did you verify your OAuth screen? Just trying to know if it's needed.

abbas-25 avatar Feb 01 '20 20:02 abbas-25

same here. I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

Oh alright. I get it. However, my query string doesn't have any apostrophe or single quotes. Did you verify your OAuth screen? Just trying to know if it's needed.

i have't verify my OAuth screen yet.

EvanFung avatar Feb 01 '20 20:02 EvanFung

same here. I found that whenever I type the query string with " ' " single quote that will trigger this error.

You mean the query string should be in double quotes instead of single quotes? Like "hii" and not 'hi'?? Also my code uses double quotes but still it manages to find that error

I mean that the query string includes single quote like [ I'm fine ] or [ thanks' ] that will trigger this error.

Oh alright. I get it. However, my query string doesn't have any apostrophe or single quotes. Did you verify your OAuth screen? Just trying to know if it's needed.

i have't verify my OAuth screen yet.

I'll give it another try.

abbas-25 avatar Feb 02 '20 07:02 abbas-25

I have the same issue. Any solutions?

javieralcantara avatar Feb 14 '20 00:02 javieralcantara

I have the same issue. Any solutions?

No. Can't even find anything on the internet.

abbas-25 avatar Feb 14 '20 17:02 abbas-25

You may get error response from dialogflow. Can you edit the library file

lib/v2/dialogflow_v2.dart (Line No: 134)

print the response. You will get what is the error (Notes: try flutter clean cache and reinstall it).

nandakumar111 avatar Feb 20 '20 06:02 nandakumar111

Any Solutions guys? I want to know what is the API used here so that I can manually get the response here. I tried in the Dialogflow docs but was unable to find anything on how to fetch the response using the API in v2.

0Vipin0 avatar Mar 11 '20 16:03 0Vipin0

Any Solutions guys? I want to know what is the API used here so that I can manually get the response here. I tried in the Dialogflow docs but was unable to find anything on how to fetch the response using the API in v2.

Dialogflow detectIntent API Doc

Check the following code, take it as an example. Here I added payload, inputAudio and outputAudioConfig in body Params. Also I added extra attribute(_audioOutput) in AIResponse class and get attribute value in a function.

class AIResponse {
// Attribute Initialization
...
 String _audioOutput;


  AIResponse({Map body}) {
    ...
    _audioOutput=body['outputAudio'];
  }

 String getOutputAudio() {
    return _audioOutput;
  }
}

...

Future<AIResponse> detectIntent(Map data) async {
    String queryInput = "";
    String queryData = "";
    String outputAudioConfig = "'outputAudioConfig':{'audioEncoding':'OUTPUT_AUDIO_ENCODING_LINEAR_16','synthesizeSpeechConfig':{'voice':{'ssmlGender':'SSML_VOICE_GENDER_FEMALE'}}}";
    if(data["audioData"] != null){
      queryData = "'audioConfig':{'languageCode':'en-US'}";
    }else{
      queryData = "'text':{'text':'${data["query"]}','language_code':'$language'}";
    }
    queryInput = "'queryInput':{$queryData}" + (data["audioData"] != null ? (",'inputAudio': ${data["audioData"]}" ): "");

    String body = "{'queryParams':{'payload':{'userId':'${data["authUserId"]}'}},$queryInput,$outputAudioConfig}";

    var response = await authGoogle.post(_getUrl(),
        headers: {
          HttpHeaders.authorizationHeader: "Bearer ${authGoogle.getToken}"
        },
        body: body
    );
    return AIResponse(body: json.decode(response.body));
  }
...

nandakumar111 avatar Mar 13 '20 20:03 nandakumar111

Any Solutions guys? I want to know what is the API used here so that I can manually get the response here. I tried in the Dialogflow docs but was unable to find anything on how to fetch the response using the API in v2.

If you get error like ERROR: Tried calling: [ ] ( " queryText " ) this, You may get an error in the response. you can also see the error to print response.body in that code.

nandakumar111 avatar Mar 13 '20 20:03 nandakumar111

I'm having the same issue. Did you find any solution?

mrhermina avatar Mar 17 '20 19:03 mrhermina

I'm having the same issue. Did you find any solution?

No

abbas-25 avatar Mar 28 '20 15:03 abbas-25

I found out I didn't saved Service account details in the https://console.cloud.google.com/iam-admin/serviceaccounts with the created JSON key.

Double-check if your account has the key saved.

jmertl avatar Apr 15 '20 13:04 jmertl

Hey i solved it by using Dialogflow v1 just import v1 lib and use it like this

import 'package:flutter_dialogflow/flutter_dialogflow.dart'; Dialogflow dialogflow = Dialogflow(token: "Your Token"); AIResponse response = await dialogflow.sendQuery("Your Query"); print('thing ${response.getMessageResponse()}');

your token can be found here https://dialogflow.cloud.google.com/#/editAgent/{your project id}/

MahmouedMohamed avatar May 16 '20 05:05 MahmouedMohamed

Hey i solved it by using Dialogflow v1 just import v1 lib and use it like this

import 'package:flutter_dialogflow/flutter_dialogflow.dart'; Dialogflow dialogflow = Dialogflow(token: "Your Token"); AIResponse response = await dialogflow.sendQuery("Your Query"); print('thing ${response.getMessageResponse()}');

your token can be found here https://dialogflow.cloud.google.com/#/editAgent/{your project id}/

At that link you get 'Project ID' and 'Service Account'. Where is the token? And if it has to do with the service account, which field is it?

shuyttr avatar Jul 14 '20 21:07 shuyttr

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me....

youraerials avatar Aug 26 '20 05:08 youraerials

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me....

Yarhem waldin waldik <3

yaa9oub avatar Nov 29 '20 01:11 yaa9oub

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me....

Thank you man you're a life saver

taharh avatar Nov 29 '20 03:11 taharh

Guys help i follow all instruction but i have complain ...

E/flutter ( 1598): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: NoSuchMethodError: The method '[]' was called on null. E/flutter ( 1598): Receiver: null E/flutter ( 1598): Tried calling: E/flutter ( 1598): #0 Object.noSuchMethod (dart:core-patch/object_patch.dart:51:5) E/flutter ( 1598): #1 new QueryResult (package:flutter_dialogflow/v2/dialogflow_v2.dart:26:21) E/flutter ( 1598): #2 new AIResponse (package:flutter_dialogflow/v2/dialogflow_v2.dart:64:24) E/flutter ( 1598): #3 Dialogflow.detectIntent (package:flutter_dialogflow/v2/dialogflow_v2.dart:124:12) E/flutter ( 1598): E/flutter ( 1598): #4 _FlutterFactsChatBotState.agentResponse (package:agentai/dialog_flow.dart:51:44) E/flutter ( 1598): E/flutter ( 1598): #5 _FlutterFactsChatBotState._submitQuery (package:agentai/dialog_flow.dart:73:5) E/flutter ( 1598): #6 EditableTextState._finalizeEditing (package:flutter/src/widgets/editable_text.dart:1819:25) E/flutter ( 1598): #7 EditableTextState.performAction (package:flutter/src/widgets/editable_text.dart:1688:9) E/flutter ( 1598): #8 TextInput._handleTextInputInvocation (package:flutter/src/services/text_input.dart:1168:37) E/flutter ( 1598): #9 MethodChannel._handleAsMethodCall (package:flutter/src/services/platform_channel.dart:430:55) E/flutter ( 1598): #10 MethodChannel.setMethodCallHandler. (package:flutter/src/services/platform_channel.dart:383:34) E/flutter ( 1598): #11 _DefaultBinaryMessenger.handlePlatformMessage (package:flutter/src/services/binding.dart:283:33) E/flutter ( 1598): #12 _invoke3. (dart:ui/hooks.dart:280:15) E/flutter ( 1598): #13 _rootRun (dart:async/zone.dart:1190:13) E/flutter ( 1598): #14 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 1598): #15 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter ( 1598): #16 _invoke3 (dart:ui/hooks.dart:279:10) E/flutter ( 1598): #17 _dispatchPlatformMessage (dart:ui/hooks.dart:154:5) E/flutter ( 1598):

daniele777 avatar Dec 21 '20 07:12 daniele777

Had the same issue. For my error happened I downloaded another project service key file. downloaded correct file and issue fixed. make sure to enable dialog flow API and download the correct Service Account JSON file

chamikara1998 avatar Jan 08 '21 03:01 chamikara1998

Nothing still problem i create new key with admin dialogflow

Cattura

but still have problem... help! i created key in json from dialog flow api enabled

daniele777 avatar Feb 03 '21 13:02 daniele777

The docs for this package are not exactly right in the current version of Dialogflow as far as I can tell.

He advises to create a NEW service account and key in the docs, but with the current release of Dialogflow, you actually have to use the EXISTING service account which you can find in the settings for your Agent. That's under the General tab. Click that gear in the top left of dialog flow to get to settings and just under the project id you should see the service account it is actually using. Note what it is called!

From there, you need to go into Service Accounts in the GCP and find that same service account email and click it, then add a key, choose JSON, and download and link as described. This worked for me.

You're a life saver man. Spent around 4-5 hours on this issue. But finally resolved it. For me though, creating a new project with just 1 service account worked. Earlier I was trying to create a service account for an older project.

thisishardik avatar Jun 07 '22 20:06 thisishardik