flutterflutter-layoutdialogflow-eschatbot

How can I add the suggestion button in my Chatbot?


I am creating a chatbot by Flutter and DialogFlow. Now I want to add some suggestion button into the chat screen right after saying "Hello" like this: suggestion buttons sample

I am a Flutter newbie so I need some ideas to create these buttons. Do you have any idea about this? Thank you a lot


Solution

  • Try this solution!

    (Don't forget to replace YOUR_INTENT_NAME with the correct value.)

    QueryResult result = await DialogflowApi.detectIntent(query, languageCode);
    if (result.intent.displayName == 'YOUR_INTENT_NAME') {
      return Column(
        children: [
          Text(result.fulfillmentText),
          SizedBox(height: 10),
          Wrap(
            spacing: 8.0,
            runSpacing: 4.0,
            children: List<Widget>.generate(
              result.fulfillmentMessages[0].suggestions.suggestions.length,
              (index) => SuggestionChip(
                label: Text(result.fulfillmentMessages[0].suggestions.suggestions[index]),
                onPressed: () => _handleSuggestionTap(result.fulfillmentMessages[0].suggestions.suggestions[index]),
              ),
            ),
          ),
        ],
      );
    }