dialog_flowtter 0.1.0
dialog_flowtter: ^0.1.0 copied to clipboard

A Flutter implementation of DialogFlow, improved


A Flutter implementation of DialogFlow, improved

Pub Package Star on GitHub style: effective dart MIT License MIT License

Installation #

  1. Add the package to your flutter dependencies in you pubspec.yaml:

         dialog_flowtter: ^0.1.0
  2. Make sure you add your dialog_flow_auth.json to the pubspec.yaml assets:

         uses-material-design: true
             - assets/dialog_flow_auth.json
  3. Add your DialogFlow Auth JSON to the assets folder and rename it to dialog_flow_auth.json

  • You can change the name and Path of your JSON later in the code. Just make sure to use the same one in the pubspec.yaml
  1. Get the packages from:

     flutter packages get

Get your keys #

Refer to Create a service account and download the private key file

How to use #

Detect intent #

One of the core features of DialogFlow is to detect what a person is trying to say. You can do that by detecting an intent that you have defined in your DialogFlow console

  1. Create an instance of DialogFlowtter and set the sessionId that will be used to identify the current conversation of the user with DialogFlow.

It's highly recommended that you use a different sessionId for every conversation that the user establishes with the Assistant

    final DialogFlowtter dialogFlowtter = DialogFlowtter(
      sessionId: "YOUR_SESSION_ID_HERE",

(OPTIONAL) Change the JSON path to the one you're using. This defaults to assets/dialog_flow_auth.json.

      jsonPath: "YOUR_JSON_PATH_HERE",
  1. Create a QueryInput where you can specify what data you want to send to DialogFlow.
    final QueryInput queryInput = QueryInput(
      text: TextInput(
        text: "Hi. How are you?",
        languageCode: "en",
  1. Send your input to DialogFlow through the detectIntent function.
    DetectIntentResponse response = await dialogFlowtter.detectIntent(
      queryInput: queryInput,

You can check the code for more info on what info you can send and receive

Be sure to dispose the instance when you're done using it #


Change the project id #

You can change the Project ID that DialogFlowtter will use to find your intents in DialogFlow.

  1. Create an instance of DialogFlowtter
    final DialogFlowtter dialogFlowtter = DialogFlowtter();
  1. Change the projectId prop of the instance;
    dialogFlowtter.projectId = "deimos-apps-0905";
  • Pro tip. You can do the exact same thing as above with the special Dart's cascade notation.

      final DialogFlowtter dialogFlowtter = DialogFlowtter()..projectId = "deimos-apps-0905";

Make authenticated http requests to your DialogFlow project #

You can access the authenticated http client generated by the package by calling the client attribute in your instance.

Keep in mind that this can become null if you have disposed your instance before.

Create your own authenticated http client #

You can get an authenticated, auto refreshing http client with your custom json data if you call the static DialogFlowtter.getClient(yourJson) function.

Keep in mind that this only authenticates with json provided by Google.

Check googleapis_auth for more info.

Further considerations #

The DialogFlowtter class is a singleton, so you don't have to worry about multiple authentication flows being prompted every time you instanciate it.

The class creates an authenticated http client, with the credentials obtained from the DialogFlow Auth JSON, whenever you instanciate the class and saves it for later use.

Memory leaks #

Make sure to dispose your DialogFlowtter instance whenever you're done using it. This makes sure to close the authenticated http client and all its StreamSubscriptions to avoid memory leaks.

Too many models #

We have coded almost every model that you may need to use when implementing this package so you don't have to work with annoying Map<String, dynamic> objects. Feel free to ask for any model that is missing to be added to the package.

The models that were not coded are included as annoying Map<String, dynamic> and are tagged with the //? Create model if necessary.


  • [x] Add support for cards, images, etc.
  • [ ] Secure DialogFlow auth JSON
  • [ ] Support audio queries
  • [ ] Add a catalog of supported languages
  • [ ] Add direct access to common used attributes
  • [ ] Support use of custom HTTP Client

Starware #

DialogFlowtter is Starware.
This means you're free to use the project, as long as you star its GitHub repository.
Your appreciation makes us grow and glow up. ⭐

Contribute #

Your help is always appreciated.

You can contribute by checking our contributing guide or opening an issue.