Flutter Dialogflow机器人程序没有响应

Flutter Dialogflow机器人程序没有响应,flutter,dart,dialogflow-es,flutter-layout,Flutter,Dart,Dialogflow Es,Flutter Layout,我一直在关注这一点,但我似乎无法让我的机器人做出响应。我收到以下附加信息: 我已经将正确的dialogflow json凭据添加到yaml文件夹,它们看起来很好 任何帮助都将不胜感激。我是个新手,所以我还是试着去了解一切 代码库: import 'package:flutter/material.dart'; import 'package:flutter_dialogflow/dialogflow_v2.dart'; void main() => runApp(new MyApp()

我一直在关注这一点,但我似乎无法让我的机器人做出响应。我收到以下附加信息:

我已经将正确的dialogflow json凭据添加到yaml文件夹,它们看起来很好

任何帮助都将不胜感激。我是个新手,所以我还是试着去了解一切

代码库:

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

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Example Dialogflow Flutter',
      theme: new ThemeData(
        primarySwatch: Colors.deepOrange,
      ),
      debugShowCheckedModeBanner: false,
      home: new HomePageDialogflow(),
    );
  }
}

class HomePageDialogflow extends StatefulWidget {
  HomePageDialogflow({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _HomePageDialogflow createState() => new _HomePageDialogflow();
}

class _HomePageDialogflow extends State<HomePageDialogflow> {
  final List<ChatMessage> _messages = <ChatMessage>[];
  final TextEditingController _textController = new TextEditingController();

  Widget _buildTextComposer() {
    return new IconTheme(
      data: new IconThemeData(color: Theme.of(context).accentColor),
      child: new Container(
        margin: const EdgeInsets.symmetric(horizontal: 8.0),
        child: new Row(
          children: <Widget>[
            new Flexible(
              child: new TextField(
                controller: _textController,
                onSubmitted: _handleSubmitted,
                decoration:
                    new InputDecoration.collapsed(hintText: "Send a message"),
              ),
            ),
            new Container(
              margin: new EdgeInsets.symmetric(horizontal: 4.0),
              child: new IconButton(
                  icon: new Icon(Icons.send),
                  onPressed: () => _handleSubmitted(_textController.text)),
            ),
          ],
        ),
      ),
    );
  }

  void response(query) async {
    _textController.clear();
    AuthGoogle authGoogle =
        await AuthGoogle(fileJson: "assets/credentials.json")
            .build();
    Dialogflow dialogflow =
        Dialogflow(authGoogle: authGoogle, language: Language.english);
    AIResponse response = await dialogflow.detectIntent(query);
    ChatMessage message = new ChatMessage(
      text: response.getMessage() ??
          new CardDialogflow(response.getListMessage()[0]).title,
      name: "Bot",
      type: false,
    );
    setState(() {
      _messages.insert(0, message);
    });
  }

  void _handleSubmitted(String text) {
    _textController.clear();
    ChatMessage message = new ChatMessage(
      text: text,
      name: "Promise",
      type: true,
    );
    setState(() {
      _messages.insert(0, message);
    });
    response(text);
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        centerTitle: true,
        title: new Text("Flutter and Dialogflow"),
      ),
      body: new Column(children: <Widget>[
        new Flexible(
            child: new ListView.builder(
          padding: new EdgeInsets.all(8.0),
          reverse: true,
          itemBuilder: (_, int index) => _messages[index],
          itemCount: _messages.length,
        )),
        new Divider(height: 1.0),
        new Container(
          decoration: new BoxDecoration(color: Theme.of(context).cardColor),
          child: _buildTextComposer(),
        ),
      ]),
    );
  }
}

class ChatMessage extends StatelessWidget {
  ChatMessage({this.text, this.name, this.type});

  final String text;
  final String name;
  final bool type;

  List<Widget> otherMessage(context) {
    return <Widget>[
      new Container(
        margin: const EdgeInsets.only(right: 16.0),
        child: new CircleAvatar(child: new Text('B')),
      ),
      new Expanded(
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            new Text(this.name,
                style: new TextStyle(fontWeight: FontWeight.bold)),
            new Container(
              margin: const EdgeInsets.only(top: 5.0),
              child: new Text(text),
            ),
          ],
        ),
      ),
    ];
  }

  List<Widget> myMessage(context) {
    return <Widget>[
      new Expanded(
        child: new Column(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: <Widget>[
            new Text(this.name, style: Theme.of(context).textTheme.subhead),
            new Container(
              margin: const EdgeInsets.only(top: 5.0),
              child: new Text(text),
            ),
          ],
        ),
      ),
      new Container(
        margin: const EdgeInsets.only(left: 16.0),
        child: new CircleAvatar(
            child: new Text(
          this.name[0],
          style: new TextStyle(fontWeight: FontWeight.bold),
        )),
      ),
    ];
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      margin: const EdgeInsets.symmetric(vertical: 10.0),
      child: new Row(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: this.type ? myMessage(context) : otherMessage(context),
      ),
    );
  }
}
导入“包装:颤振/材料.省道”;
导入“包:颤振_对话框流/对话框流_v2.dart”;
void main()=>runApp(新的MyApp());
类MyApp扩展了无状态小部件{
@凌驾
小部件构建(构建上下文){
返回新材料PP(
标题:“流体颤振示例”,
主题:新主题数据(
primarySwatch:颜色。深橙色,
),
debugShowCheckedModeBanner:false,
主页:新主页DialogFlow(),
);
}
}
类HomePageDialogflow扩展StatefulWidget{
HomePageDialogflow({Key-Key,this.title}):超级(Key:Key);
最后的字符串标题;
@凌驾
_HomePageDialogflow createState()=>new_HomePageDialogflow();
}
类_HomePageDialogflow扩展状态{
最终列表_消息=[];
最终文本编辑控制器_textController=新文本编辑控制器();
小部件_buildTextComposer(){
返回新的IconTheme(
数据:新的IconThemeData(颜色:Theme.of(context.accentColor)),
子容器:新容器(
边距:常量边集。对称(水平:8.0),
孩子:新的一排(
儿童:[
新柔性(
孩子:新文本字段(
控制器:_textController,
未提交:_handleSubmitted,
装饰:
新建InputDecoration.collapsed(hintText:“发送消息”),
),
),
新容器(
边距:新边集。对称(水平:4.0),
孩子:新的图标按钮(
图标:新图标(Icons.send),
按下时:()=>_handleSubmitted(_textController.text)),
),
],
),
),
);
}
无效响应(查询)异步{
_textController.clear();
AuthGoogle AuthGoogle=
等待AuthGoogle(fileJson:“assets/credentials.json”)
.build();
对话流对话流=
Dialogflow(authGoogle:authGoogle,语言:language.english);
AIResponse response=wait dialogflow.detectinent(查询);
ChatMessage message=新建ChatMessage(
文本:response.getMessage()??
新建CardDialogflow(response.getListMessage()[0])。标题,
名称:“机器人”,
类型:false,
);
设置状态(){
_消息。插入(0,消息);
});
}
void\u handleSubmitted(字符串文本){
_textController.clear();
ChatMessage message=新建ChatMessage(
文本:文本,
名称:“承诺”,
类型:对,
);
设置状态(){
_消息。插入(0,消息);
});
答复(案文);
}
@凌驾
小部件构建(构建上下文){
归还新脚手架(
appBar:新的appBar(
标题:对,
标题:新文本(“颤振与对话流”),
),
正文:新列(子项:[
新柔性(
子项:新建ListView.builder(
填充:新边缘设置。全部(8.0),
相反:是的,
itemBuilder:(\u,int index)=>\u消息[索引],
itemCount:_messages.length,
)),
新隔板(高度:1.0),
新容器(
装饰:新盒子装饰(颜色:主题.of(上下文).cardColor),
子项:_buildTextComposer(),
),
]),
);
}
}
类ChatMessage扩展了无状态小部件{
ChatMessage({this.text,this.name,this.type});
最终字符串文本;
最后的字符串名;
最终布尔型;
列出其他消息(上下文){
返回[
新容器(
边距:仅限常量边集(右:16.0),
child:new CircleAvatar(child:new Text('B')),
),
新扩展(
子:新列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
新文本(this.name,
样式:新文本样式(fontWeight:fontWeight.bold)),
新容器(
边距:仅限常量边集(顶部:5.0),
子:新文本(文本),
),
],
),
),
];
}
列表myMessage(上下文){
返回[
新扩展(
子:新列(
crossAxisAlignment:crossAxisAlignment.end,
儿童:[
新文本(this.name,style:Theme.of(context.textTheme.subhead),
新容器(
边距:仅限常量边集(顶部:5.0),
子:新文本(文本),
),
],
),
),
新容器(
边距:仅限常量边集(左:16.0),
孩子:新CircleAvatar(
儿童:新文本(
此.name[0],
样式:新文本样式(fontWeight:fontWeight.bold),
)),
),
];
}
@凌驾
小部件构建(构建上下文){
退回新货柜(
边距:常数边集。对称(垂直:10.0),
孩子:新的一排(
crossAxisAlignment:crossAxisAlignment.start,
子项:this.type?myMessage(上下文):otherMessage(上下文),
),
);
}
}
  • 转到Dialogflow agent设置

  • 点击服务帐户链接,这将打开您的谷歌项目服务帐户

  • 单击您的服务帐户-->添加密钥-->创建新密钥-->JSON并下载

  • 在您的项目中导入JSON文件,并使用以下语句插入链接:

    AuthGoogle AuthGoogle=等待AuthGoogle(fileJson:“json文件的路径”).build()

  • 转到Dialogflow agent设置

  • 点击服务帐户链接,这将打开您的谷歌项目服务帐户

  • 单击您的服务帐户-->添加密钥-->Cre