brianegan/scoped_model

Could not find the correct ScopedModel using a drawer

warriorCoder opened this issue · 2 comments

I have a situation where I've wrapped a Scaffold in my model and have a side drawer. On the page where my model and Scaffold are declared. From the drawer, there is a material route that loads a new page and uses the model declared on the first page. This new page is the one that throws the ScopedModel can't find my model error.

I can fix this by creating the model on the subpage, however, I need to load data (list of products) and then modify the product list when it is filtered, etc so using say a future builder causes the page to fully reload when the items are favorited for example.

Either way, it seems like ScopedModel ought to be able to find the ProductModel as it's declared in the tree above the product page.

Have you been able to solve this? I'm running into this issue with MaterialPageRoute as well.

EDIT: Moved ScopedModel outside of MaterialApp as suggested in #67, solved the problem (although I'd really like to know if there's a more elegant solution than wrapping the entire app in the ScopedModel)

I decided to move from Scoped Model to the Bloc pattern... and I ended up figuring out that the issue isn't Scoped Model, it is how Flutter builds screens. The use of an overlay widget which is above the screen widgets which is why the Scoped Model can't be found, ever.

The only other solution that I can come up with would be to pass the model to the new screen in the Route.