Milad-Akarie / auto_route_library

Flutter route generator
MIT License
1.6k stars 406 forks source link

Can we dynamically generate route? #699

Closed AscentionOne closed 3 years ago

AscentionOne commented 3 years ago

Hi, @Milad-Akarie I am building a web application with a list of tabs. You can refer to https://unsplash.com/. There are feature tabs on the navigation section. When clicking each feature it will navigate to the page and also preserve the state when navigating between features(data don't need to be load every time when the user navigates between them).

image

Is there a good way to implement this kind of tab? I have around 15 categories and each has its own data. I am currently creating a page route that takes 15 different category types as id /category/:id.

How do I preserve the data between categories like using AutoTabsRouter. I am currently using the same generic page, thus constantly updating the page. The state will not be preserved. Thanks!

benjaminschreck commented 3 years ago

I would suggest to use a state management solution like e.g. riverpod or getx

Milad-Akarie commented 3 years ago

@AscentionOne I'd suggest the same as @benjaminschreck, I'd have a categories state somewhere up my widgets tree and have my categoryRoute/page read it's state from there based on categoryId.

I'm thinking of something that looks like this

class CategoriesController/Cubit{
final categoriesState = <int,SingleCategoryState>{}

loadCategoryStateOf(int catId){
   // check if state already exists in map, if not load it. 
 }
}
t
AscentionOne commented 3 years ago

Thanks, @benjaminschreck @Milad-Akarie I'll give it a try and see how it goes!