-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
886de7a
commit ecfcd74
Showing
8 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# This file tracks properties of this Flutter project. | ||
# Used by Flutter tool to assess capabilities and perform upgrades etc. | ||
# | ||
# This file should be version controlled and should not be manually edited. | ||
|
||
version: | ||
revision: adc687823a831bbebe28bdccfac1a628ca621513 | ||
channel: stable | ||
|
||
project_type: app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This file is deprecated. Tools should instead consume | ||
# `.dart_tool/package_config.json`. | ||
# | ||
# For more info see: https://dart.dev/go/dot-packages-deprecation | ||
# | ||
# Generated by pub on 2021-11-13 20:43:02.858639. | ||
async:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/async-2.8.1/lib/ | ||
boolean_selector:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/boolean_selector-2.1.0/lib/ | ||
characters:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/characters-1.1.0/lib/ | ||
charcode:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/charcode-1.3.1/lib/ | ||
clock:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/clock-1.1.0/lib/ | ||
collection:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/collection-1.15.0/lib/ | ||
crypto:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/crypto-3.0.1/lib/ | ||
cupertino_icons:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/cupertino_icons-1.0.4/lib/ | ||
fake_async:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/fake_async-1.2.0/lib/ | ||
flutter:file:///C:/src/flutter/packages/flutter/lib/ | ||
flutter_dialogflow:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_dialogflow-0.1.3/lib/ | ||
flutter_test:file:///C:/src/flutter/packages/flutter_test/lib/ | ||
googleapis_auth:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/googleapis_auth-0.2.12+1/lib/ | ||
http:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/http-0.12.2/lib/ | ||
http_parser:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/http_parser-3.1.4/lib/ | ||
matcher:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/matcher-0.12.10/lib/ | ||
meta:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/meta-1.7.0/lib/ | ||
path:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/path-1.8.0/lib/ | ||
pedantic:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/pedantic-1.11.1/lib/ | ||
sky_engine:file:///C:/src/flutter/bin/cache/pkg/sky_engine/lib/ | ||
source_span:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/source_span-1.8.1/lib/ | ||
stack_trace:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/stack_trace-1.10.0/lib/ | ||
stream_channel:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/stream_channel-2.1.0/lib/ | ||
string_scanner:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/string_scanner-1.1.0/lib/ | ||
term_glyph:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/term_glyph-1.2.0/lib/ | ||
test_api:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/test_api-0.4.2/lib/ | ||
typed_data:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/typed_data-1.3.0/lib/ | ||
vector_math:file:///C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/vector_math-2.1.0/lib/ | ||
dialogflow_demo_flutter:lib/ |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import 'package:dialogflow_demo_flutter/screens/home_screen.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
void main() { | ||
runApp(MyApp()); | ||
} | ||
|
||
class MyApp extends StatelessWidget { | ||
// This widget is the root of your application. | ||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'Flutter Demo', | ||
theme: ThemeData( | ||
primarySwatch: Colors.blue, | ||
), | ||
home: HomeScreen(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import 'package:flutter/cupertino.dart'; | ||
|
||
class ChatMessage { | ||
String messageContent; | ||
String messageType; | ||
ChatMessage({@required this.messageContent, @required this.messageType}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
import 'package:dialogflow_demo_flutter/models/chat_message.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_dialogflow/dialogflow_v2.dart'; | ||
|
||
class HomeScreen extends StatefulWidget { | ||
@override | ||
_HomeScreenState createState() => _HomeScreenState(); | ||
} | ||
|
||
class _HomeScreenState extends State<HomeScreen> { | ||
List<ChatMessage> messages = []; | ||
TextEditingController _inputMessageController = new TextEditingController(); | ||
Dialogflow dialogflow; | ||
AuthGoogle authGoogle; | ||
ScrollController _scrollController = new ScrollController( | ||
initialScrollOffset: 0.0, | ||
keepScrollOffset: true, | ||
); | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
Future.delayed(Duration.zero, () async { | ||
await initiateDialogFlow(); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
_scrollToBottom(); | ||
return Scaffold( | ||
appBar: AppBar( | ||
elevation: 0, | ||
automaticallyImplyLeading: false, | ||
backgroundColor: Colors.white, | ||
flexibleSpace: SafeArea( | ||
child: Container( | ||
padding: EdgeInsets.only(right: 16), | ||
child: Row( | ||
children: <Widget>[ | ||
IconButton( | ||
onPressed: () {}, | ||
icon: Icon( | ||
Icons.arrow_back, | ||
color: Colors.black, | ||
), | ||
), | ||
SizedBox( | ||
width: 12, | ||
), | ||
Expanded( | ||
child: Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
mainAxisAlignment: MainAxisAlignment.center, | ||
children: <Widget>[ | ||
Text( | ||
"Vignesh Marimuthu", | ||
style: TextStyle( | ||
fontSize: 16, fontWeight: FontWeight.w600), | ||
), | ||
SizedBox( | ||
height: 6, | ||
), | ||
Text( | ||
"Online", | ||
style: TextStyle( | ||
color: Colors.grey.shade600, fontSize: 13), | ||
), | ||
], | ||
), | ||
) | ||
], | ||
), | ||
), | ||
), | ||
), | ||
body: Container( | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
chatSpaceWidget(), | ||
Container( | ||
height: 1.0, | ||
width: double.infinity, | ||
color: Colors.blueGrey, | ||
), | ||
bottomChatView() | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget chatSpaceWidget() { | ||
return Flexible( | ||
child: SingleChildScrollView( | ||
controller: _scrollController, | ||
physics: BouncingScrollPhysics(), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.end, | ||
children: [ | ||
ListView.builder( | ||
itemCount: messages.length, | ||
shrinkWrap: true, | ||
padding: EdgeInsets.only(top: 10, bottom: 10), | ||
physics: NeverScrollableScrollPhysics(), | ||
itemBuilder: (context, index) { | ||
return Container( | ||
padding: EdgeInsets.only( | ||
left: 14, right: 14, top: 10, bottom: 10), | ||
child: Align( | ||
alignment: (messages[index].messageType == "receiver" | ||
? Alignment.topLeft | ||
: Alignment.topRight), | ||
child: Container( | ||
decoration: BoxDecoration( | ||
borderRadius: BorderRadius.circular(20), | ||
color: (messages[index].messageType == "receiver" | ||
? Colors.grey.shade200 | ||
: Colors.blue[200]), | ||
), | ||
padding: EdgeInsets.all(16), | ||
child: Text( | ||
messages[index].messageContent, | ||
style: TextStyle(fontSize: 15), | ||
), | ||
), | ||
), | ||
); | ||
}), | ||
], | ||
), | ||
), | ||
); | ||
} | ||
|
||
Widget bottomChatView() { | ||
return Container( | ||
padding: EdgeInsets.only(left: 10, bottom: 10, top: 10), | ||
height: 60, | ||
width: double.infinity, | ||
child: Row( | ||
children: <Widget>[ | ||
SizedBox( | ||
width: 15, | ||
), | ||
Expanded( | ||
child: TextField( | ||
controller: _inputMessageController, | ||
onSubmitted: (String str) { | ||
fetchFromDialogFlow(str); | ||
}, | ||
decoration: InputDecoration( | ||
hintText: "Write message...", | ||
hintStyle: TextStyle(color: Colors.black54), | ||
border: InputBorder.none), | ||
), | ||
), | ||
SizedBox( | ||
width: 15, | ||
), | ||
FloatingActionButton( | ||
onPressed: () { | ||
fetchFromDialogFlow(_inputMessageController.text); | ||
}, | ||
child: Icon( | ||
Icons.send, | ||
color: Colors.white, | ||
size: 18, | ||
), | ||
backgroundColor: Colors.blue, | ||
elevation: 0, | ||
), | ||
], | ||
), | ||
); | ||
} | ||
|
||
_scrollToBottom() { | ||
WidgetsBinding.instance.addPostFrameCallback((_) { | ||
if (_scrollController.hasClients) { | ||
_scrollController.jumpTo(_scrollController.position.maxScrollExtent); | ||
} | ||
}); | ||
} | ||
|
||
initiateDialogFlow() async { | ||
AuthGoogle authGoogle = | ||
await AuthGoogle(fileJson: "assets/creds.json").build(); | ||
dialogflow = Dialogflow(authGoogle: authGoogle, language: Language.english); | ||
} | ||
|
||
fetchFromDialogFlow(String input) async { | ||
_inputMessageController.clear(); | ||
setState(() { | ||
messages.add(ChatMessage(messageContent: input, messageType: "sender")); | ||
}); | ||
|
||
AIResponse response = await dialogflow.detectIntent(input); | ||
print(response.getMessage()); | ||
messages.add(ChatMessage( | ||
messageContent: response.getMessage(), messageType: "receiver")); | ||
setState(() {}); | ||
} | ||
} |
Oops, something went wrong.