Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detectIntent function ERROR #23

Open
LEOyrh opened this issue Mar 3, 2020 · 4 comments
Open

detectIntent function ERROR #23

LEOyrh opened this issue Mar 3, 2020 · 4 comments

Comments

@LEOyrh
Copy link

LEOyrh commented Mar 3, 2020

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

above error is thrown when a input is sent through the post request.
var response = await authGoogle.post(_getUrl(),
headers: {
HttpHeaders.authorizationHeader: "Bearer ${authGoogle.getToken}"
},
body: body);

CAN SOMEONE FIX THIS ISSUE OR AT LEAST EXPLAIN THE SOLUTION? I"M WILLING TO LISTEN AND LEARN

@0Vipin0
Copy link

0Vipin0 commented Mar 11, 2020

I am facing the same issue. Can't find anything on net that works for this problem.
This package is dead. No maintenance by the author.

@VedantaServer
Copy link

I am also facing exactly same issues.. Exception has occurred.
NoSuchMethodError (NoSuchMethodError: The method '[]' was called on null.
Receiver: null
Tried calling: )

@AlexHartford
Copy link

Hi guys, I recommend you not to use this package and instead use your own implementation.

It's not that much harder, and following this pattern will make use of the best practice googleapis package for accessing your resources, rather than HTTPS as implemented in this package.

Here is a gist of a simple connection & query in the form of a dialogflow provider. I hope it helps!

import 'package:flutter/services.dart';
import 'package:googleapis/dialogflow/v2.dart';
import 'package:googleapis_auth/auth_io.dart';

enum DialogFlowStatus { Uninitialized, Initialized, Error }

class Dialogflow with ChangeNotifier {
  DialogFlowStatus _status = DialogFlowStatus.Uninitialized;
  DialogFlowStatus get status => _status;

  DialogflowApi _dialogFlow;
  DialogflowApi get dialogflow => _dialogFlow;

  Dialogflow.instance() {
    print('Initializing DialogflowApi...');
    init();
  }

  void init() async {
    String _configString = await rootBundle.loadString('<YOUR-DIALOGFLOW-INTEGRATION-JSON>');
    
    final _credentials = ServiceAccountCredentials.fromJson(_configString);
    const _SCOPES = const [DialogflowApi.CloudPlatformScope, DialogflowApi.DialogflowScope];
    final _client = await clientViaServiceAccount(_credentials, _SCOPES);
    
    _dialogFlow = DialogflowApi(_client);
    
    _status = DialogFlowStatus.Initialized;
    notifyListeners();
    print('Successfully initialized DialogflowApi');
  }

  void test() async {
    Map data = {
      "queryInput": {
        "text": {
          "text": "Hello",
          "languageCode": "en"
        }
      }
    };
    
    final request = GoogleCloudDialogflowV2DetectIntentRequest.fromJson(data);
    final session = 'projects/<YOUR-PROJECT-ID>/agent/sessions/<SESSION-ID>'; // session ID can be anything, e.g. 123

    try {
      final test = await _dialogFlow.projects.agent.sessions.detectIntent(request, session);
      print(test.queryResult.fulfillmentText);
    } catch (e) {
      print('error: $e');
    }
  }
}

@ElZombieIsra
Copy link

Hi everyone.

Complementing @AlexHartford response, maybe you do not want to handle every use case in your implementation.

You can use a package that is getting updated constantly like DialogFlowtter

This package is gonna be maintained for a time, and when I'm not able to maintain it anymore, is gonna be donated to Flutter Community to be maintained there.

Feedback is welcome. Greetings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants