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

question: UI interactivity and separation of concerns #4183

Closed
jnorkus opened this issue May 29, 2024 · 2 comments
Closed

question: UI interactivity and separation of concerns #4183

jnorkus opened this issue May 29, 2024 · 2 comments
Labels
question Further information is requested

Comments

@jnorkus
Copy link

jnorkus commented May 29, 2024

I have a Home screen that contains a Scaffold with an AppBar and content. The content will change based on selected tab. I would like my AppBar to be dynamic and change its transparency, title and actions based on route and some other properties of deeper nested components within the routes, like a bottom sheet height.

I found myself looking at various implementation paths so I'd like to get some suggestions on what would be the correct BloC way. This is my current approach:

Route is stored in the HomeBloc, HomeView has listeners on the deeper Blocs, that update the HomeBloc with properties like "isAppBarVisible", "appBarTitle", "isAppBarTransparent". AppBar rebuilds based on this state.

My concern is that this looks like presentation logic and maybe it's not the best idea to store it in BloC. So I was thinking maybe this has nothing to do with BloC at all and should be kept within stateful widgets and controllers? Or is it ok to store UI specific properties like view height, transparency, visibility, etc. in BloC?

@jnorkus jnorkus added the bug Something isn't working label May 29, 2024
@felangel
Copy link
Owner

felangel commented Jun 4, 2024

Hi @jnorkus 👋
Thanks for opening an issue!

Generally, presentation logic should be maintained in the widget tree but there's never a single hard/fast rule for these things so I'd recommend trying a couple of different options and weighing the pros/cons before making a decision. I'm happy to take a closer look at your current implementation (if it's publicly available on GitHub) or if you are able to share a minimal reproduction sample I can take a closer look and provide any suggestions. Hope that helps! 👍

@felangel felangel added question Further information is requested waiting for response Waiting for follow up and removed bug Something isn't working labels Jun 4, 2024
@jnorkus
Copy link
Author

jnorkus commented Jun 4, 2024

Thanks a lot for taking the time to respond.

I decided to completely isolate the presentation logic and use the standard framework classes, like ChangeNotifier, StreamBuilder, etc. to reach my goals. One added benefit is that now the code can be refactored into reusable widgets as opposed to having the logic in the BLL and being app specific.

@felangel felangel removed the waiting for response Waiting for follow up label Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants