Coder Social home page Coder Social logo

Scroll to last index about dash_chat HOT 11 CLOSED

fayeed avatar fayeed commented on June 23, 2024 1
Scroll to last index

from dash_chat.

Comments (11)

Dreamersoul avatar Dreamersoul commented on June 23, 2024

you can fix it using the following:
add this in the build method

    WidgetsBinding.instance.addPostFrameCallback(afterBuild);

and use a scrollcontroller like the following:

  void afterBuild(Duration duration) {
    _scrollController.jumpTo(_scrollController.position.maxScrollExtent);
  }

from dash_chat.

fayeed avatar fayeed commented on June 23, 2024

@Marcosmaliki This is fixed in 1.0.17.

from dash_chat.

Marcosmaliki avatar Marcosmaliki commented on June 23, 2024

I have updated but I can't see any difference. All I want is to display the latest messages first. The current implementation displays old messages then scrolls/jumps to the latest. Reproduce this with a thousand messages to see how ugly it looks.

from dash_chat.

Marcosmaliki avatar Marcosmaliki commented on June 23, 2024

ezgif com-optimize

from dash_chat.

Dreamersoul avatar Dreamersoul commented on June 23, 2024

Hello can you provide an example project? And I'll take a look at it

from dash_chat.

Marcosmaliki avatar Marcosmaliki commented on June 23, 2024

Hello @Dreamersoul thanks!
Reversing the list then reversing the message works alright but the list scrolls to the top when sending a message๐Ÿ˜†. Ps. I'm not using Firebase

return Scaffold(
      appBar: AppBar(
        title: Text('Messages'),
      ),
      body: FutureBuilder<ApiRes<MessagesRes>>(
        future: NetworkCalls().getMessages(id),
        builder: (context, snapshot) {
          if (snapshot.hasData) {
            if (snapshot.data.error) {
              return Center(child: Text(snapshot.data.errorMsg.toString()));
            } else {
              List<Messages> msgs =
                  List.from(snapshot.data.data.messages);
//                  List.from(snapshot.data.data.messages.reversed);
              var mess;
              messages.clear();
              msgs.forEach((f) {
                user = ChatUser(
                  name: f.name,
                  uid: f.from,
                  avatar: "f.avatar",
                );
                mess = ChatMessage(
                    text: f.message,
                    user: user,
                    createdAt: DateTime.parse(f.createdat)
                        .add(new Duration(hours: 3)));
                messages.add(mess);
              });
              return DashChat(
                messages: messages,
                showUserAvatar: false,
                showAvatarForEveryMessage: false,
                scrollToBottom: false,
                inverted: false,//true
                user: user,
                shouldShowLoadEarlier: false,
                key: _chatViewKey,
                onSend: onSend,
                leading: <Widget>[
                  IconButton(
                    icon: Icon(Icons.attach_file),
                    onPressed: () {
                      print("object");
                    },
                  )
                ],
//                scrollController: _scrollController,
                onLoadEarlier: () {
                  print('loading . . . ');
                },
                onLongPressMessage: (val) {
                  _modalBottomSheet(context);
                },
                inputDecoration:
                    InputDecoration.collapsed(hintText: "Add message here..."),
                dateFormat: DateFormat('dd MMM yyyy'),
                timeFormat: DateFormat.jm(),
                inputMaxLines: 5,
                messageContainerPadding:
                    EdgeInsets.only(left: 5.0, right: 5.0, top: 5),
                alwaysShowSend: false,
                inputTextStyle: TextStyle(fontSize: 16.0),
                inputContainerStyle: BoxDecoration(
                  border: Border.all(width: 0.0, color: Colors.grey),
                  color: Colors.white,
                ),
              );
            }
          } else if (snapshot.hasError) {
            return Center(child: Text(snapshot.error.toString()));
          }
          return Center(child: spinkitSquareCircle);
        },
      ),
    );

from dash_chat.

Dreamersoul avatar Dreamersoul commented on June 23, 2024

Can I see the onSend method?

from dash_chat.

Marcosmaliki avatar Marcosmaliki commented on June 23, 2024
  void onSend(ChatMessage message) {
    //send to API and MQTT
    print(message.text + 'ID of sending user: $id');
    Map<String, dynamic> data = {'message': message.text, 'to': id};
    sendMessage(data);
    messages.insert(0,
        ChatMessage(text: message.text, createdAt: DateTime.now(), user: user));

    messages = [...messages];
  }

the insert method is a fix to add the message as the start of the array when reversed. My major issue is the scrolling. Check the gif above. The list stutters when scrolling

from dash_chat.

Dreamersoul avatar Dreamersoul commented on June 23, 2024

i dont seem to know how to fix this, maybe @fayeed can help out!

from dash_chat.

lehno avatar lehno commented on June 23, 2024

Same problem here =/

from dash_chat.

hangaoke1 avatar hangaoke1 commented on June 23, 2024

mark, same problem

from dash_chat.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.