Skip to content

Commit 62fa4f8

Browse files
committed
added chatbot page
1 parent b881052 commit 62fa4f8

5 files changed

Lines changed: 158 additions & 55 deletions

File tree

lib/chatBotPage.dart

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import 'package:chat_bubbles/bubbles/bubble_normal.dart';
2+
import 'package:chat_bubbles/message_bars/message_bar.dart';
3+
import 'package:flutter/material.dart';
4+
5+
class ChatBotPage extends StatefulWidget{
6+
@override
7+
State<StatefulWidget> createState() => _ChatBotPageState();
8+
9+
}
10+
11+
class _ChatBotPageState extends State<ChatBotPage> {
12+
13+
var chatList = <Widget>[];
14+
15+
final ScrollController _scrollController = ScrollController();
16+
17+
@override
18+
void dispose() {
19+
_scrollController.dispose();
20+
super.dispose();
21+
}
22+
23+
void handleChatSend(String msg) {
24+
final sentChat = BubbleNormal(
25+
text: msg,
26+
isSender: true,
27+
color: Colors.purple,
28+
textStyle: TextStyle(
29+
fontSize: 18,
30+
color: Colors.white
31+
),
32+
);
33+
34+
final responseChat = BubbleNormal(
35+
text: "nodakke yenu illa backendalli", // TODO get response from backend
36+
color: Colors.grey.shade300,
37+
isSender: false,
38+
textStyle: TextStyle(
39+
fontSize: 18
40+
),
41+
);
42+
43+
chatList.add(sentChat);
44+
chatList.add(SizedBox(height: 8,));
45+
chatList.add(responseChat);
46+
chatList.add(SizedBox(height: 8,));
47+
}
48+
49+
@override
50+
Widget build(BuildContext context) {
51+
return Scaffold(
52+
appBar: AppBar(
53+
centerTitle: true,
54+
title: Text("Library chatbot")
55+
),
56+
body: Column(
57+
children: [
58+
Expanded(
59+
child: SingleChildScrollView(
60+
controller: _scrollController,
61+
child: Column(
62+
children: chatList,
63+
),
64+
),
65+
),
66+
CustomMessageBar(
67+
onSend: (msg) {
68+
setState(() {
69+
handleChatSend(msg);
70+
});
71+
WidgetsBinding.instance.addPostFrameCallback((_) {
72+
_scrollController.animateTo(
73+
_scrollController.position.maxScrollExtent,
74+
duration: Duration(milliseconds: 200),
75+
curve: Curves.easeOut,
76+
);
77+
});
78+
},
79+
)
80+
],
81+
)
82+
);
83+
}
84+
85+
}
86+
87+
class CustomMessageBar extends MessageBar {
88+
final TextEditingController _textController = TextEditingController();
89+
90+
CustomMessageBar({super.onSend});
91+
92+
@override
93+
Widget build(BuildContext context) {
94+
return Align(
95+
alignment: Alignment.bottomCenter,
96+
child: Container(
97+
child: Row(
98+
children: [
99+
Expanded(
100+
child: Padding(
101+
padding: EdgeInsets.all(12),
102+
child: Material(
103+
elevation: 2,
104+
borderRadius: BorderRadius.circular(28),
105+
child: TextField(
106+
controller: _textController,
107+
keyboardType: TextInputType.multiline,
108+
onChanged: super.onTextChanged,
109+
decoration: InputDecoration(
110+
suffixIcon: Padding(
111+
padding: EdgeInsets.only(right: 4),
112+
child: IconButton(
113+
onPressed: () {
114+
if(_textController.text.trim() != '') {
115+
if(onSend != null) {
116+
onSend!(_textController.text.trim());
117+
}
118+
_textController.text = '';
119+
}
120+
},
121+
icon: Icon(Icons.send_outlined),
122+
),
123+
),
124+
filled: true,
125+
hintText: "",
126+
contentPadding: const EdgeInsets.symmetric(
127+
horizontal: 12.0,
128+
vertical: 14.0,
129+
),
130+
fillColor: Colors.purple.shade50,
131+
border: OutlineInputBorder(
132+
borderRadius: BorderRadius.circular(28),
133+
borderSide: BorderSide.none
134+
)
135+
136+
),
137+
138+
),
139+
)
140+
)
141+
)
142+
],
143+
),
144+
)
145+
);
146+
}
147+
}

lib/main.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:library_nitc/chatBotPage.dart';
23
import 'package:library_nitc/homePage.dart';
34
import 'package:library_nitc/loadingScreen.dart';
45
import 'package:library_nitc/profilePage.dart';
@@ -73,7 +74,7 @@ class _MainPageState extends State<MainPage> {
7374
item: ItemConfig(icon: Icon(Icons.home_outlined), title: "HOME", activeForegroundColor: Colors.black)
7475
),
7576
PersistentTabConfig(
76-
screen: SafeArea(child: HomePage()),
77+
screen: SafeArea(child: ChatBotPage()),
7778
item: ItemConfig(icon: Icon(Icons.chat_bubble_outline), title: "CHATBOT", activeForegroundColor: Colors.black)
7879
),
7980
PersistentTabConfig(

lib/paymentPage.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import 'package:easy_upi_payment/easy_upi_payment.dart';
21
import 'package:flutter/cupertino.dart';
32
import 'package:flutter/material.dart';
4-
import 'package:flutter_upi_india/flutter_upi_india.dart';
5-
import 'package:payu_checkoutpro_flutter/payu_checkoutpro_flutter.dart';
63
import 'package:persistent_bottom_nav_bar_v2/persistent_bottom_nav_bar_v2.dart';
74
import 'package:upi_payment_qrcode_generator/upi_payment_qrcode_generator.dart';
85

pubspec.lock

Lines changed: 8 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ packages:
4949
url: "https://pub.dev"
5050
source: hosted
5151
version: "1.4.0"
52+
chat_bubbles:
53+
dependency: "direct main"
54+
description:
55+
name: chat_bubbles
56+
sha256: "902bc84e22f9ce6b993d015457067a37d37eb7478bd7b5b185712d5c5329b866"
57+
url: "https://pub.dev"
58+
source: hosted
59+
version: "1.7.0"
5260
clock:
5361
dependency: transitive
5462
description:
@@ -97,22 +105,6 @@ packages:
97105
url: "https://pub.dev"
98106
source: hosted
99107
version: "6.0.3+1"
100-
decimal:
101-
dependency: transitive
102-
description:
103-
name: decimal
104-
sha256: "28239b8b929c1bd8618702e6dbc96e2618cf99770bbe9cb040d6cf56a11e4ec3"
105-
url: "https://pub.dev"
106-
source: hosted
107-
version: "3.2.1"
108-
easy_upi_payment:
109-
dependency: "direct main"
110-
description:
111-
name: easy_upi_payment
112-
sha256: "46c9c62dbcb190f89180451bc7310b2b5f712de390506b4384e976b2fed56d62"
113-
url: "https://pub.dev"
114-
source: hosted
115-
version: "0.1.6"
116108
fake_async:
117109
dependency: transitive
118110
description:
@@ -155,14 +147,6 @@ packages:
155147
description: flutter
156148
source: sdk
157149
version: "0.0.0"
158-
flutter_upi_india:
159-
dependency: "direct main"
160-
description:
161-
name: flutter_upi_india
162-
sha256: d0686c9f510df959924140817f31727d58440d7b052d212b3f757b771b3b3fe8
163-
url: "https://pub.dev"
164-
source: hosted
165-
version: "0.0.6"
166150
flutter_web_plugins:
167151
dependency: transitive
168152
description: flutter
@@ -272,14 +256,6 @@ packages:
272256
url: "https://pub.dev"
273257
source: hosted
274258
version: "1.9.1"
275-
payu_checkoutpro_flutter:
276-
dependency: "direct main"
277-
description:
278-
name: payu_checkoutpro_flutter
279-
sha256: b140e85960d59c610e51eb73cbfbf231a4b85842c9d8299c7d1f9d3355181ef4
280-
url: "https://pub.dev"
281-
source: hosted
282-
version: "1.3.0"
283259
persistent_bottom_nav_bar_v2:
284260
dependency: "direct main"
285261
description:
@@ -296,14 +272,6 @@ packages:
296272
url: "https://pub.dev"
297273
source: hosted
298274
version: "6.1.0"
299-
plugin_platform_interface:
300-
dependency: transitive
301-
description:
302-
name: plugin_platform_interface
303-
sha256: "4820fbfdb9478b1ebae27888254d445073732dae3d6ea81f0b7e06d5dedc3f02"
304-
url: "https://pub.dev"
305-
source: hosted
306-
version: "2.1.8"
307275
posix:
308276
dependency: transitive
309277
description:
@@ -328,14 +296,6 @@ packages:
328296
url: "https://pub.dev"
329297
source: hosted
330298
version: "4.1.0"
331-
rational:
332-
dependency: transitive
333-
description:
334-
name: rational
335-
sha256: cb808fb6f1a839e6fc5f7d8cb3b0a10e1db48b3be102de73938c627f0b636336
336-
url: "https://pub.dev"
337-
source: hosted
338-
version: "2.2.3"
339299
sky_engine:
340300
dependency: transitive
341301
description: flutter

pubspec.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ dependencies:
3939
date_field: ^6.0.3+1
4040
intl: ^0.20.2
4141
flutter_native_splash: ^2.4.6
42-
flutter_upi_india: ^0.0.6
4342
upi_payment_qrcode_generator: ^1.6.0
44-
payu_checkoutpro_flutter: ^1.3.0
45-
easy_upi_payment: ^0.1.6
43+
chat_bubbles: ^1.7.0
4644

4745
dev_dependencies:
4846
flutter_test:

0 commit comments

Comments
 (0)