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

How can i open ChannelPage out of ChannelListPage #63

Closed
yswtrue opened this issue Jul 26, 2020 · 3 comments
Closed

How can i open ChannelPage out of ChannelListPage #63

yswtrue opened this issue Jul 26, 2020 · 3 comments

Comments

@yswtrue
Copy link

yswtrue commented Jul 26, 2020

I have followed the guide create the ChannelListPage and ChannelPage, and it works fine for me. But now I want to open a one to one conversation, but when I navigate to StreamChannel, it keeps on loading, and I don't know how to make it work. Help me, please.

This is my code.

class ChannelListPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        title: Text(
          'Messages',
          style: TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
        ),
      ),
      bottomNavigationBar: CustomButtomBar(
        index: 2,
      ),
      body: ChannelsBloc(
        child: ChannelListView(
          filter: {
            'members': {
              '\$in': [StreamChat.of(context).user.id],
            }
          },
          sort: [SortOption('last_message_at')],
          pagination: PaginationParams(
            limit: 20,
          ),
          channelWidget: ChannelPage(),
        ),
      ),
    );
  }
}

class ChannelPage extends StatelessWidget {
  const ChannelPage({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: ChannelHeader(),
      body: Column(
        children: <Widget>[
          Expanded(
            child: MessageListView(
              threadBuilder: (_, parentMessage) {
                return ThreadPage(
                  parent: parentMessage,
                );
              },
            ),
          ),
          MessageInput(),
        ],
      ),
    );
  }
}

class ThreadPage extends StatelessWidget {
  final Message parent;

  ThreadPage({
    Key key,
    this.parent,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: ThreadHeader(
        parent: parent,
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: MessageListView(
              parentMessage: parent,
            ),
          ),
          MessageInput(
            parentMessage: parent,
          ),
        ],
      ),
    );
  }
}

and these is how to navigate to channel page. These code is in other place to jump to ChannelPage.

                                onTap: () async {
                                  var conversation = Chat()
                                      .client
                                      .channel("messaging", extraData: {
                                    "members": [
                                      user.id.toString(),
                                      ClientChannelManager.getUser()
                                          .id
                                          .toString()
                                    ]
                                  });
                                  Navigator.push(context, MaterialPageRoute(
                                    builder: (context) {
                                      return StreamChannel(
                                        child: ChannelPage(),
                                        channel: conversation,
                                      );
                                      //   return MessagePage(
                                      //   userId: user.id,
                                      // );
                                    },
                                  ));
                                },

and the app keep in this state
photo_2020-07-27_01-33-24

gz#4631

@yswtrue
Copy link
Author

yswtrue commented Jul 26, 2020

I have found the solution, this works for me.

                                onTap: () async {
                                  var conversation = Chat()
                                      .client
                                      .channel("messaging", extraData: {
                                    "members": [
                                      user.id.toString(),
                                      ClientChannelManager.getUser()
                                          .id
                                          .toString()
                                    ]
                                  });
                                  var st = await conversation.create();
                                  var c = Channel.fromState(Chat().client, st);
                                  Navigator.push(context, MaterialPageRoute(
                                    builder: (context) {
                                      return StreamChannel(
                                        child: ChannelPage(),
                                        channel: c,
                                      );
                                      //   return MessagePage(
                                      //   userId: user.id,
                                      // );
                                    },
                                  ));
                                },

@yswtrue yswtrue closed this as completed Jul 26, 2020
@imtoori
Copy link
Contributor

imtoori commented Jul 27, 2020

you can also use conversation.watch to create and watch the conversation at the same
it will also be added to the channel list

@yswtrue
Copy link
Author

yswtrue commented Jul 28, 2020

you can also use conversation.watch to create and watch the conversation at the same
it will also be added to the channel list

It works for me, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants