I am building a Spotify clone in flutter and want to achieve the look of the buttons on the appbar(All, Music, Podcasts) they change colors like in tabbar function but I am not sure if this particular thing can be achieved with tab bar.Example image of Spotify Ui <= providing the image here, just take a look at the appbar at those buttons or tabs to be precise.
I have tried using tabbar under appbar but couldn’t quite get that.
2
Answers
You can create the buttons you will use in a
Row
with a for loop. Then you can display the widget you will display at the bottom usingPageViewBuilder
. With the clicks of the buttons above, you change the index of the widgets inPageViewBuilder
. In this way, the buttons will be as you want.Instead of TabBar, use a custom AppBar widget.
Inside the AppBar’s preferredSize property, define a Size with your desired app bar height.
Within the AppBar’s child, use a Row widget to horizontally arrange the buttons.
Create individual TextButton widgets for "All," "Music," and "Podcasts."
Style the TextButtons with appropriate colors (use onPressed callback to change color on press).
Consider using a Container with rounded corners around each TextButton to mimic the Spotify button style.