I have cloned this project from Github https://github.com/neon97/chatbot_dialogflow but I am not getting a response from the bot.

I have added the correct Dialogflow JSON credentials to the YAML folder, and they seem to be fine. Any help would be much appreciated.

Below I am adding code of main.dart and pubspec

Main.dart

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

void main() {
  runApp(MaterialApp(
    home: MyApp(),
    debugShowCheckedModeBanner: false,
  ));
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  void response(query) async {
    AuthGoogle authGoogle = await AuthGoogle(
            fileJson: "assets/smartstudentguide-vfml-3892228c2f8e.json")
        .build();
    Dialogflow dialogflow =
        Dialogflow(authGoogle: authGoogle, language: Language.english);
    AIResponse aiResponse = await dialogflow.detectIntent(query);
    setState(() {
      messsages.insert(0, {
        "data": 0,
        "message": aiResponse.getListMessage()[0]["text"]["text"][0].toString()
      });
    });
  }

  final messageInsert = TextEditingController();
  // ignore: deprecated_member_use
  List<Map> messsages = List();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(
          "Smart Student Guide",
        ),
        backgroundColor: Colors.deepOrange,
      ),
      body: Container(
        child: Column(
          children: <Widget>[
            Flexible(
                child: ListView.builder(
                    reverse: true,
                    itemCount: messsages.length,
                    itemBuilder: (context, index) => chat(
                        messsages[index]["message"].toString(),
                        messsages[index]["data"]))),
            Divider(
              height: 5.0,
              color: Colors.deepOrange,
            ),
            Container(
              padding: EdgeInsets.only(left: 15.0, right: 15.0),
              margin: const EdgeInsets.symmetric(horizontal: 8.0),
              child: Row(
                children: <Widget>[
                  Flexible(
                      child: TextField(
                    controller: messageInsert,
                    decoration: InputDecoration.collapsed(
                        hintText: "Send your message",
                        hintStyle: TextStyle(
                            fontWeight: FontWeight.bold, fontSize: 18.0)),
                  )),
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 4.0),
                    child: IconButton(

                        icon: Icon(

                          Icons.send,
                          size: 30.0,
                          color: Colors.deepOrange,
                        ),
                        onPressed: () {
                          if (messageInsert.text.isEmpty) {
                            print("empty message");
                          } else {
                            setState(() {
                              messsages.insert(0,
                                  {"data": 1, "message": messageInsert.text});
                            });
                            response(messageInsert.text);
                            messageInsert.clear();
                          }
                        }),
                  )
                ],
              ),
            ),
            SizedBox(
              height: 15.0,
            )
          ],
        ),
      ),
    );
  }

  //for better one i have use the bubble package check out the pubspec.yaml

  Widget chat(String message, int data) {
    return Padding(
      padding: EdgeInsets.all(10.0),
      child: Bubble(
          radius: Radius.circular(15.0),
          color: data == 0 ? Colors.deepOrange : Colors.orangeAccent,
          elevation: 0.0,
          alignment: data == 0 ? Alignment.topLeft : Alignment.topRight,
          nip: data == 0 ? BubbleNip.leftBottom : BubbleNip.rightTop,
          child: Padding(
            padding: EdgeInsets.all(2.0),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                CircleAvatar(
                  backgroundImage: AssetImage(
                      data == 0 ? "assets/bot.png" : "assets/user.png"),
                ),
                SizedBox(
                  width: 10.0,
                ),
                Flexible(
                    child: Text(
                  message,
                  style: TextStyle(
                      color: Colors.white, fontWeight: FontWeight.bold),
                ))
              ],
            ),
          )),
    );
  }
}

pubspec.yaml

name: chatbot_dialogflow
description: A new Flutter project.
publish_to: 'none' 

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.3
  flutter_dialogflow: ^0.1.3
  bubble: ^1.1.9+1

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:

  uses-material-design: true

  assets:
    - assets/smartstudentguide-vfml-3892228c2f8e.json
    - assets/bot.png
    - assets/user.png

I have made the services account and created the JSON credentials and downloaded the file and added it to the assets folder application runs successfully but the bot is not responding to queries. Please help me with I am new to flutter and I just have started learning it. Thanks in advance.


Solution 1: manas mohanty

I don't know exact problem in your code . Just to contribute. ,I want to mention this repos. This approach works perfect for me for integrating a dialogflow chatbot in my flutter app

https://github.com/Aditsyal/flutter_chatBot

Just copy the the dialog_flow.dart and fact_message.dart from lib , navigate to FlutterFactsChatBot() class when your widget is pressed. custom chat widget I use is mentioned below.

// page 3 is mentioned FlutterFactsChatbot() in main.dart as route. Widget factBot(BuildContext context) { return Container( alignment: Alignment.bottomRight, child: FloatingActionButton( materialTapTargetSize: MaterialTapTargetSize.padded, child: Center( child: Icon(Icons.chat), ), elevation: 4.0, backgroundColor: Colors.blue, onPressed: () => Navigator.pushNamed(context, '/page3'), ) ); }


Solution 2: Pooja Gcp

If you are still facing the issue with integrating the Dialogflow chatbot into your Flutter app, then there are many platforms that support integrating Dialogflow chatbot.

Following are the steps to achieve the same:

  1. Integrate a Dialogflow chatbot into the third party platform like Kommunicate

  2. Once you finish the bot integration, add the chat feature into your flutter app. Check out the documentation to integrate the chat into the flutter app.