flutter_dialogflow
flutter_dialogflow copied to clipboard
detectIntent function ERROR
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
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.
I am also facing exactly same issues.. Exception has occurred. NoSuchMethodError (NoSuchMethodError: The method '[]' was called on null. Receiver: null Tried calling: )
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');
}
}
}
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