Allow the StreamChat widget to be called within a route or lower-level-descendant widget
Please select which package this feature is related to
stream_chat_flutter
Which platforms would this feature impact?
iOS, Android
Is your feature request related to a problem?
No, it's a preference.
Describe the solution that you'd like
Background: Currently developing an enterprise-flutter app that is driven by TDD and has multiple routes and uses stream_chat_flutter 3.4.0.
It would appreciated if the StreamChat widget was not required to be at the top level of the application and still work as expected. Currently, the StreamChat widget needs to be one of the highest widgets in the app for messages and editing messages to work. This forces stream chat widgets to be sprinkled throughout the application and would prefer to isolate and encapsulate 3rd party libraries appropriately. Further more, tests at the highest level of the widget tree wouldn't have to account for Stream's widgets.
The need to have it be one of the highest widgets in the tree comes from the message widget which has a function called _showMessageActionModalBottomSheet. This function shows a dialog which then gets StreamChat.of(context).currentUser on line 98 in message_actions_modal. If this were to pass in the currentUser directly, it would resolve the need to place StreamChat up so high in the widget tree, allow for encapsulation, and help out with tests. This is one example, however, any dialog that then calls StreamChat.of will force StreamChat to remain high up in the widget tree due to the widget tree and how routing impacts the widget tree.
Describe alternatives that you have considered
Keep the StreamChat widget high up in tree.
Additional context
No response
Code of Conduct
- [X] I agree to follow this project's Code of Conduct
Hi @sampontec, thank you for making the issue. There are a few things we will need to refactor to eventually get rid of this strict dependency that requires it to be high up in the widget tree. This is something we will aim to improve.
I see you mention that you sprinkle the SteamChat widget across the application. As an alternative solution, you could make use of the builder in MaterialApp, as shown here: https://github.com/GetStream/stream-chat-flutter/blob/ca4cc3cd3d0ee58283c72a2f561f2051191e1037/packages/stream_chat_flutter/example/lib/main.dart#L77
This can be used to insert StreamChat above the default Navigator. Though I understand that from a testing perspective that might still not be the ideal solution.
Hey @HayesGordon, thanks for reaching out and the post. That's what we have done to make sure everything works appropriately. Like you said, it's not an optimal solution for testing. Would really like to encapsulate stream chat logic to our messaging page. At this point it's just a preference. : )
Appreciate what Stream Chat has done and looking forward to seeing what's next!
I am closing this as it is stale for too long. Please feel free to re-open it if you think it is still relevant