so you can disappear the title's in the app bar as user scrolls, like spotify
Yes, using Flutter Bloc for managing the state of the ScrollController is indeed a possibility. This would keep with the overall architecture of your current app.
Here is a rough outline how you would do it:
First, define a Bloc event that parameterizes the relevant scroll position:
class ScrollUpdated extends YourBlocEvent {
final double scrollPosition;
ScrollUpdated(this.scrollPosition);
}
Then you can define a corresponding state:
class ScrollState extends YourBlocState {
final double scrollPosition;
ScrollState(this.scrollPosition);
}
Next, in the initState() method of your widget, you can add listener to your ScrollController that will dispatch an event to your bloc every time new scroll position is detected:
Remember to dispose of your ScrollController in the dispose method of the widget.
Now, your bloc will emit a new ScrollState every time the scroll position is changed and you can listen to these events from your appBar or any other part of your app by using BlocBuilder or BlocConsumer.
Although it's not a common use case to manage scroll position using a state management solution such as Bloc, in complex apps with many layers that require such synchronization it might be one way to tackle this problem. Using Bloc in this case allows multiple components to react to the ScrollPosition changes.
so you can disappear the title's in the app bar as user scrolls, like spotify
Yes, using Flutter Bloc for managing the state of the ScrollController is indeed a possibility. This would keep with the overall architecture of your current app.
Here is a rough outline how you would do it:
First, define a Bloc event that parameterizes the relevant scroll position:
Then you can define a corresponding state:
Next, in the
initState()
method of your widget, you can add listener to your ScrollController that will dispatch an event to your bloc every time new scroll position is detected:And lastly, in your Bloc mapEventToState, handle the ScrollUpdated event:
Remember to dispose of your ScrollController in the
dispose
method of the widget.Now, your bloc will emit a new
ScrollState
every time the scroll position is changed and you can listen to these events from your appBar or any other part of your app by using BlocBuilder or BlocConsumer.Although it's not a common use case to manage scroll position using a state management solution such as Bloc, in complex apps with many layers that require such synchronization it might be one way to tackle this problem. Using Bloc in this case allows multiple components to react to the ScrollPosition changes.