Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dash_chat producing an error when i tried to run the program #2

Closed
Wizpna opened this issue Aug 6, 2019 · 5 comments
Closed

dash_chat producing an error when i tried to run the program #2

Wizpna opened this issue Aug 6, 2019 · 5 comments
Labels
invalid This doesn't seem right

Comments

@Wizpna
Copy link

Wizpna commented Aug 6, 2019

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
image

@fayeed
Copy link
Owner

fayeed commented Aug 6, 2019

Can you provide some code and also which version of dash_chat, flutter version you are using so that I could investigate the problem.

@Wizpna
Copy link
Author

Wizpna commented Aug 6, 2019

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");
            },
          )
        ],
      ),
    );
  }
}

@fayeed
Copy link
Owner

fayeed commented Aug 7, 2019

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

@Wizpna
Copy link
Author

Wizpna commented Aug 7, 2019

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'.

  • 'BoxDecoration' is from 'package:flutter/src/painting/box_decoration.dart' ('file:///C:/flutter/packages/flutter/lib/src/painting/box_decoration.dart').
    Try correcting the name to the name of an existing method, or defining a method named 'copyWith'.
    ? messageContainerDecoration.copyWith(
    ^^^^^^^^
    Compiler failed on D:\chat_bot\lib\main.dart

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.

@fayeed fayeed added the invalid This doesn't seem right label Aug 8, 2019
@fayeed
Copy link
Owner

fayeed commented Aug 8, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants