Code Monkey home page Code Monkey logo

Comments (14)

pixnbit avatar pixnbit commented on May 14, 2024 3

I was confused with that builder usage under MaterialApp and got rid of it, then I saw the same message error. I also use named routes.
It's not a clean solution, having the StreamChat initialized this early and at such high scope. Look forward to the better solution. And in the meantime, maybe you can comment in the sample code that builder: was a temporary hack.

from stream-chat-flutter.

barancezayirli avatar barancezayirli commented on May 14, 2024 2

it is a really bad design choice I think. The chat itself would require authentication (need to get a token for a specific user min). And as far as I see, no plan to change it :/

I am building an app, not concentrated on chat but have chat with as an extra feature. Users should log in (this is where they will get the token with their id). When a first-time user opens the app, there is no user so no token.

Furthermore, users can log out and log in with different credentials. That time the client will be initialized with a different token.

Any suggestions on what can I do without putting StreamChat into the builder?

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024 1

We added a navigator to make the StreamChat widget always be on top of the widget tree.
This approach is not the best and we should refactorize it finding a good compromise between usability and convenience.
The point is to make the user write as less code as possible to make a working app.

I'll think about it and hopefully come with a better solution.

For the moment you can try to use
Navigator.of(context, rootNavigator: true).pushNamed('/test'),

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024 1

Are you trying to use StreamChat.of in your new route?
The problem is that once you push a new route, the StreamChat widget is not in your current widget tree anymore.
You may want to take a look at this https://stackoverflow.com/questions/49968817/flutter-inherited-widget-and-routes

A possible solution is to put the widget StreamChat in the builder method of your MaterialApp (like this answer https://stackoverflow.com/questions/49328362/get-access-to-the-context-of-inheritedwidget/49329255#49329255)
I think that's a better solution and in the next version, we can get rid of the additional Navigator (it was a workaround for this situation) suggesting to put the StreamChat widget there.

from stream-chat-flutter.

brizaldi avatar brizaldi commented on May 14, 2024 1

after using the last version and put StreamChat inside the builder, i can confirm that its working perfectly now, thank you for the quick response and maybe you can close this issue

from stream-chat-flutter.

brizaldi avatar brizaldi commented on May 14, 2024

now i get this error when i call StreamChat.of(context).client :

You must have a StreamChat widget at the top of your widget tree

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024

Could you try the last version using the StreamChat widget in the builder method of the MaterialApp?

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024

Thank you for reporting the issue :)

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024

I think that's true, but you can always just initialize the client and call client.setUser deeper in the tree.
That was the simplest way to avoid to pass the StreamChat widget on every Navigator.push.

We're trying to find a better solution by the way.

from stream-chat-flutter.

siddhartha2000v avatar siddhartha2000v commented on May 14, 2024

I think that's true, but you can always just initialize the client and call client.setUser deeper in the tree.
That was the simplest way to avoid to pass the StreamChat widget on every Navigator.push.

We're trying to find a better solution by the way.

I think that's true, but you can always just initialize the client and call client.setUser deeper in the tree.
That was the simplest way to avoid to pass the StreamChat widget on every Navigator.push.

We're trying to find a better solution by the way.

@imtoori just wanted to check if this issue was resolved in the latest version.I am working on an application and dont want to initialise the stream client above authentication. I am getting the same error quoted above 'You must have a StreamChat widget at the top of your widget tree'

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024

hey @siddhartha2000v this is not really an issue, but we've found a better solution than using the builder parameter of the MaterialApp and we're working on it

Can you give me more information about your issue?
I think the best way to use the StreamChat widget at the moment is using the builder parameter of the MaterialApp as you can see in our sample apps
The initialization using client.connectUser can even happen deeper in the widget tree, but the StreamChat widget would be better placed in there

from stream-chat-flutter.

siddhartha2000v avatar siddhartha2000v commented on May 14, 2024

Thanks for the update @imtoori. I am able to resolve the issue using the builder parameter in material app. However was looking for the update on better solution. Thanks for helping with current status anyways.

from stream-chat-flutter.

luvishq avatar luvishq commented on May 14, 2024

@barancezayirli : were you able to solve the issue ? I am in a similar situation right now . @imtoori : any solution for this ?

from stream-chat-flutter.

imtoori avatar imtoori commented on May 14, 2024

@luvishq what's your issue?
Putting the StreamChat into the builder is always required, but you could call connectUser even deeper in your tree.
Let me know your issue

from stream-chat-flutter.

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.