Closed Wizpna closed 5 years ago
Can you provide some code and also which version of dash_chat
, flutter version you are using so that I could investigate the problem.
Thanks for your feedback.
This is the code I added to my pubspec.yaml file:
dependencies: dash_chat: ^1.0.4
While this code was what I added to my main.dart file.
import 'dart:async';
import 'package:dash_chat/dash_chat.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(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final GlobalKey<DashChatState> _chatViewKey = GlobalKey<DashChatState>();
final ChatUser user = ChatUser(
name: "Fayeed",
uid: "123456789",
avatar: "https://www.wrappixel.com/ampleadmin/assets/images/users/4.jpg",
);
final ChatUser otherUser = ChatUser(
name: "Mrfatty",
uid: "25649654",
avatar: "",
);
List<ChatMessage> messages = List<ChatMessage>();
var m = List<ChatMessage>();
var i = 0;
@override
void initState() {
m.addAll([
ChatMessage(text: "Hi", user: otherUser, createdAt: DateTime.now()),
ChatMessage(
text: "How are you?",
user: otherUser,
createdAt: DateTime.now(),
quickReplies: QuickReplies(
values: <Reply>[
Reply(
title: "Great, What about you",
value: "Great, What about you",
),
Reply(
title: "I am good, How are you",
value: "I am good, How are you",
),
],
),
),
ChatMessage(
text: "I am fine",
user: otherUser,
createdAt: DateTime.now(),
quickReplies: QuickReplies(
values: <Reply>[
Reply(
title: "Where are you travelling too",
value: "Where are you travelling too",
),
Reply(
title: "When do you want to meet",
value: "When do you want to meet",
),
],
),
),
ChatMessage(
text: "Paris",
user: otherUser,
createdAt: DateTime.now(),
quickReplies: QuickReplies(
values: <Reply>[
Reply(
title: "Can you send a pic later",
value: "Can you send a pic later",
),
Reply(
title: "Send me pic of Eiffel tower",
value: "Send me pic of Eiffel tower",
),
],
),
),
ChatMessage(
text: "",
image:
"https://amp.insider.com/images/58d919eaf2d0331b008b4bbd-750-562.jpg",
user: otherUser,
createdAt: DateTime.now(),
quickReplies: QuickReplies(
values: <Reply>[
Reply(
title: "Looks awesome",
value: "Looks awesome",
),
Reply(
title: "Cool",
value: "Cool",
),
Reply(
title: "Wow 😲",
value: "Wow 😲",
),
],
),
),
ChatMessage(
text: "Message you in a bit",
user: otherUser,
createdAt: DateTime.now(),
quickReplies: QuickReplies(
values: <Reply>[
Reply(
title: "I will Message you later",
value: "I will Message you later",
),
Reply(
title: "Maybe not.",
value: "Maybe not.",
),
Reply(
title: "Meet me at my place",
value: "Meet me at my place",
),
Reply(
title: "What!!",
value: "What!!",
),
],
),
)
]);
super.initState();
}
void systemMessage() {
Timer(Duration(milliseconds: 300), () {
if (i < 6) {
setState(() {
messages = [...messages, m[i]];
});
i++;
}
Timer(Duration(milliseconds: 300), () {
_chatViewKey.currentState.scrollController
..animateTo(
_chatViewKey.currentState.scrollController.position.maxScrollExtent,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 300),
);
});
});
}
void onSend(ChatMessage message) {
setState(() {
messages = [...messages, message];
print(messages.length);
});
if (i == 0) {
systemMessage();
Timer(Duration(milliseconds: 600), () {
systemMessage();
});
} else {
systemMessage();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Chat App"),
),
body: DashChat(
key: _chatViewKey,
inverted: false,
onSend: onSend,
user: user,
inputDecoration:
InputDecoration.collapsed(hintText: "Add message here..."),
dateFormat: DateFormat('yyyy-MMM-dd'),
timeFormat: DateFormat('HH:mm'),
messages: messages,
showUserAvatar: false,
showAvatarForEveryMessage: false,
onPressAvatar: (ChatUser user) {
print("OnPressAvatar: ${user.name}");
},
onLongPressAvatar: (ChatUser user) {
print("OnLongPressAvatar: ${user.name}");
},
inputMaxLines: 5,
messageContainerPadding: EdgeInsets.only(left: 5.0, right: 5.0),
alwaysShowSend: true,
inputTextStyle: TextStyle(fontSize: 16.0),
inputContainerStyle: BoxDecoration(
border: Border.all(width: 0.0),
color: Colors.white,
),
onQuickReply: (Reply reply) {
setState(() {
messages.add(ChatMessage(
text: reply.value, createdAt: DateTime.now(), user: user));
messages = [...messages];
});
Timer(Duration(milliseconds: 300), () {
_chatViewKey.currentState.scrollController
..animateTo(
_chatViewKey
.currentState.scrollController.position.maxScrollExtent,
curve: Curves.easeOut,
duration: const Duration(milliseconds: 300),
);
if (i == 0) {
systemMessage();
Timer(Duration(milliseconds: 600), () {
systemMessage();
});
} else {
systemMessage();
}
});
},
onLoadEarlier: () {
print("laoding...");
},
shouldShowLoadEarlier: true,
showTraillingBeforeSend: true,
trailing: <Widget>[
IconButton(
icon: Icon(Icons.photo),
onPressed: () {
print("object");
},
)
],
),
);
}
}
Hey, I don't think this is a problem with the package as I tried reproducing it but everything seems fine. What steps did you take that leads to this error. Are you running the example provided in the package if so there's no need to add dash_chat
in dependencies
Thanks for your feedback.
This is the link to my chatbot repository https://github.com/Wizpna/chat_bot
When I run the project, I receive his error message:
Compiler message: file:///C:/flutter/.pub-cache/hosted/pub.flutter-io.cn/dash_chat-1.0.4/lib/src/chat_input_toolbar.dart:97:21: Error: No named parameter with the name 'showCursor'. showCursor: showInputCursor, ^^^^^^^^^^ file:///C:/flutter/packages/flutter/lib/src/material/text_field.dart:134:9: Context: Found this candidate, but the arguments don't match. const TextField({ ^ file:///C:/flutter/.pub-cache/hosted/pub.flutter-io.cn/dash_chat-1.0.4/lib/src/widgets/message_container.dart:62:42: Error: The method 'copyWith' isn't defined for the class 'BoxDecoration'.
FAILURE: Build failed with an exception.
Where: Script 'C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 648
What went wrong: Execution failed for task ':app:compileflutterBuildDebugandroid-arm'.
Process 'command 'C:\flutter\bin\flutter.bat'' finished with non-zero exit value 1
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 38s Finished with error: Gradle task assembleDebug failed with exit code 1
You can download the repository and run the project, you will get the same error message.
Hey just checked you repository and everything works fine. I think this is something to with your flutter installation. Anyways, since this is not related to this package I am going to close this issue now.
Thanks for the lovely plugin.
I downloaded the project and while trying to run the project on my computer, I received an error message and the project did not complete.
This is the error message