6

I'm trying to use the flutter_dialogflow package with Dialogflow v2. I've taken all the necessary steps in my view. I need help in knowing if I'm missing out on anything.

My Code -

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 sampleQuery = "travel destinations in india";

  void _sendQuery() async {
    try {
    AuthGoogle _authGoogle = await AuthGoogle(fileJson: "assets/dependencies/dialogflow.json").build();
    Dialogflow dialogflow = Dialogflow(authGoogle: _authGoogle, language: Language.english);
    AIResponse response = await dialogflow.detectIntent("hi");
    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)),
       ),
    );
  }
}

Please note:

  1. I've enabled Web API option in Dialogflow Integrations
  2. I've downloaded the JSON file and added it to the directory and assets in pubspec.yaml file
  3. I've checked the path to the file many times (no issues there)
  4. My Google Cloud Console is NOT payment verified (i don't think this should be the concern)
  5. I've NOT verified the OAUTH CONSENT SCREEN as I don't know what to put in the URL for a mobile app

Here's the error log -

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

I believe the issue lies in AIResponse response = await dialogflow.detectIntent("hi"); line of code but can't find out why and how. Maybe I'm missing out on some steps. Thank Youuu!

Abbas
  • 773
  • 6
  • 16

6 Answers6

0

I've just stumbled across the same issue and in my particular case it was because I'd forgot to enable the API inside https://console.developers.google.com/apis/dashboard for the project after creating a new service account.

You would have most likely set up a service account at: https://console.developers.google.com/iam-admin/serviceaccounts

You'd then need to go to: https://console.developers.google.com/apis/library for that the same project an enable DialogFlow.

This may not be your issue but it's worth checking too.

Thanks

0

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.

TopGun
  • 338
  • 2
  • 8
0

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}/

0

I also faced same issue and solved it by adding dialogflow API admin role in service account permissions . While creating service account you have got optional section to add role ,if role have not added then please recreate account and select role(dialogflow API admin) then use new JSON generated

  • Hi, will look into it. It's long since I touched that project cause it was postponed. Anyway, it's good to resolve it. – Abbas Jul 01 '20 at 16:32
  • It worked! My friend and I were struggling to solve this error for more than a week! Thank you so much! :)) – Susca Bogdan Aug 20 '20 at 13:18
0

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

0

image hereGo to settings inside Dialogflow and make sure the project id is the same as that you downloaded the credentials from.